WWLCDPanel.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*****************************************************************************/
  2. /* ここから */
  3. /*****************************************************************************/
  4. #include "WWLCDPanelP.h"
  5. #include "etc.h"
  6. /*****************************************************************************/
  7. /* メンバ関数の定義 */
  8. /*****************************************************************************/
  9. int WWLCDPanel_GetWidth( WWLCDPanel p) { return (p->width ); }
  10. int WWLCDPanel_GetHeight(WWLCDPanel p) { return (p->height); }
  11. int WWLCDPanel_SetWidth( WWLCDPanel p, int n) { return (p->width = n); }
  12. int WWLCDPanel_SetHeight(WWLCDPanel p, int n) { return (p->height = n); }
  13. int WWLCDPanel_ResetCurrent(WWLCDPanel p)
  14. {
  15. return (p->current = 0);
  16. }
  17. int WWLCDPanel_ReverseCurrent(WWLCDPanel p)
  18. {
  19. return (p->current = 1 - p->current);
  20. }
  21. int WWLCDPanel_ResetAllDraw(WWLCDPanel p) { return (p->all_draw = 0); }
  22. int WWLCDPanel_SetAllDraw(WWLCDPanel p) { return (p->all_draw = 1); }
  23. int WWLCDPanel_IsAllDraw(WWLCDPanel p) { return (p->all_draw); }
  24. unsigned char * WWLCDPanel_GetPixelMap(WWLCDPanel p)
  25. {
  26. return (p->pixel[p->current]);
  27. }
  28. /* LCDは1ピクセル16色(4ビット必要) */
  29. static int WWLCDPanel_GetPixelByCurrent(WWLCDPanel lcd_panel, int current,
  30. int x, int y)
  31. {
  32. unsigned char pixel;
  33. if ( (x < 0) || (x > WWLCDPanel_GetWidth( lcd_panel) - 1) ||
  34. (y < 0) || (y > WWLCDPanel_GetHeight(lcd_panel) - 1) )
  35. return (-1);
  36. pixel = lcd_panel->pixel[current][y * WWLCDPanel_GetWidth(lcd_panel) + x];
  37. pixel &= 0x0f;
  38. return ((int)pixel);
  39. }
  40. static int WWLCDPanel_GetOldPixel(WWLCDPanel lcd_panel, int x, int y)
  41. {
  42. return (WWLCDPanel_GetPixelByCurrent(lcd_panel, 1 - lcd_panel->current, x, y));
  43. }
  44. int WWLCDPanel_GetPixel(WWLCDPanel lcd_panel, int x, int y)
  45. {
  46. return (WWLCDPanel_GetPixelByCurrent(lcd_panel, lcd_panel->current, x, y));
  47. }
  48. int WWLCDPanel_SetPixel(WWLCDPanel lcd_panel, int x, int y, int pixel)
  49. {
  50. unsigned char p;
  51. int n;
  52. if ( (x < 0) || (x > WWLCDPanel_GetWidth( lcd_panel) - 1) ||
  53. (y < 0) || (y > WWLCDPanel_GetHeight(lcd_panel) - 1) )
  54. return (-1);
  55. p = ((unsigned char)pixel) & 0x0f;
  56. n = y * WWLCDPanel_GetWidth(lcd_panel) + x;
  57. lcd_panel->pixel[lcd_panel->current][n] = p;
  58. return (pixel);
  59. }
  60. int WWLCDPanel_IsPixelChanged(WWLCDPanel lcd_panel, int x, int y)
  61. {
  62. int old_pixel;
  63. int current_pixel;
  64. if (WWLCDPanel_IsAllDraw(lcd_panel)) return (1);
  65. old_pixel = WWLCDPanel_GetOldPixel(lcd_panel, x, y);
  66. current_pixel = WWLCDPanel_GetPixel(lcd_panel, x, y);
  67. return (!(old_pixel == current_pixel));
  68. }
  69. WWLCDPanel WWLCDPanel_Create(int width, int height)
  70. {
  71. WWLCDPanel lcd_panel;
  72. int x, y, i;
  73. lcd_panel = (WWLCDPanel)malloc(sizeof(_WWLCDPanel));
  74. if (lcd_panel == NULL)
  75. Wonx_Error("WWLCDPanel_Create", "Cannot allocate memory.");
  76. WWLCDPanel_SetWidth( lcd_panel, width);
  77. WWLCDPanel_SetHeight(lcd_panel, height);
  78. for (i = 0; i < 2; i++) {
  79. lcd_panel->pixel[i] =
  80. (unsigned char *)malloc(sizeof(unsigned char) *
  81. WWLCDPanel_GetWidth(lcd_panel) *
  82. WWLCDPanel_GetHeight(lcd_panel));
  83. }
  84. for (y = 0; y < lcd_panel->height; y++) {
  85. for (x = 0; x < lcd_panel->width / 2; x++) {
  86. WWLCDPanel_SetPixel(lcd_panel, x, y, 0x00);
  87. }
  88. }
  89. WWLCDPanel_ResetCurrent(lcd_panel);
  90. WWLCDPanel_SetAllDraw(lcd_panel); /* 初回は全画面を描画する */
  91. return (lcd_panel);
  92. }
  93. WWLCDPanel WWLCDPanel_Destroy(WWLCDPanel lcd_panel)
  94. {
  95. int i;
  96. if (lcd_panel == NULL) return (NULL);
  97. for (i = 0; i < 2; i++) {
  98. if (lcd_panel->pixel[i]) free(lcd_panel->pixel[i]);
  99. }
  100. free(lcd_panel);
  101. return (NULL);
  102. }
  103. /*****************************************************************************/
  104. /* ここまで */
  105. /*****************************************************************************/
  106. /*****************************************************************************/
  107. /* End of File. */
  108. /*****************************************************************************/