fbutil.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (c) 2019 Clementine Computing LLC.
  3. *
  4. * This file is part of PopuFare.
  5. *
  6. * PopuFare is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * PopuFare is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #define XRES (640)
  21. #define YRES (480)
  22. #define PIXELS (XRES * YRES)
  23. int open_framebuffer_nondestructive();
  24. int open_framebuffer();
  25. void close_framebuffer();
  26. void set_color(int r, int g, int b);
  27. void set_bgcolor(int r, int g, int b);
  28. void set_color_t(int r, int g, int b, int a);
  29. void set_bgcolor_t(int r, int g, int b, int a);
  30. void cls();
  31. void set_pos(int x, int y);
  32. void line_to(int xdest, int ydest);
  33. void box(int x, int y);
  34. void box_fill(int x, int y);
  35. void set_font(unsigned char font);
  36. void print_string(char *str, int bkgr);
  37. void font_cell_size(int *w, int *h);
  38. void set_backlight(int fd, int on);
  39. void beep(int fd, int hz, int milis);
  40. int translate_ts_x(unsigned rawx);
  41. int translate_ts_y(unsigned rawy);
  42. int present_framebuffer();
  43. void reset_clip_rect();
  44. void set_clip_rect(unsigned x, unsigned y, unsigned xx, unsigned yy);
  45. void get_clip_rect(unsigned *x, unsigned *y, unsigned *xx, unsigned *yy);
  46. #define BLENDMODE_DARK (0)
  47. #define BLENDMODE_LIGHT (1)
  48. //This function selects which of the two blend modes will be used for subsequent blend operations
  49. //when a pixel is plotted that has its blend flag set. This is quick because it just selects a differnt
  50. //pre-computed-at-compile-time table.
  51. //
  52. void select_blend_mode(int mode);
  53. //This function is VERY slow as it precomputes the results of every
  54. //possible alpha blending operation and stores it in a table that is
  55. //normally generated at compile-time with the two tables being filled
  56. //with reasonable defaults:
  57. //
  58. // BLENDMODE_DARK is the dark table and uses an alpha of ALPHA_DRK (usually 75% opaque)
  59. // BLENDMODE_LIGHT is the light table and uses an alpha of ALPHA_LGT (usually 50% opaque)
  60. //
  61. // (so yeah, don't call this function you bastard!)
  62. //
  63. void set_alpha_level(unsigned int alpha, unsigned int mode);
  64. typedef unsigned char pixel;
  65. #define FBCOLOR_RED ((pixel)0x60)
  66. #define FBCOLOR_DKRED ((pixel)0x20)
  67. #define FBCOLOR_GREEN ((pixel)0x1C)
  68. #define FBCOLOR_DKGREEN ((pixel)0x10)
  69. #define FBCOLOR_BLUE ((pixel)0x03)
  70. #define FBCOLOR_DKBLUE ((pixel)0x02)
  71. #define FBCOLOR_YELLOW (FBCOLOR_RED | FBCOLOR_GREEN)
  72. #define FBCOLOR_CYAN (FBCOLOR_GREEN | FBCOLOR_BLUE)
  73. #define FBCOLOR_MAGENTA (FBCOLOR_BLUE | FBCOLOR_RED)
  74. #define FBCOLOR_DKYELLOW (FBCOLOR_DKRED | FBCOLOR_DKGREEN)
  75. #define FBCOLOR_DKCYAN (FBCOLOR_DKGREEN | FBCOLOR_DKBLUE)
  76. #define FBCOLOR_DKMAGENTA (FBCOLOR_DKBLUE | FBCOLOR_DKRED)
  77. #define FBCOLOR_WHITE ((pixel)0x7F)
  78. #define FBCOLOR_GRAY ((pixel)0x52)
  79. #define FBCOLOR_DKGRAY ((pixel)0x29)
  80. #define FBCOLOR_BLACK ((pixel)0x00)
  81. #define FBCOLOR_LTRED (FBCOLOR_RED | FBCOLOR_GRAY)
  82. #define FBCOLOR_LTGREEN (FBCOLOR_GREEN | FBCOLOR_GRAY)
  83. #define FBCOLOR_LTBLUE (FBCOLOR_BLUE | FBCOLOR_GRAY)
  84. #define FBCOLOR_LTYELLOW (FBCOLOR_YELLOW | FBCOLOR_GRAY)
  85. #define FBCOLOR_LTMAGENTA (FBCOLOR_MAGENTA | FBCOLOR_GRAY)
  86. #define FBCOLOR_LTCYAN (FBCOLOR_CYAN | FBCOLOR_GRAY)
  87. //This value can be OR'd with any of the above colors as a modifier
  88. #define FBCOLOR_TRANSLUCENT ((pixel)0x80)
  89. typedef struct named_color_struct
  90. {
  91. char *name; //this is the name of the color (for the purposes of config files)
  92. //a NULL value is an end-of-array sentinel.
  93. pixel color; //this is the raw color associated with that name
  94. } named_color;
  95. //This function looks up any of our named colors, or converts hex colors in the following formats:
  96. // #XX 8 bit raw color in hex (bits: TRRGGGBB)
  97. // #RRGGBB 24 bit true color in hex
  98. // #RRGGBBAA 32 bit true color w/ alpha in hex
  99. pixel string_to_color(char *str);
  100. void set_rawcolor(pixel color);
  101. void set_bgrawcolor(pixel color);
  102. typedef struct sprite_struct
  103. {
  104. unsigned width;
  105. unsigned height;
  106. pixel *data;
  107. } sprite;
  108. void draw_sprite(sprite *s);
  109. int begin_touchscreen_calibration();
  110. int draw_touchscreen_calibration();
  111. int advance_touchscreen_calibration(int rawx, int rawy, int down);