Menu

[r760]: / trunk / lispbuilder-sdl / sdl / font.lisp  Maximize  Restore  History

Download this file

75 lines (53 with data), 2.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
;;;; General font definition
(in-package :lispbuilder-sdl)
(defclass font ()
((cached-surface :accessor cached-surface :initform nil))
(:documentation
"The generic SDL font class. All fonts in `LISPBUILDER-SDL` inherit from this class.
Free using [FREE](#free)."))
(defmethod width ((font font))
(width (cached-surface font)))
(defmethod height ((font font))
(height (cached-surface font)))
(defmethod x ((font font))
(x (cached-surface font)))
(defmethod (setf x) (x-val (font font))
(setf (x (cached-surface font)) x-val))
(defmethod y ((font font))
(y (cached-surface font)))
(defmethod (setf y) (y-val (font font))
(setf (y (cached-surface font)) y-val))
(defmethod draw-font (&key (font *default-font*) (surface *default-surface*))
(check-type font font)
(blit-surface (cached-surface font) surface))
(defmethod draw-font-at (position &key (font *default-font*) (surface *default-surface*))
(check-type font font)
(draw-surface-at (cached-surface font) position :surface surface))
(defmethod draw-font-at-* (x y &key (font *default-font*) (surface *default-surface*))
(check-type font font)
(check-type (cached-surface font) sdl-surface)
(draw-surface-at-* (cached-surface font) x y :surface surface))
(defmethod free-cached-surface ((font font))
(when (cached-surface font)
(free (cached-surface font))))
(defmacro with-default-font ((font) &body body)
"Sets `\*DEFAULT-FONT\*` to `FONT` within the scope of `WITH-DEFAULT-FONT`.
##### Example
\(WITH-DEFAULT-FONT \(new-font\)
\(DRAW-CHARACTER-SHADED-* \"Hello World!\" 0 0 F-COLOR B-COLOR\)\)
##### Packages
* Also supported in _LISPBUILDER-SDL-GFX_"
`(let ((*default-font* ,font))
,@body))
(defmacro with-font ((font font-definition) &body body)
"Sets `\*DEFAULT-FONT\*` to a new [BITMAP-FONT](#bitmap-font) in `FONT` within the scope of `WITH-FONT`.
Frees `FONT` when `WITH-FONT` goes out of scope.
##### Example
\(WITH-FONT \(new-font *font-8x8*\)
\(DRAW-CHARACTER-SHADED-* \"Hello World!\" 0 0 F-COLOR B-COLOR\)\)
##### Packages
* Also supported in _LISPBUILDER-SDL-GFX_"
`(let ((,font (initialise-font ,font-definition)))
(with-default-font (,font)
,@body)
(free ,font)))
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.