| 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 volatile int full_palette; |
|---|
| 14 | static color cl; |
|---|
| 15 | static volatile char counter; |
|---|
| 16 | static int palette_mode; |
|---|
| 17 | static void (*palette_on_select)(color clr); |
|---|
| 18 | static int gui_palette_redraw; |
|---|
| 19 | |
|---|
| 20 | #define COUNTER_N 100 |
|---|
| 21 | |
|---|
| 22 | //------------------------------------------------------------------- |
|---|
| 23 | void gui_palette_init(int mode, color st_color, void (*on_select)(color clr)) { |
|---|
| 24 | full_palette = (mode!=PALETTE_MODE_SELECT); |
|---|
| 25 | cl = st_color; |
|---|
| 26 | palette_mode = mode; |
|---|
| 27 | palette_on_select = on_select; |
|---|
| 28 | counter = COUNTER_N; |
|---|
| 29 | gui_palette_redraw = 1; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | //------------------------------------------------------------------- |
|---|
| 33 | void gui_palette_kbd_process() { |
|---|
| 34 | switch (kbd_get_autoclicked_key()) { |
|---|
| 35 | case KEY_DOWN: |
|---|
| 36 | if (!full_palette) { |
|---|
| 37 | cl = ((((cl>>4)+1)<<4)|(cl&0x0f))&0xFF; |
|---|
| 38 | gui_palette_redraw = 1; |
|---|
| 39 | } |
|---|
| 40 | break; |
|---|
| 41 | case KEY_UP: |
|---|
| 42 | if (!full_palette) { |
|---|
| 43 | cl = ((((cl>>4)-1)<<4)|(cl&0x0f))&0xFF; |
|---|
| 44 | gui_palette_redraw = 1; |
|---|
| 45 | } |
|---|
| 46 | break; |
|---|
| 47 | case KEY_LEFT: |
|---|
| 48 | if (!full_palette) { |
|---|
| 49 | cl = ((((cl&0x0f)-1)&0x0f)|(cl&0xf0))&0xFF; |
|---|
| 50 | gui_palette_redraw = 1; |
|---|
| 51 | } |
|---|
| 52 | break; |
|---|
| 53 | case KEY_RIGHT: |
|---|
| 54 | if (!full_palette) { |
|---|
| 55 | cl = ((((cl&0x0f)+1)&0x0f)|(cl&0xf0))&0xFF; |
|---|
| 56 | gui_palette_redraw = 1; |
|---|
| 57 | } |
|---|
| 58 | break; |
|---|
| 59 | case KEY_SET: |
|---|
| 60 | if (palette_mode!=PALETTE_MODE_SELECT) { |
|---|
| 61 | full_palette = !full_palette; |
|---|
| 62 | counter = 0; |
|---|
| 63 | gui_palette_redraw = 1; |
|---|
| 64 | } else { |
|---|
| 65 | if (palette_on_select) |
|---|
| 66 | palette_on_select(cl); |
|---|
| 67 | gui_set_mode(GUI_MODE_MENU); |
|---|
| 68 | } |
|---|
| 69 | break; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | //------------------------------------------------------------------- |
|---|
| 74 | void gui_palette_draw() { |
|---|
| 75 | unsigned int x, y; |
|---|
| 76 | char f=0; |
|---|
| 77 | color c; |
|---|
| 78 | static char buf[64]; |
|---|
| 79 | |
|---|
| 80 | switch (palette_mode) { |
|---|
| 81 | case PALETTE_MODE_DEFAULT: |
|---|
| 82 | if (full_palette) { |
|---|
| 83 | if (!counter || counter == COUNTER_N) { |
|---|
| 84 | for (y=0; y<screen_height; ++y) { |
|---|
| 85 | for (x=0; x<screen_width; ++x) { |
|---|
| 86 | c = ((y*16/screen_height)<<4)|(x*16/screen_width); |
|---|
| 87 | draw_pixel(x, y, c); |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | if (counter) { |
|---|
| 91 | draw_txt_string(6, 7, lang_str(LANG_PALETTE_TEXT_1), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); |
|---|
| 92 | draw_txt_string(6, 8, lang_str(LANG_PALETTE_TEXT_2), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | if (counter) |
|---|
| 96 | --counter; |
|---|
| 97 | f=1; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | if (!full_palette) { |
|---|
| 101 | sprintf(buf, " %s: 0x%02X ", lang_str(LANG_PALETTE_TEXT_COLOR), cl); |
|---|
| 102 | draw_txt_string(0, 0, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); |
|---|
| 103 | draw_filled_rect(20, 20, screen_width-20, screen_height-20, MAKE_COLOR(cl, COLOR_WHITE)); |
|---|
| 104 | sprintf(buf, lang_str(LANG_PALETTE_TEXT_SELECT_COLOR), "\x18\x19\x1b\x1a"); |
|---|
| 105 | draw_txt_string(0, 14, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); |
|---|
| 106 | } |
|---|
| 107 | break; |
|---|
| 108 | case PALETTE_MODE_SELECT: |
|---|
| 109 | if (gui_palette_redraw) { |
|---|
| 110 | #define CELL_SIZE 13 |
|---|
| 111 | #define BORDER_SIZE 8 |
|---|
| 112 | #define CELL_ZOOM 5 |
|---|
| 113 | draw_string(screen_width-29*FONT_WIDTH, 0, " Use \x18\x19\x1b\x1a to change color ", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); |
|---|
| 114 | sprintf(buf, " %s: 0x%02hX ", lang_str(LANG_PALETTE_TEXT_COLOR), (unsigned char)cl); |
|---|
| 115 | draw_txt_string(0, 0, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE)); |
|---|
| 116 | for (y=0; y<16; ++y) { |
|---|
| 117 | for (x=0; x<16; ++x) { |
|---|
| 118 | c = (y<<4)|x; |
|---|
| 119 | draw_filled_rect(BORDER_SIZE+x*CELL_SIZE, BORDER_SIZE+y*CELL_SIZE+FONT_HEIGHT, BORDER_SIZE+(x+1)*CELL_SIZE, BORDER_SIZE+(y+1)*CELL_SIZE+FONT_HEIGHT, MAKE_COLOR(c, COLOR_BLACK)); |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | draw_filled_rect(0, FONT_HEIGHT, screen_width-1, FONT_HEIGHT+BORDER_SIZE-1, MAKE_COLOR(COLOR_GREY, COLOR_GREY)); //top |
|---|
| 123 | draw_filled_rect(0, FONT_HEIGHT+BORDER_SIZE+16*CELL_SIZE+1, screen_width-1, FONT_HEIGHT+BORDER_SIZE+16*CELL_SIZE+BORDER_SIZE, MAKE_COLOR(COLOR_GREY, COLOR_GREY)); //bottom |
|---|
| 124 | draw_filled_rect(0, FONT_HEIGHT+BORDER_SIZE, BORDER_SIZE-1, FONT_HEIGHT+BORDER_SIZE+16*CELL_SIZE, MAKE_COLOR(COLOR_GREY, COLOR_GREY)); //left |
|---|
| 125 | draw_filled_rect(BORDER_SIZE+16*CELL_SIZE+1, FONT_HEIGHT+BORDER_SIZE, BORDER_SIZE+16*CELL_SIZE+BORDER_SIZE, FONT_HEIGHT+BORDER_SIZE+16*CELL_SIZE, MAKE_COLOR(COLOR_GREY, COLOR_GREY)); //middle |
|---|
| 126 | draw_filled_rect(screen_width-BORDER_SIZE, FONT_HEIGHT+BORDER_SIZE, screen_width-1, FONT_HEIGHT+BORDER_SIZE+16*CELL_SIZE, MAKE_COLOR(COLOR_GREY, COLOR_GREY)); //right |
|---|
| 127 | |
|---|
| 128 | y=(cl>>4)&0x0F; x=cl&0x0F; |
|---|
| 129 | draw_filled_rect(BORDER_SIZE+x*CELL_SIZE-CELL_ZOOM, FONT_HEIGHT+BORDER_SIZE+y*CELL_SIZE-CELL_ZOOM, BORDER_SIZE+(x+1)*CELL_SIZE+CELL_ZOOM, FONT_HEIGHT+BORDER_SIZE+(y+1)*CELL_SIZE+CELL_ZOOM, MAKE_COLOR(cl, COLOR_RED)); //selected |
|---|
| 130 | draw_rect(BORDER_SIZE+x*CELL_SIZE-CELL_ZOOM-1, FONT_HEIGHT+BORDER_SIZE+y*CELL_SIZE-CELL_ZOOM-1, BORDER_SIZE+(x+1)*CELL_SIZE+CELL_ZOOM+1, FONT_HEIGHT+BORDER_SIZE+(y+1)*CELL_SIZE+CELL_ZOOM+1, COLOR_RED); //selected |
|---|
| 131 | draw_filled_rect(BORDER_SIZE+16*CELL_SIZE+BORDER_SIZE+1, FONT_HEIGHT+BORDER_SIZE, screen_width-BORDER_SIZE-1, FONT_HEIGHT+BORDER_SIZE+16*CELL_SIZE, MAKE_COLOR(cl, COLOR_WHITE)); |
|---|
| 132 | gui_palette_redraw = 0; |
|---|
| 133 | } |
|---|
| 134 | break; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | |
|---|