TEXT.C 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /******************************************************************************
  2. Plush Version 1.1
  3. text.c
  4. Text code and data (8xX bitmapped)
  5. Copyright (c) 1996-2000, Justin Frankel
  6. ******************************************************************************/
  7. #include "plush.h"
  8. #include <stdarg.h>
  9. static pl_uChar font_height = 16;
  10. static pl_uChar *current_font = plText_DefaultFont;
  11. void plTextSetFont(pl_uChar *font, pl_uChar height) {
  12. current_font = font;
  13. font_height = height;
  14. }
  15. void plTextPutChar(pl_Cam *cam, pl_sInt x, pl_sInt y, pl_Float z,
  16. pl_uChar color, pl_uChar c) {
  17. pl_uChar *font = current_font + (c*font_height);
  18. pl_sInt offset = x+(y*cam->ScreenWidth);
  19. pl_ZBuffer zz = (pl_ZBuffer) (1.0/z);
  20. pl_sInt xx = x, a;
  21. pl_uChar len = font_height;
  22. pl_uChar ch;
  23. pl_uChar *outmem;
  24. pl_ZBuffer *zbuffer;
  25. if (y+font_height < cam->ClipTop || y >= cam->ClipBottom) return;
  26. if (y < cam->ClipTop) {
  27. font += (cam->ClipTop-y);
  28. offset += (cam->ClipTop-y)*cam->ScreenWidth;
  29. len -= (cam->ClipTop-y);
  30. y = cam->ClipTop;
  31. }
  32. if (y+font_height >= cam->ClipBottom) {
  33. len = cam->ClipBottom-y;
  34. }
  35. if (len > 0) {
  36. if (cam->zBuffer && z != 0.0) do {
  37. outmem = cam->frameBuffer + offset;
  38. zbuffer = cam->zBuffer + offset;
  39. offset += cam->ScreenWidth;
  40. xx = x;
  41. ch = *font++;
  42. a = 128;
  43. while (a) {
  44. if (xx >= cam->ClipRight) break;
  45. if (xx++ >= cam->ClipLeft)
  46. if (ch & a)
  47. if (zz > *zbuffer) {
  48. *zbuffer = zz;
  49. *outmem = color;
  50. }
  51. zbuffer++;
  52. outmem++;
  53. a >>= 1;
  54. }
  55. if (a) break;
  56. } while (--len);
  57. else do {
  58. outmem = cam->frameBuffer + offset;
  59. offset += cam->ScreenWidth;
  60. xx = x;
  61. ch = *font++;
  62. a = 128;
  63. while (a) {
  64. if (xx >= cam->ClipRight) break;
  65. if (xx++ >= cam->ClipLeft) if (ch & a) *outmem = color;
  66. outmem++;
  67. a >>= 1;
  68. }
  69. if (a) break;
  70. } while (--len);
  71. }
  72. }
  73. void plTextPutStr(pl_Cam *cam, pl_sInt x, pl_sInt y, pl_Float z,
  74. pl_uChar color, pl_sChar *string) {
  75. pl_sInt xx = x;
  76. while (*string) {
  77. switch (*string) {
  78. case '\n': y += font_height; xx = x; break;
  79. case ' ': xx += 8; break;
  80. case '\r': break;
  81. case '\t': xx += 8*5; break;
  82. default:
  83. plTextPutChar(cam,xx,y,z,color,(pl_uChar) *string);
  84. xx += 8;
  85. break;
  86. }
  87. string++;
  88. }
  89. }
  90. void plTextPutStrW(pl_Cam* cam, pl_sInt x, pl_sInt y, pl_Float z,
  91. pl_uChar color, const wchar_t* string) {
  92. pl_sInt xx = x;
  93. while (*string) {
  94. switch (*string) {
  95. case L'\n': y += font_height; xx = x; break;
  96. case L' ': xx += 8; break;
  97. case L'\r': break;
  98. case L'\t': xx += 8 * 5; break;
  99. default:
  100. plTextPutChar(cam, xx, y, z, color, (pl_uChar)*string);
  101. xx += 8;
  102. break;
  103. }
  104. string++;
  105. }
  106. }
  107. void plTextPrintf(pl_Cam *cam, pl_sInt x, pl_sInt y, pl_Float z,
  108. pl_uChar color, pl_sChar *format, ...) {
  109. va_list arglist;
  110. pl_sChar str[256];
  111. va_start(arglist, format);
  112. vsprintf((char *)str, (char *) format,arglist);
  113. va_end(arglist);
  114. plTextPutStr(cam,x,y,z,color,str);
  115. }