Artifact
6f9c572a5edffd5e1ce29601969776e374fe2317:
- File
sdl2/ttf-shim/readme.md
— part of check-in
[186525ea12]
at
2018-01-08 17:10:49
on branch trunk
— readme for shim
(user:
ovenpasta@users.noreply.github.com
size: 1765)
0000: 53 68 69 6d 20 74 6f 20 61 6c 6c 6f 77 20 74 74 Shim to allow tt
0010: 66 20 66 75 6e 63 74 69 6f 6e 73 20 74 6f 20 6c f functions to l
0020: 6f 61 64 2e 0a 0a 43 68 65 7a 20 63 61 6e 27 74 oad...Chez can't
0030: 20 70 61 73 73 20 73 74 72 75 63 74 75 72 65 73 pass structures
0040: 20 74 68 72 6f 75 67 68 20 66 66 69 20 61 74 20 through ffi at
0050: 74 68 65 20 6d 6f 6d 65 6e 74 2c 20 62 75 74 20 the moment, but
0060: 77 6f 72 6b 20 69 73 20 62 65 69 6e 67 20 64 6f work is being do
0070: 6e 65 20 6f 6e 20 69 74 20 74 65 6e 61 74 69 76 ne on it tenativ
0080: 65 6c 79 20 28 68 74 74 70 73 3a 2f 2f 67 69 74 ely (https://git
0090: 68 75 62 2e 63 6f 6d 2f 63 69 73 63 6f 2f 43 68 hub.com/cisco/Ch
00a0: 65 7a 53 63 68 65 6d 65 2f 70 75 6c 6c 2f 32 31 ezScheme/pull/21
00b0: 33 29 2e 20 20 54 68 69 73 20 73 68 69 6d 20 69 3). This shim i
00c0: 73 20 71 75 69 74 65 20 73 69 6d 70 6c 65 2c 20 s quite simple,
00d0: 61 6c 6c 20 69 74 20 64 6f 65 73 20 69 73 20 64 all it does is d
00e0: 65 66 69 6e 65 20 77 72 61 70 70 65 72 20 66 75 efine wrapper fu
00f0: 6e 63 74 69 6f 6e 73 20 66 6f 72 20 65 61 63 68 nctions for each
0100: 20 6f 66 20 74 68 65 20 52 45 4e 44 45 52 20 66 of the RENDER f
0110: 75 6e 63 74 69 6f 6e 73 20 74 68 61 74 20 53 44 unctions that SD
0120: 4c 5f 54 54 46 20 68 61 73 2e 20 20 57 65 20 68 L_TTF has. We h
0130: 61 76 65 20 74 6f 20 64 6f 20 74 68 69 73 20 62 ave to do this b
0140: 65 63 61 75 73 65 20 75 6e 6c 69 6b 65 20 6d 6f ecause unlike mo
0150: 73 74 20 6f 66 20 74 68 65 20 6f 74 68 65 72 20 st of the other
0160: 53 44 4c 20 63 6f 64 65 20 49 27 76 65 20 62 65 SDL code I've be
0170: 65 6e 20 67 6f 69 6e 67 20 74 68 72 6f 75 67 68 en going through
0180: 2c 20 74 68 65 73 65 20 70 61 72 74 69 63 75 6c , these particul
0190: 61 72 20 66 75 6e 63 74 69 6f 6e 73 20 74 61 6b ar functions tak
01a0: 65 20 74 68 65 20 73 74 72 75 63 74 75 72 65 20 e the structure
01b0: 61 73 20 61 6e 20 61 72 67 75 6d 65 6e 74 2c 20 as an argument,
01c0: 72 61 74 68 65 72 20 74 68 61 6e 20 61 20 70 6f rather than a po
01d0: 69 6e 74 65 72 20 74 6f 20 74 68 65 20 73 74 72 inter to the str
01e0: 75 63 74 75 72 65 2e 20 20 41 6c 6c 20 74 68 65 ucture. All the
01f0: 20 77 72 61 70 70 65 72 20 66 75 6e 63 74 69 6f wrapper functio
0200: 6e 73 20 64 6f 20 69 73 20 74 61 6b 65 20 61 20 ns do is take a
0210: 70 6f 69 6e 74 65 72 20 74 68 72 6f 75 67 68 20 pointer through
0220: 74 68 65 20 66 66 69 2c 20 61 6e 64 20 63 61 6c the ffi, and cal
0230: 6c 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 20 69 l the function i
0240: 74 20 77 72 61 70 73 20 77 69 74 68 20 74 68 65 t wraps with the
0250: 20 70 6f 69 6e 74 65 72 20 64 65 72 65 66 65 72 pointer derefer
0260: 65 6e 63 65 64 2e 0a 0a 49 20 68 61 76 65 20 63 enced...I have c
0270: 68 6f 73 65 6e 20 61 74 20 74 68 65 20 6d 6f 6d hosen at the mom
0280: 65 6e 74 20 74 6f 20 6e 61 6d 65 20 61 6e 64 20 ent to name and
0290: 65 78 70 6f 72 74 20 74 68 65 73 65 20 66 75 6e export these fun
02a0: 63 74 69 6f 6e 73 20 77 69 74 68 20 61 20 73 75 ctions with a su
02b0: 66 66 69 78 20 22 53 54 54 46 5f 22 20 77 68 69 ffix "STTF_" whi
02c0: 63 68 20 73 74 61 6e 64 73 20 66 6f 72 20 22 53 ch stands for "S
02d0: 68 69 6d 6d 65 64 20 54 54 46 22 2e 20 20 4f 70 himmed TTF". Op
02e0: 65 72 61 74 69 6f 6e 73 20 61 72 65 20 74 68 65 erations are the
02f0: 20 65 78 61 63 74 20 73 61 6d 65 20 69 6e 20 61 exact same in a
0300: 73 20 79 6f 75 20 77 6f 75 6c 64 20 65 78 70 65 s you would expe
0310: 63 74 2c 20 61 6c 6c 20 79 6f 75 20 68 61 76 65 ct, all you have
0320: 20 74 6f 20 64 6f 20 69 73 20 61 70 70 65 6e 64 to do is append
0330: 20 74 68 65 20 72 65 6e 64 65 72 20 66 75 6e 63 the render func
0340: 74 69 6f 6e 73 20 79 6f 75 20 75 73 65 20 69 6e tions you use in
0350: 20 73 63 68 65 6d 65 20 77 69 74 68 20 61 6e 20 scheme with an
0360: 22 73 74 74 66 2d 22 20 69 6e 73 74 65 61 64 20 "sttf-" instead
0370: 6f 66 20 22 74 74 66 2d 22 2e 20 20 46 6f 72 20 of "ttf-". For
0380: 61 6c 6c 20 6e 6f 6e 2d 72 65 6e 64 65 72 20 66 all non-render f
0390: 75 6e 63 74 69 6f 6e 73 20 22 74 74 66 2d 22 20 unctions "ttf-"
03a0: 69 73 20 73 74 69 6c 6c 20 75 73 65 64 2e 20 28 is still used. (
03b0: 4c 6f 61 64 69 6e 67 2c 20 69 6e 69 74 29 2e 0a Loading, init)..
03c0: 0a 43 75 72 72 65 6e 74 6c 79 2c 20 74 68 65 72 .Currently, ther
03d0: 65 20 61 72 65 20 74 77 6f 20 6c 69 62 72 61 72 e are two librar
03e0: 79 20 69 6e 69 74 20 66 75 6e 63 74 69 6f 6e 73 y init functions
03f0: 20 65 78 70 6f 72 74 65 64 20 73 6f 20 73 63 68 exported so sch
0400: 65 6d 65 20 63 61 6e 20 6c 6f 61 64 20 74 68 65 eme can load the
0410: 20 2e 73 6f 2c 20 62 75 74 20 73 69 6e 63 65 20 .so, but since
0420: 49 27 6d 20 6c 69 6e 6b 69 6e 67 20 74 68 65 20 I'm linking the
0430: 73 68 69 6d 20 2e 73 6f 20 74 6f 20 74 68 65 20 shim .so to the
0440: 73 64 6c 5f 74 74 66 20 2e 73 6f 20 69 74 20 6d sdl_ttf .so it m
0450: 61 79 20 6e 6f 74 20 62 65 20 6e 65 63 65 73 73 ay not be necess
0460: 61 72 79 20 74 6f 20 68 61 76 65 20 62 6f 74 68 ary to have both
0470: 2e 20 20 57 6f 72 6b 20 77 69 6c 6c 20 62 65 20 . Work will be
0480: 64 6f 6e 65 20 6f 6e 20 74 68 69 73 2e 0a 0a 54 done on this...T
0490: 6f 20 63 6f 6d 70 69 6c 65 20 74 68 65 20 73 68 o compile the sh
04a0: 61 72 65 64 20 6c 69 62 72 61 72 79 3a 0a 0a 0a ared library:...
04b0: 67 63 63 20 2d 63 20 74 74 66 2d 73 68 69 6d 2e gcc -c ttf-shim.
04c0: 63 20 2d 49 2f 75 73 72 2f 69 6e 63 6c 75 64 65 c -I/usr/include
04d0: 2f 53 44 4c 32 20 2d 44 5f 47 4e 55 5f 53 4f 55 /SDL2 -D_GNU_SOU
04e0: 52 43 45 3d 31 20 2d 44 5f 52 45 45 4e 54 52 41 RCE=1 -D_REENTRA
04f0: 4e 54 0a 0a 0a 67 63 63 20 74 74 66 2d 73 68 69 NT...gcc ttf-shi
0500: 6d 2e 6f 20 2d 73 68 61 72 65 64 20 2d 6f 20 74 m.o -shared -o t
0510: 74 66 73 68 69 6d 2e 73 6f 20 2d 4c 2f 75 73 72 tfshim.so -L/usr
0520: 2f 6c 69 62 20 2d 6c 53 44 4c 32 20 2d 6c 70 74 /lib -lSDL2 -lpt
0530: 68 72 65 61 64 20 2d 6c 53 44 4c 32 5f 74 74 66 hread -lSDL2_ttf
0540: 0a 0a 0a 49 20 68 61 76 65 20 74 65 73 74 65 64 ...I have tested
0550: 20 69 74 20 77 69 74 68 20 73 6f 6d 65 20 73 69 it with some si
0560: 6d 70 6c 65 20 63 61 73 65 73 20 61 6e 64 20 69 mple cases and i
0570: 74 20 73 65 65 6d 73 20 74 6f 20 77 6f 72 6b 20 t seems to work
0580: 61 62 73 6f 6c 75 74 65 6c 79 20 66 69 6e 65 20 absolutely fine
0590: 73 6f 20 66 61 72 2e 0a 0a 0a 4f 6e 65 20 66 69 so far....One fi
05a0: 6e 61 6c 20 6e 6f 74 65 20 6f 6e 20 74 68 69 73 nal note on this
05b0: 2c 20 20 69 74 20 6d 61 6b 65 73 20 69 74 20 73 , it makes it s
05c0: 6c 69 67 68 74 6c 79 20 6d 6f 72 65 20 63 6f 6d lightly more com
05d0: 70 6c 69 63 61 74 65 64 20 74 6f 20 67 65 6e 65 plicated to gene
05e0: 72 61 74 65 20 6e 65 77 20 62 69 6e 64 69 6e 67 rate new binding
05f0: 20 75 73 69 6e 67 20 74 68 65 20 63 32 66 66 69 using the c2ffi
0600: 20 6d 65 74 68 6f 64 2e 20 20 59 6f 75 20 77 69 method. You wi
0610: 6c 6c 20 68 61 76 65 20 74 6f 20 6d 61 6e 75 61 ll have to manua
0620: 6c 6c 79 20 67 6f 20 69 6e 74 6f 20 74 68 65 20 lly go into the
0630: 22 74 74 66 2d 66 75 6e 63 74 69 6f 6e 73 2e 73 "ttf-functions.s
0640: 73 22 20 66 69 6c 65 20 61 6e 64 20 63 68 61 6e s" file and chan
0650: 67 65 20 61 6c 6c 20 69 6e 73 74 61 6e 63 65 73 ge all instances
0660: 20 6f 66 20 28 73 64 6c 2d 63 6f 6c 6f 72 2d 74 of (sdl-color-t
0670: 29 20 74 6f 20 73 6f 6d 65 74 68 69 6e 67 20 68 ) to something h
0680: 61 72 6d 6c 65 73 73 20 6c 69 6b 65 20 61 6e 20 armless like an
0690: 69 6e 74 2e 20 20 57 6f 72 6b 20 61 6c 73 6f 20 int. Work also
06a0: 62 65 69 6e 67 20 64 6f 6e 65 20 6f 6e 20 66 69 being done on fi
06b0: 6c 74 65 72 69 6e 67 20 74 68 65 73 65 20 6f 75 ltering these ou
06c0: 74 20 73 6f 20 61 75 74 6f 6d 61 74 69 63 20 67 t so automatic g
06d0: 65 6e 65 72 61 74 69 6f 6e 20 63 61 6e 20 72 65 eneration can re
06e0: 73 75 6d 65 2e sume.