| 1 | #include "stdlib.h" |
|---|
| 2 | #include "platform.h" |
|---|
| 3 | #include "core.h" |
|---|
| 4 | #include "keyboard.h" |
|---|
| 5 | #include "conf.h" |
|---|
| 6 | #include "lang.h" |
|---|
| 7 | #include "gui.h" |
|---|
| 8 | #include "gui_draw.h" |
|---|
| 9 | #include "gui_lang.h" |
|---|
| 10 | #include "gui_palette.h" |
|---|
| 11 | |
|---|
| 12 | //------------------------------------------------------------------- |
|---|
| 13 | static color cl; |
|---|
| 14 | static int palette_mode; |
|---|
| 15 | static void (*palette_on_select)(color clr); |
|---|
| 16 | static int gui_palette_redraw; |
|---|
| 17 | |
|---|
| 18 | //------------------------------------------------------------------- |
|---|
| 19 | void gui_palette_init(int mode, color st_color, void (*on_select)(color clr)) { |
|---|
| 20 | cl = st_color; |
|---|
| 21 | palette_mode = mode; |
|---|
| 22 | palette_on_select = on_select; |
|---|
| 23 | gui_palette_redraw = 1; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | //------------------------------------------------------------------- |
|---|
| 27 | void gui_palette_kbd_process() { |
|---|
| 28 | switch (kbd_get_autoclicked_key()) |
|---|
| 29 | { |
|---|
| 30 | case KEY_DOWN: |
|---|
| 31 | cl = (((cl+16)&0xf0)|(cl&0x0f)); |
|---|
| 32 | gui_palette_redraw = 1; |
|---|
| 33 | break; |
|---|
| 34 | case KEY_UP: |
|---|
| 35 | cl = (((cl-16)&0xf0)|(cl&0x0f)); |
|---|
| 36 | gui_palette_redraw = 1; |
|---|
| 37 | break; |
|---|
| 38 | case KEY_LEFT: |
|---|
| 39 | cl = ((cl&0xf0)|((cl-1)&0x0f)); |
|---|
| 40 | gui_palette_redraw = 1; |
|---|
| 41 | break; |
|---|
| 42 | case KEY_RIGHT: |
|---|
| 43 | cl = ((cl&0xf0)|((cl+1)&0x0f)); |
|---|
| 44 | gui_palette_redraw = 1; |
|---|
| 45 | break; |
|---|
| 46 | case KEY_SET: |
|---|
| 47 | if (palette_mode == PALETTE_MODE_SELECT) |
|---|
| 48 | { |
|---|
| 49 | if (palette_on_select) |
|---|
| 50 | palette_on_select(cl); |
|---|
| 51 | gui_set_mode(GUI_MODE_MENU); |
|---|
| 52 | } |
|---|
| 53 | break; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | //------------------------------------------------------------------- |
|---|
| 58 | #define CELL_SIZE 13 |
|---|
| 59 | #define BORDER_SIZE 8 |
|---|
| 60 | #define CELL_ZOOM 6 |
|---|
| 61 | #define DISP_LEFT BORDER_SIZE |
|---|
| 62 | #define DISP_RIGHT (BORDER_SIZE + CELL_SIZE * 16) |
|---|
| 63 | #define DISP_TOP (FONT_HEIGHT + BORDER_SIZE) |
|---|
| 64 | #define DISP_BOTTOM (FONT_HEIGHT + BORDER_SIZE + CELL_SIZE * 16) |
|---|
| 65 | |
|---|
| 66 | void gui_palette_draw() { |
|---|
| 67 | unsigned int x, y; |
|---|
| 68 | char f=0; |
|---|
| 69 | color c; |
|---|
| 70 | static char buf[64]; |
|---|
| 71 | |
|---|
| 72 | if (gui_palette_redraw) |
|---|
| 73 | { |
|---|
| 74 | // Draw top text line - current color + instructions |
|---|
| 75 | draw_string(screen_width-29*FONT_WIDTH, 0, " Use \x18\x19\x1b\x1a to change color ", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); |
|---|
| 76 | sprintf(buf, " %s: 0x%02hX ", lang_str(LANG_PALETTE_TEXT_COLOR), (unsigned char)cl); |
|---|
| 77 | draw_txt_string(0, 0, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); |
|---|
| 78 | |
|---|
| 79 | // Draw Palette color boxes |
|---|
| 80 | c = COLOR_BLACK; |
|---|
| 81 | for (y=DISP_TOP; y<DISP_BOTTOM; y+=CELL_SIZE) |
|---|
| 82 | { |
|---|
| 83 | for (x=DISP_LEFT; x<DISP_RIGHT; x+=CELL_SIZE, c+=0x0100) |
|---|
| 84 | { |
|---|
| 85 | draw_filled_rect(x, y, x+CELL_SIZE, y+CELL_SIZE, c); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | // Draw gray borders |
|---|
| 90 | draw_rect_thick(0, DISP_TOP-BORDER_SIZE, screen_width-1, screen_height-1, COLOR_GREY, BORDER_SIZE); // outer border |
|---|
| 91 | draw_filled_rect(DISP_RIGHT+1, DISP_TOP, DISP_RIGHT+BORDER_SIZE, DISP_BOTTOM, MAKE_COLOR(COLOR_GREY, COLOR_GREY)); //middle |
|---|
| 92 | |
|---|
| 93 | // Co-ordintate of selected color |
|---|
| 94 | y = DISP_TOP + ((cl>>4)&0x0F) * CELL_SIZE; |
|---|
| 95 | x = DISP_LEFT + (cl&0x0F) * CELL_SIZE; |
|---|
| 96 | |
|---|
| 97 | // Highlight selected color |
|---|
| 98 | draw_filled_rect_thick(x-CELL_ZOOM, y-CELL_ZOOM, x+CELL_SIZE+CELL_ZOOM, y+CELL_SIZE+CELL_ZOOM, MAKE_COLOR(cl, COLOR_RED), 2); |
|---|
| 99 | |
|---|
| 100 | // Fill 'sample' area with selected color |
|---|
| 101 | draw_filled_rect(DISP_RIGHT+BORDER_SIZE+1, DISP_TOP, screen_width-BORDER_SIZE-1, DISP_BOTTOM, MAKE_COLOR(cl, COLOR_WHITE)); |
|---|
| 102 | |
|---|
| 103 | gui_palette_redraw = 0; |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | |
|---|