WWLCDPanel.c 4.1 KB

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