WWText.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. int f, b;
  66. unsigned short int pixel;
  67. unsigned short int bitmap;
  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;
  108. for (k = 0; k < 8; k++) {
  109. pixel = (fonts[n] & (1 << k)) ? f : b;
  110. bitmap |= ( pixel & 1) << k;
  111. bitmap |= ((pixel >> 1) & 1) << (k + 8);
  112. }
  113. WWCharacter_SetBitmapAsShortInt(ww_character, j, bitmap);
  114. n++;
  115. }
  116. #endif
  117. /* 表示時にパレットを設定するのでいいのか? 不明 */
  118. WWScreen_SetPalette(WWText_GetScreen(ww_text),
  119. WWText_GetX(ww_text) + x,
  120. WWText_GetY(ww_text) + y,
  121. WWText_GetPalette(ww_text));
  122. return (character);
  123. }
  124. /*===========================================================================*/
  125. /* オブジェクトの生成と消去 */
  126. /*===========================================================================*/
  127. WWText WWText_Create(WWScreen screen,
  128. int x, int y, int width, int height,
  129. WWPalette palette)
  130. {
  131. WWText ww_text;
  132. WWCharacter ww_character;
  133. int i, j, k, n;
  134. int f, b;
  135. unsigned short int pixel;
  136. unsigned short int bitmap;
  137. ww_text = (WWText)malloc(sizeof(_WWText));
  138. if (ww_text == NULL) WonX_Error("WWText_Create", "Cannot allocate memory.");
  139. WWText_SetScreen(ww_text, screen);
  140. WWText_SetX(ww_text, x);
  141. WWText_SetY(ww_text, y);
  142. WWText_SetWidth( ww_text, width );
  143. WWText_SetHeight(ww_text, height);
  144. WWText_SetPalette(ww_text, palette);
  145. /* 以下は,
  146. f = WWDisplay_GetForegroundColor(ww_display);
  147. b = WWDisplay_GetBackgroundColor(ww_display);
  148. で取得すべきかもしれない
  149. */
  150. f = 3;
  151. b = 0;
  152. n = 0;
  153. for (i = 0; i < 128; i++) {
  154. ww_character = WWCharacter_Create(i);
  155. for (j = 0; j < 8; j++) {
  156. bitmap = 0;
  157. for (k = 0; k < 8; k++) {
  158. pixel = (fonts[n] & (1 << k)) ? f : b;
  159. bitmap |= ( pixel & 1) << k;
  160. bitmap |= ((pixel >> 1) & 1) << (k + 8);
  161. }
  162. WWCharacter_SetBitmapAsShortInt(ww_character, j, bitmap);
  163. n++;
  164. }
  165. WWText_SetFont(ww_text, i, ww_character);
  166. }
  167. return (ww_text);
  168. }
  169. WWText WWText_Destroy(WWText ww_text)
  170. {
  171. int i;
  172. if (ww_text == NULL)
  173. WonX_Error("WWText_Destroy", "Object is not created.");
  174. for (i = 0; i < 128; i++) {
  175. if (WWText_GetFont(ww_text, i))
  176. WWText_SetFont(ww_text, i,
  177. WWCharacter_Destroy(WWText_GetFont(ww_text, i)));
  178. }
  179. free(ww_text);
  180. return (NULL);
  181. }
  182. /*****************************************************************************/
  183. /* ここまで */
  184. /*****************************************************************************/
  185. /*****************************************************************************/
  186. /* End of File. */
  187. /*****************************************************************************/