WWText.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*****************************************************************************/
  2. /* ここから */
  3. /*****************************************************************************/
  4. #include "WWTextP.h"
  5. #include "WonX.h"
  6. /* フォントのビットマップデータ */
  7. #include "WWTextFonts.c"
  8. /*****************************************************************************/
  9. /* メンバ関数の定義 */
  10. /*****************************************************************************/
  11. /*===========================================================================*/
  12. /* メンバの取得 */
  13. /*===========================================================================*/
  14. WWScreen WWText_GetScreen(WWText t) { return (t->screen); }
  15. int WWText_GetX(WWText t) { return (t->x); }
  16. int WWText_GetY(WWText t) { return (t->y); }
  17. int WWText_GetWidth( WWText t) { return (t->width ); }
  18. int WWText_GetHeight(WWText t) { return (t->height); }
  19. int WWText_GetBase(WWText t) { return (t->base); }
  20. WWPalette WWText_GetPalette(WWText t) { return (t->palette); }
  21. static WWCharacter WWText_GetFont(WWText t, int n) { return (t->font[n]); }
  22. /*===========================================================================*/
  23. /* メンバの設定 */
  24. /*===========================================================================*/
  25. WWScreen WWText_SetScreen(WWText t, WWScreen s) { return (t->screen = s); }
  26. int WWText_SetX(WWText t, int n) { return (t->x = n); }
  27. int WWText_SetY(WWText t, int n) { return (t->y = n); }
  28. int WWText_SetWidth( WWText t, int n) { return (t->width = n); }
  29. int WWText_SetHeight(WWText t, int n) { return (t->height = n); }
  30. int WWText_SetBase(WWText t, int n) { return (t->base = n); }
  31. WWPalette WWText_SetPalette(WWText t, WWPalette p) { return (t->palette = p); }
  32. static WWCharacter WWText_SetFont(WWText t, int n, WWCharacter c)
  33. { return (t->font[n] = c); }
  34. int WWText_SetTextWindow(WWText ww_text, int x, int y,
  35. int width, int height, int base,
  36. WWDisplay ww_display)
  37. {
  38. int tx, ty, c;
  39. WWCharacter ww_character;
  40. WWText_SetX(ww_text, x);
  41. WWText_SetY(ww_text, y);
  42. WWText_SetWidth(ww_text, width);
  43. WWText_SetHeight(ww_text, height);
  44. WWText_SetBase(ww_text, base);
  45. c = WWText_GetBase(ww_text);
  46. for (ty = 0; ty < WWText_GetHeight(ww_text); ty++) {
  47. for (tx = 0; tx < WWText_GetWidth(ww_text); tx++) {
  48. if (c >= 512) WonX_Error("WWText_SetTextWindow", "Over character.");
  49. ww_character = WWDisplay_GetCharacter(ww_display, c);
  50. WWCharacter_ClearAllPixels(ww_character);
  51. WWScreen_SetCharacter(WWText_GetScreen(ww_text),
  52. WWText_GetX(ww_text) + tx,
  53. WWText_GetY(ww_text) + ty,
  54. ww_character);
  55. c++;
  56. }
  57. }
  58. return (0);
  59. }
  60. int WWText_PutCharacter(WWText ww_text, int x, int y, int character,
  61. WWDisplay ww_display)
  62. {
  63. WWCharacter ww_character;
  64. int j, k, n;
  65. unsigned char pixel;
  66. int f, b;
  67. unsigned char bitmap[2];
  68. if ((character < 0) || (character > 127)) {
  69. WonX_Warning("WWText_PutCharacter", "Character number is out of range.");
  70. return (-1);
  71. }
  72. /*
  73. * テキスト表示は,text_window_init() で指定したテキストウインドウの
  74. * 座標系で行う(らしい).(ウインドウ内の左上が(0,0)になる)
  75. */
  76. if ( (x < 0) || (x > WWText_GetWidth( ww_text) - 1) ||
  77. (y < 0) || (y > WWText_GetHeight(ww_text) - 1) ) {
  78. WonX_Warning("WWText_PutCharacter", "Position is out of range.");
  79. return (-1);
  80. }
  81. #if 0
  82. n = WWText_GetBase(ww_text) +
  83. (x - WWText_GetX(ww_text)) +
  84. (y - WWText_GetY(ww_text)) * WWText_GetWidth(ww_text);
  85. ww_character = WWDisplay_GetCharacter(ww_display, n);
  86. #else
  87. ww_character = WWScreen_GetCharacter(WWText_GetScreen(ww_text),
  88. WWText_GetX(ww_text) + x,
  89. WWText_GetY(ww_text) + y);
  90. #endif
  91. /*
  92. * テキストフォントは
  93. * f = WWDisplay_GetForegroundColor(ww_display);
  94. * b = WWDisplay_GetBackgroundColor(ww_display);
  95. * で描画する必要があるため,描画のたびにビットマップをコピーする必要がある.
  96. * で,カラー化の際に,そのように修正した.
  97. * よって,テキストの初期化時に WWCharacter の配列を作成する必要は
  98. * 無くなったので,WWCharacter の配列はいずれ削除すること.
  99. */
  100. #if 0
  101. WWCharacter_CopyAllPixels(ww_character, WWText_GetFont(ww_text, character));
  102. #else
  103. f = WWDisplay_GetForegroundColor(ww_display);
  104. b = WWDisplay_GetBackgroundColor(ww_display);
  105. n = character * 8;
  106. for (j = 0; j < 8; j++) {
  107. bitmap[0] = 0;
  108. bitmap[1] = 0;
  109. for (k = 0; k < 8; k++) {
  110. pixel = (fonts[n] & (1 << k)) ? f : b;
  111. bitmap[0] |= ( pixel & 1) << k;
  112. bitmap[1] |= ((pixel >> 1) & 1) << k;
  113. }
  114. WWCharacter_SetBitmap(ww_character, j*2 , bitmap[0]);
  115. WWCharacter_SetBitmap(ww_character, j*2+1, bitmap[1]);
  116. n++;
  117. }
  118. #endif
  119. /* 表示時にパレットを設定するのでいいのか? 不明 */
  120. WWScreen_SetPalette(WWText_GetScreen(ww_text),
  121. WWText_GetX(ww_text) + x,
  122. WWText_GetY(ww_text) + y,
  123. WWText_GetPalette(ww_text));
  124. return (character);
  125. }
  126. /*===========================================================================*/
  127. /* オブジェクトの生成と消去 */
  128. /*===========================================================================*/
  129. WWText WWText_Create(WWScreen screen,
  130. int x, int y, int width, int height,
  131. WWPalette palette)
  132. {
  133. WWText ww_text;
  134. WWCharacter ww_character;
  135. int i, j, k, n;
  136. unsigned char pixel;
  137. int f, b;
  138. unsigned char bitmap[2];
  139. ww_text = (WWText)malloc(sizeof(_WWText));
  140. if (ww_text == NULL) WonX_Error("WWText_Create", "Cannot allocate memory.");
  141. WWText_SetScreen(ww_text, screen);
  142. WWText_SetX(ww_text, x);
  143. WWText_SetY(ww_text, y);
  144. WWText_SetWidth( ww_text, width );
  145. WWText_SetHeight(ww_text, height);
  146. WWText_SetPalette(ww_text, palette);
  147. /* 以下は,
  148. f = WWDisplay_GetForegroundColor(ww_display);
  149. b = WWDisplay_GetBackgroundColor(ww_display);
  150. で取得すべきかもしれない
  151. */
  152. f = 3;
  153. b = 0;
  154. n = 0;
  155. for (i = 0; i < 128; i++) {
  156. ww_character = WWCharacter_Create(i);
  157. for (j = 0; j < 8; j++) {
  158. bitmap[0] = 0;
  159. bitmap[1] = 0;
  160. for (k = 0; k < 8; k++) {
  161. pixel = (fonts[n] & (1 << k)) ? f : b;
  162. bitmap[0] |= ( pixel & 1) << k;
  163. bitmap[1] |= ((pixel >> 1) & 1) << k;
  164. }
  165. WWCharacter_SetBitmap(ww_character, j*2 , bitmap[0]);
  166. WWCharacter_SetBitmap(ww_character, j*2+1, bitmap[1]);
  167. n++;
  168. }
  169. WWText_SetFont(ww_text, i, ww_character);
  170. }
  171. return (ww_text);
  172. }
  173. WWText WWText_Destroy(WWText ww_text)
  174. {
  175. int i;
  176. if (ww_text == NULL) WonX_Error("WWText_Destroy", "Object is not created.");
  177. for (i = 0; i < 128; i++) {
  178. if (WWText_GetFont(ww_text, i))
  179. WWText_SetFont(ww_text, i,
  180. WWCharacter_Destroy(WWText_GetFont(ww_text, i)));
  181. }
  182. free(ww_text);
  183. return (NULL);
  184. }
  185. /*****************************************************************************/
  186. /* ここまで */
  187. /*****************************************************************************/
  188. /*****************************************************************************/
  189. /* End of File. */
  190. /*****************************************************************************/