Ctrl+click to pick colors immediately

A keyboard shortcut is now available for picking colors from
the canvas more quickly.  Hold either (left or right) [Ctrl] key
while clicking, and the color selector option will appear.
Release the mouse button over a color on the canvas to choose it
(or outside the canvas to abort).
Closes https://sourceforge.net/p/tuxpaint/feature-requests/209/

Also,
 * Don't play 'bubble' paint sound when color picker or selector
   are aborted (e.g., via their "Back" buttons).
 * Replace many instances of "NUM_COLOR - 1" and "NUM_COLOR - 2"
   (which correspond to color chose via picker (palette) and
   selector (canvas), respectively) with #define's that
   represent them. (Avoid magic numbers.)
This commit is contained in:
Bill Kendrick 2022-01-26 01:07:11 -08:00
parent 269f0cfe3a
commit 83d316a166
2 changed files with 541 additions and 492 deletions

View file

@ -70,10 +70,16 @@ http://www.tuxpaint.org/
* Show a "pipette"-shaped mouse pointer when selecting a * Show a "pipette"-shaped mouse pointer when selecting a
color from the color palette, or the picture. color from the color palette, or the picture.
* WIP Provide a keyboard shortcut for picking colors from * A keyboard shortcut is now available for picking colors from
the canvas more quickly. the canvas more quickly. Hold either (left or right) [Ctrl] key
while clicking, and the color selector option will appear.
Release the mouse button over a color on the canvas to choose it
(or outside the canvas to abort).
Closes https://sourceforge.net/p/tuxpaint/feature-requests/209/ Closes https://sourceforge.net/p/tuxpaint/feature-requests/209/
* Don't play 'bubble' paint sound when color picker or selector
are aborted (e.g., via their "Back" buttons).
* Localization Updates: * Localization Updates:
--------------------- ---------------------
* Albanian translation * Albanian translation

View file

@ -689,6 +689,8 @@ static int NUM_COLORS;
static Uint8 **color_hexes; static Uint8 **color_hexes;
static char **color_names; static char **color_names;
#define COLOR_SELECTOR (NUM_COLORS - 2)
#define COLOR_PICKER (NUM_COLORS - 1)
/* Show debugging stuff: */ /* Show debugging stuff: */
@ -2095,6 +2097,7 @@ static int do_new_dialog_add_colors(SDL_Surface * *thumbs, int num_files, int *d
char * *d_exts, int *white_in_palette); char * *d_exts, int *white_in_palette);
static int do_color_picker(void); static int do_color_picker(void);
static int do_color_sel(int temp_mode); static int do_color_sel(int temp_mode);
static void handle_color_changed(void);
static int do_slideshow(void); static int do_slideshow(void);
static void play_slideshow(int *selected, int num_selected, char *dirname, char **d_names, char **d_exts, int speed); static void play_slideshow(int *selected, int num_selected, char *dirname, char **d_names, char **d_exts, int speed);
@ -2471,6 +2474,7 @@ static void mainloop(void)
(key_unicode > ' ' && key_unicode < 127) ? (char)event.key.keysym.unicode : ' ', (key_unicode > ' ' && key_unicode < 127) ? (char)event.key.keysym.unicode : ' ',
iswprint(key_unicode) ? "" : "not ", (unsigned)key_down); iswprint(key_unicode) ? "" : "not ", (unsigned)key_down);
#endif #endif
if (cur_tool == TOOL_STAMP) if (cur_tool == TOOL_STAMP)
{ {
SDL_Rect r_stamps_sizesel; SDL_Rect r_stamps_sizesel;
@ -4482,17 +4486,19 @@ static void mainloop(void)
cur_color = whichc; cur_color = whichc;
draw_tux_text(TUX_KISS, color_names[cur_color], 1); draw_tux_text(TUX_KISS, color_names[cur_color], 1);
if (cur_color == (unsigned)(NUM_COLORS - 1) || cur_color == (unsigned)(NUM_COLORS - 2)) if (cur_color == (unsigned) COLOR_PICKER || cur_color == (unsigned) COLOR_SELECTOR)
{ {
int chose_color;
disable_avail_tools(); disable_avail_tools();
draw_toolbar(); draw_toolbar();
draw_colors(COLORSEL_CLOBBER_WIPE); draw_colors(COLORSEL_CLOBBER_WIPE);
draw_none(); draw_none();
if (cur_color == (unsigned)(NUM_COLORS - 1)) if (cur_color == (unsigned) COLOR_PICKER)
do_color_picker(); chose_color = do_color_picker();
else else
do_color_sel(0); chose_color = do_color_sel(0);
if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL) if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL)
{ {
@ -4526,7 +4532,10 @@ static void mainloop(void)
else if (cur_tool == TOOL_FILL) else if (cur_tool == TOOL_FILL)
draw_fills(); draw_fills();
if (chose_color)
playsound(screen, 1, SND_BUBBLE, 1, SNDPOS_CENTER, SNDDIST_NEAR); playsound(screen, 1, SND_BUBBLE, 1, SNDPOS_CENTER, SNDDIST_NEAR);
else
playsound(screen, 1, SND_CLICK, 1, SNDPOS_CENTER, SNDDIST_NEAR);
SDL_Flip(screen); SDL_Flip(screen);
} }
@ -4537,23 +4546,38 @@ static void mainloop(void)
playsound(screen, 1, SND_BUBBLE, 1, event.button.x, SNDDIST_NEAR); playsound(screen, 1, SND_BUBBLE, 1, event.button.x, SNDDIST_NEAR);
} }
render_brush(); handle_color_changed();
if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL)
do_render_cur_text(0);
else if (cur_tool == TOOL_MAGIC)
magic_funcs[magics[magic_group][cur_magic[magic_group]].handle_idx].set_color(
magic_api_struct,
color_hexes[cur_color][0],
color_hexes[cur_color][1],
color_hexes[cur_color][2]);
else if (cur_tool == TOOL_STAMP)
clear_cached_stamp();
} }
} }
} }
else if (HIT(r_canvas) && valid_click(event.button.button) && keyglobal == 0) else if (HIT(r_canvas) && valid_click(event.button.button) && keyglobal == 0)
{
Uint8 * kbd_state;
kbd_state = SDL_GetKeyState(NULL);
if ((kbd_state[SDLK_LCTRL] || kbd_state[SDLK_RCTRL]) && colors_are_selectable)
{
int chose_color;
/* Holding [Ctrl] while clicking; switch to temp-mode color selector! */
chose_color = do_color_sel(1);
draw_cur_tool_tip();
draw_colors(COLORSEL_FORCE_REDRAW);
if (chose_color)
{
playsound(screen, 1, SND_BUBBLE, 1, SNDPOS_CENTER, SNDDIST_NEAR);
cur_color = COLOR_SELECTOR;
handle_color_changed();
}
else
playsound(screen, 1, SND_CLICK, 1, SNDPOS_CENTER, SNDDIST_NEAR);
SDL_Flip(screen);
}
else
{ {
/* Draw something! */ /* Draw something! */
old_x = event.button.x - r_canvas.x; old_x = event.button.x - r_canvas.x;
@ -4950,6 +4974,7 @@ static void mainloop(void)
button_down = 1; button_down = 1;
} }
}
else if (HIT(r_sfx) && valid_click(event.button.button)) else if (HIT(r_sfx) && valid_click(event.button.button))
{ {
/* A sound player button on the lower left has been pressed! */ /* A sound player button on the lower left has been pressed! */
@ -6797,8 +6822,6 @@ static void stamp_draw(int x, int y)
if (current_stamp_cached == NULL) if (current_stamp_cached == NULL)
{ {
printf("Generating stamp image\n");
Uint32(*getpixel) (SDL_Surface *, int, int); Uint32(*getpixel) (SDL_Surface *, int, int);
void (*putpixel) (SDL_Surface *, int, int, Uint32); void (*putpixel) (SDL_Surface *, int, int, Uint32);
@ -6891,13 +6914,10 @@ static void stamp_draw(int x, int y)
tmp_surf = surf_ptr; tmp_surf = surf_ptr;
} }
printf("Caching stamp\n");
current_stamp_cached = SDL_DisplayFormatAlpha(tmp_surf); current_stamp_cached = SDL_DisplayFormatAlpha(tmp_surf);
} }
else else
{ {
printf("Using cached stamp!\n");
tmp_surf = current_stamp_cached; tmp_surf = current_stamp_cached;
dont_free_tmp_surf = 1; dont_free_tmp_surf = 1;
dont_free_scaled_surf = 1; dont_free_scaled_surf = 1;
@ -7619,14 +7639,9 @@ static void clear_cached_stamp(void)
{ {
if (current_stamp_cached != NULL) if (current_stamp_cached != NULL)
{ {
printf("Clearing cached stamp\n");
SDL_FreeSurface(current_stamp_cached); SDL_FreeSurface(current_stamp_cached);
current_stamp_cached = NULL; current_stamp_cached = NULL;
} }
else
{
printf("No cached stamp to clear\n");
}
} }
/** /**
@ -21182,7 +21197,7 @@ static int do_new_dialog(void)
/* Launch color picker if they chose that: */ /* Launch color picker if they chose that: */
if (which == NUM_COLORS - 1) if (which == COLOR_PICKER)
{ {
if (do_color_picker() == 0) if (do_color_picker() == 0)
return (0); return (0);
@ -21270,7 +21285,7 @@ static int do_new_dialog_add_colors(SDL_Surface * *thumbs, int num_files, int *d
{ {
added = 0; added = 0;
if (j < NUM_COLORS - 1) if (j < COLOR_PICKER)
{ {
if (j == -1 || /* (short circuit) */ if (j == -1 || /* (short circuit) */
color_hexes[j][0] != 255 || /* Ignore white, we'll have already added it */ color_hexes[j][0] != 255 || /* Ignore white, we'll have already added it */
@ -21534,8 +21549,9 @@ static int do_color_sel(int temp_mode)
SDL_FillRect(screen, &color_example_dest, SDL_FillRect(screen, &color_example_dest,
SDL_MapRGB(screen->format, SDL_MapRGB(screen->format,
color_hexes[NUM_COLORS - 2][0], color_hexes[COLOR_SELECTOR][0],
color_hexes[NUM_COLORS - 2][1], color_hexes[NUM_COLORS - 2][2])); color_hexes[COLOR_SELECTOR][1],
color_hexes[COLOR_SELECTOR][2]));
/* Show "Back" button */ /* Show "Back" button */
back_left = r_color_sel.x + r_color_sel.w - button_w - 4; back_left = r_color_sel.x + r_color_sel.w - button_w - 4;
@ -21559,6 +21575,9 @@ static int do_color_sel(int temp_mode)
SDL_GetMouseState(&mx, &my); SDL_GetMouseState(&mx, &my);
SDL_WarpMouse(mx - 1, my); /* Need to move to a different spot, or no events occur */ SDL_WarpMouse(mx - 1, my); /* Need to move to a different spot, or no events occur */
SDL_WarpMouse(mx, my); SDL_WarpMouse(mx, my);
/* These will be unused in this mode: */
back_left = back_top = 0;
} }
@ -21683,8 +21702,9 @@ static int do_color_sel(int temp_mode)
SDL_FillRect(screen, &color_example_dest, SDL_FillRect(screen, &color_example_dest,
SDL_MapRGB(screen->format, SDL_MapRGB(screen->format,
color_hexes[NUM_COLORS - 2][0], color_hexes[COLOR_SELECTOR][0],
color_hexes[NUM_COLORS - 2][1], color_hexes[NUM_COLORS - 2][2])); color_hexes[COLOR_SELECTOR][1],
color_hexes[COLOR_SELECTOR][2]));
SDL_UpdateRect(screen, SDL_UpdateRect(screen,
color_example_dest.x, color_example_dest.x,
@ -21733,9 +21753,9 @@ static int do_color_sel(int temp_mode)
getpixel_img_color_picker = getpixels[canvas->format->BytesPerPixel]; getpixel_img_color_picker = getpixels[canvas->format->BytesPerPixel];
SDL_GetRGB(getpixel_img_color_picker(canvas, color_sel_x, color_sel_y), canvas->format, &r, &g, &b); SDL_GetRGB(getpixel_img_color_picker(canvas, color_sel_x, color_sel_y), canvas->format, &r, &g, &b);
color_hexes[NUM_COLORS - 2][0] = r; color_hexes[COLOR_SELECTOR][0] = r;
color_hexes[NUM_COLORS - 2][1] = g; color_hexes[COLOR_SELECTOR][1] = g;
color_hexes[NUM_COLORS - 2][2] = b; color_hexes[COLOR_SELECTOR][2] = b;
/* Re-render color picker to show the current color it contains: */ /* Re-render color picker to show the current color it contains: */
@ -21748,14 +21768,14 @@ static int do_color_sel(int temp_mode)
getpixel_tmp_btn_down = getpixels[tmp_btn_down->format->BytesPerPixel]; getpixel_tmp_btn_down = getpixels[tmp_btn_down->format->BytesPerPixel];
getpixel_img_paintwell = getpixels[img_paintwell->format->BytesPerPixel]; getpixel_img_paintwell = getpixels[img_paintwell->format->BytesPerPixel];
rh = sRGB_to_linear_table[color_hexes[NUM_COLORS - 2][0]]; rh = sRGB_to_linear_table[color_hexes[COLOR_SELECTOR][0]];
gh = sRGB_to_linear_table[color_hexes[NUM_COLORS - 2][1]]; gh = sRGB_to_linear_table[color_hexes[COLOR_SELECTOR][1]];
bh = sRGB_to_linear_table[color_hexes[NUM_COLORS - 2][2]]; bh = sRGB_to_linear_table[color_hexes[COLOR_SELECTOR][2]];
SDL_LockSurface(img_color_btns[NUM_COLORS - 2]); SDL_LockSurface(img_color_btns[COLOR_SELECTOR]);
SDL_LockSurface(img_color_btns[NUM_COLORS - 2 + NUM_COLORS]); SDL_LockSurface(img_color_btns[COLOR_SELECTOR + NUM_COLORS]);
for (y = 0; y < tmp_btn_up->h /* 48 */ ; y++) for (y = 0; y < tmp_btn_up->h /* 48 */ ; y++)
{ {
@ -21780,14 +21800,14 @@ static int do_color_sel(int temp_mode)
if (a == 255) if (a == 255)
{ {
putpixels[img_color_btns[NUM_COLORS - 2]->format->BytesPerPixel] putpixels[img_color_btns[COLOR_SELECTOR]->format->BytesPerPixel]
(img_color_btns[NUM_COLORS - 2], x, y, (img_color_btns[COLOR_SELECTOR], x, y,
SDL_MapRGB(img_color_btns[i]->format, SDL_MapRGB(img_color_btns[i]->format,
linear_to_sRGB(rh * aa + ru * (1.0 - aa)), linear_to_sRGB(rh * aa + ru * (1.0 - aa)),
linear_to_sRGB(gh * aa + gu * (1.0 - aa)), linear_to_sRGB(bh * aa + bu * (1.0 - aa)))); linear_to_sRGB(gh * aa + gu * (1.0 - aa)), linear_to_sRGB(bh * aa + bu * (1.0 - aa))));
putpixels[img_color_btns[NUM_COLORS - 2 + NUM_COLORS]->format->BytesPerPixel] putpixels[img_color_btns[COLOR_SELECTOR + NUM_COLORS]->format->BytesPerPixel]
(img_color_btns[NUM_COLORS - 2 + NUM_COLORS], x, y, (img_color_btns[COLOR_SELECTOR + NUM_COLORS], x, y,
SDL_MapRGB(img_color_btns[i + NUM_COLORS]->format, SDL_MapRGB(img_color_btns[i + NUM_COLORS]->format,
linear_to_sRGB(rh * aa + rd * (1.0 - aa)), linear_to_sRGB(rh * aa + rd * (1.0 - aa)),
linear_to_sRGB(gh * aa + gd * (1.0 - aa)), linear_to_sRGB(bh * aa + bd * (1.0 - aa)))); linear_to_sRGB(gh * aa + gd * (1.0 - aa)), linear_to_sRGB(bh * aa + bd * (1.0 - aa))));
@ -21795,18 +21815,18 @@ static int do_color_sel(int temp_mode)
} }
} }
SDL_UnlockSurface(img_color_btns[NUM_COLORS - 2]); SDL_UnlockSurface(img_color_btns[COLOR_SELECTOR]);
SDL_UnlockSurface(img_color_btns[NUM_COLORS - 2 + NUM_COLORS]); SDL_UnlockSurface(img_color_btns[COLOR_SELECTOR + NUM_COLORS]);
dest.x = (img_color_btns[NUM_COLORS - 2]->w - img_color_sel->w) / 2; dest.x = (img_color_btns[COLOR_SELECTOR]->w - img_color_sel->w) / 2;
dest.y = (img_color_btns[NUM_COLORS - 2]->h - img_color_sel->h) / 2; dest.y = (img_color_btns[COLOR_SELECTOR]->h - img_color_sel->h) / 2;
dest.w = img_color_sel->w; dest.w = img_color_sel->w;
dest.h = img_color_sel->h; dest.h = img_color_sel->h;
SDL_BlitSurface(img_color_sel, NULL, img_color_btns[NUM_COLORS - 2], &dest); SDL_BlitSurface(img_color_sel, NULL, img_color_btns[COLOR_SELECTOR], &dest);
dest.x = (img_color_btns[NUM_COLORS - 2 + NUM_COLORS]->w - img_color_sel->w) / 2; dest.x = (img_color_btns[COLOR_SELECTOR + NUM_COLORS]->w - img_color_sel->w) / 2;
dest.y = (img_color_btns[NUM_COLORS - 2 + NUM_COLORS]->h - img_color_sel->h) / 2; dest.y = (img_color_btns[COLOR_SELECTOR + NUM_COLORS]->h - img_color_sel->h) / 2;
SDL_BlitSurface(img_color_sel, NULL, img_color_btns[NUM_COLORS - 2 + NUM_COLORS], &dest); SDL_BlitSurface(img_color_sel, NULL, img_color_btns[COLOR_SELECTOR + NUM_COLORS], &dest);
} }
return (chose); return (chose);
@ -22004,8 +22024,9 @@ static int do_color_picker(void)
SDL_FillRect(screen, &color_example_dest, SDL_FillRect(screen, &color_example_dest,
SDL_MapRGB(screen->format, SDL_MapRGB(screen->format,
color_hexes[NUM_COLORS - 1][0], color_hexes[COLOR_PICKER][0],
color_hexes[NUM_COLORS - 1][1], color_hexes[NUM_COLORS - 1][2])); color_hexes[COLOR_PICKER][1],
color_hexes[COLOR_PICKER][2]));
@ -22125,8 +22146,9 @@ static int do_color_picker(void)
SDL_FillRect(screen, &color_example_dest, SDL_FillRect(screen, &color_example_dest,
SDL_MapRGB(screen->format, SDL_MapRGB(screen->format,
color_hexes[NUM_COLORS - 1][0], color_hexes[COLOR_PICKER][0],
color_hexes[NUM_COLORS - 1][1], color_hexes[NUM_COLORS - 1][2])); color_hexes[COLOR_PICKER][1],
color_hexes[COLOR_PICKER][2]));
SDL_UpdateRect(screen, SDL_UpdateRect(screen,
color_example_dest.x, color_example_dest.x,
@ -22174,9 +22196,9 @@ static int do_color_picker(void)
getpixel_img_color_picker = getpixels[img_color_picker->format->BytesPerPixel]; getpixel_img_color_picker = getpixels[img_color_picker->format->BytesPerPixel];
SDL_GetRGB(getpixel_img_color_picker(img_color_picker, x, y), img_color_picker->format, &r, &g, &b); SDL_GetRGB(getpixel_img_color_picker(img_color_picker, x, y), img_color_picker->format, &r, &g, &b);
color_hexes[NUM_COLORS - 1][0] = r; color_hexes[COLOR_PICKER][0] = r;
color_hexes[NUM_COLORS - 1][1] = g; color_hexes[COLOR_PICKER][1] = g;
color_hexes[NUM_COLORS - 1][2] = b; color_hexes[COLOR_PICKER][2] = b;
/* Re-render color picker to show the current color it contains: */ /* Re-render color picker to show the current color it contains: */
@ -22189,12 +22211,12 @@ static int do_color_picker(void)
getpixel_tmp_btn_down = getpixels[tmp_btn_down->format->BytesPerPixel]; getpixel_tmp_btn_down = getpixels[tmp_btn_down->format->BytesPerPixel];
getpixel_img_paintwell = getpixels[img_paintwell->format->BytesPerPixel]; getpixel_img_paintwell = getpixels[img_paintwell->format->BytesPerPixel];
rh = sRGB_to_linear_table[color_hexes[NUM_COLORS - 1][0]]; rh = sRGB_to_linear_table[color_hexes[COLOR_PICKER][0]];
gh = sRGB_to_linear_table[color_hexes[NUM_COLORS - 1][1]]; gh = sRGB_to_linear_table[color_hexes[COLOR_PICKER][1]];
bh = sRGB_to_linear_table[color_hexes[NUM_COLORS - 1][2]]; bh = sRGB_to_linear_table[color_hexes[COLOR_PICKER][2]];
SDL_LockSurface(img_color_btns[NUM_COLORS - 1]); SDL_LockSurface(img_color_btns[COLOR_PICKER]);
SDL_LockSurface(img_color_btns[NUM_COLORS - 1 + NUM_COLORS]); SDL_LockSurface(img_color_btns[COLOR_PICKER + NUM_COLORS]);
for (y = 0; y < tmp_btn_up->h /* 48 */ ; y++) for (y = 0; y < tmp_btn_up->h /* 48 */ ; y++)
{ {
@ -22217,23 +22239,23 @@ static int do_color_picker(void)
aa = a / 255.0; aa = a / 255.0;
putpixels[img_color_btns[NUM_COLORS - 1]->format->BytesPerPixel] putpixels[img_color_btns[COLOR_PICKER]->format->BytesPerPixel]
(img_color_btns[NUM_COLORS - 1], x, y, (img_color_btns[COLOR_PICKER], x, y,
getpixels[img_color_picker_thumb->format->BytesPerPixel] (img_color_picker_thumb, x, y)); getpixels[img_color_picker_thumb->format->BytesPerPixel] (img_color_picker_thumb, x, y));
putpixels[img_color_btns[NUM_COLORS - 1 + NUM_COLORS]->format->BytesPerPixel] putpixels[img_color_btns[COLOR_PICKER + NUM_COLORS]->format->BytesPerPixel]
(img_color_btns[NUM_COLORS - 1 + NUM_COLORS], x, y, (img_color_btns[COLOR_PICKER + NUM_COLORS], x, y,
getpixels[img_color_picker_thumb->format->BytesPerPixel] (img_color_picker_thumb, x, y)); getpixels[img_color_picker_thumb->format->BytesPerPixel] (img_color_picker_thumb, x, y));
if (a == 255) if (a == 255)
{ {
putpixels[img_color_btns[NUM_COLORS - 1]->format->BytesPerPixel] putpixels[img_color_btns[COLOR_PICKER]->format->BytesPerPixel]
(img_color_btns[NUM_COLORS - 1], x, y, (img_color_btns[COLOR_PICKER], x, y,
SDL_MapRGB(img_color_btns[i]->format, SDL_MapRGB(img_color_btns[i]->format,
linear_to_sRGB(rh * aa + ru * (1.0 - aa)), linear_to_sRGB(rh * aa + ru * (1.0 - aa)),
linear_to_sRGB(gh * aa + gu * (1.0 - aa)), linear_to_sRGB(bh * aa + bu * (1.0 - aa)))); linear_to_sRGB(gh * aa + gu * (1.0 - aa)), linear_to_sRGB(bh * aa + bu * (1.0 - aa))));
putpixels[img_color_btns[NUM_COLORS - 1 + NUM_COLORS]->format->BytesPerPixel] putpixels[img_color_btns[COLOR_PICKER + NUM_COLORS]->format->BytesPerPixel]
(img_color_btns[NUM_COLORS - 1 + NUM_COLORS], x, y, (img_color_btns[COLOR_PICKER + NUM_COLORS], x, y,
SDL_MapRGB(img_color_btns[i + NUM_COLORS]->format, SDL_MapRGB(img_color_btns[i + NUM_COLORS]->format,
linear_to_sRGB(rh * aa + rd * (1.0 - aa)), linear_to_sRGB(rh * aa + rd * (1.0 - aa)),
linear_to_sRGB(gh * aa + gd * (1.0 - aa)), linear_to_sRGB(bh * aa + bd * (1.0 - aa)))); linear_to_sRGB(gh * aa + gd * (1.0 - aa)), linear_to_sRGB(bh * aa + bd * (1.0 - aa))));
@ -22241,8 +22263,8 @@ static int do_color_picker(void)
} }
} }
SDL_UnlockSurface(img_color_btns[NUM_COLORS - 1]); SDL_UnlockSurface(img_color_btns[COLOR_PICKER]);
SDL_UnlockSurface(img_color_btns[NUM_COLORS - 1 + NUM_COLORS]); SDL_UnlockSurface(img_color_btns[COLOR_PICKER + NUM_COLORS]);
} }
@ -22254,6 +22276,27 @@ static int do_color_picker(void)
return (chose); return (chose);
} }
/**
* Things to do whenever a color is changed
* (either by selecting a color, using the color selector in full-UI mode,
* using the color picker (palette), or using the shortcut key to
* use color selector in temp-mode.
*/
static void handle_color_changed(void) {
render_brush();
if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL)
do_render_cur_text(0);
else if (cur_tool == TOOL_MAGIC)
magic_funcs[magics[magic_group][cur_magic[magic_group]].handle_idx].set_color(
magic_api_struct,
color_hexes[cur_color][0],
color_hexes[cur_color][1],
color_hexes[cur_color][2]);
else if (cur_tool == TOOL_STAMP)
clear_cached_stamp();
}
/** /**
* FIXME * FIXME
@ -22490,22 +22533,22 @@ static struct label_node *search_label_list(struct label_node **ref_head, Uint16
{ {
if ((color_hexes[k][0] == tmp_node->save_color.r) && if ((color_hexes[k][0] == tmp_node->save_color.r) &&
(color_hexes[k][1] == tmp_node->save_color.g) && (color_hexes[k][1] == tmp_node->save_color.g) &&
(color_hexes[k][2] == tmp_node->save_color.b) && (k < NUM_COLORS - 1)) (color_hexes[k][2] == tmp_node->save_color.b) && (k < COLOR_PICKER))
{ {
select_color = k; select_color = k;
cur_color = k; cur_color = k;
break; break;
} }
if (k == NUM_COLORS - 1) if (k == COLOR_PICKER)
{ {
cur_color = NUM_COLORS - 1; cur_color = COLOR_PICKER;
select_color = NUM_COLORS - 1; select_color = COLOR_PICKER;
color_hexes[select_color][0] = tmp_node->save_color.r; color_hexes[select_color][0] = tmp_node->save_color.r;
color_hexes[select_color][1] = tmp_node->save_color.g; color_hexes[select_color][1] = tmp_node->save_color.g;
color_hexes[select_color][2] = tmp_node->save_color.b; color_hexes[select_color][2] = tmp_node->save_color.b;
SDL_LockSurface(img_color_btns[NUM_COLORS - 1]); SDL_LockSurface(img_color_btns[COLOR_PICKER]);
SDL_LockSurface(img_color_btns[NUM_COLORS - 1 + NUM_COLORS]); SDL_LockSurface(img_color_btns[COLOR_PICKER + NUM_COLORS]);
for (j = 0; j < 48 /* 48 */ ; j++) for (j = 0; j < 48 /* 48 */ ; j++)
{ {
@ -22515,19 +22558,19 @@ static struct label_node *search_label_list(struct label_node **ref_head, Uint16
img_paintwell->format, &r, &g, &b, &a); img_paintwell->format, &r, &g, &b, &a);
if (a == 255) if (a == 255)
{ {
putpixels[img_color_btns[NUM_COLORS - 1]->format->BytesPerPixel] putpixels[img_color_btns[COLOR_PICKER]->format->BytesPerPixel]
(img_color_btns[NUM_COLORS - 1], i, j, (img_color_btns[COLOR_PICKER], i, j,
SDL_MapRGB(img_color_btns[NUM_COLORS - 1]->format, SDL_MapRGB(img_color_btns[COLOR_PICKER]->format,
tmp_node->save_color.r, tmp_node->save_color.g, tmp_node->save_color.b)); tmp_node->save_color.r, tmp_node->save_color.g, tmp_node->save_color.b));
putpixels[img_color_btns[NUM_COLORS - 1 + NUM_COLORS]->format->BytesPerPixel] putpixels[img_color_btns[COLOR_PICKER + NUM_COLORS]->format->BytesPerPixel]
(img_color_btns[NUM_COLORS - 1 + NUM_COLORS], i, j, (img_color_btns[COLOR_PICKER + NUM_COLORS], i, j,
SDL_MapRGB(img_color_btns[NUM_COLORS - 1 + NUM_COLORS]->format, SDL_MapRGB(img_color_btns[COLOR_PICKER + NUM_COLORS]->format,
tmp_node->save_color.r, tmp_node->save_color.g, tmp_node->save_color.b)); tmp_node->save_color.r, tmp_node->save_color.g, tmp_node->save_color.b));
} }
} }
} }
SDL_UnlockSurface(img_color_btns[NUM_COLORS - 1]); SDL_UnlockSurface(img_color_btns[COLOR_PICKER]);
SDL_UnlockSurface(img_color_btns[NUM_COLORS - 1 + NUM_COLORS]); SDL_UnlockSurface(img_color_btns[COLOR_PICKER + NUM_COLORS]);
draw_colors(COLORSEL_CLOBBER); draw_colors(COLORSEL_CLOBBER);
render_brush(); /* FIXME: render_brush should be called at the start of Brush and Line tools? */ render_brush(); /* FIXME: render_brush should be called at the start of Brush and Line tools? */
@ -25936,7 +25979,7 @@ static void setup(void)
double gh = sRGB_to_linear_table[color_hexes[i][1]]; double gh = sRGB_to_linear_table[color_hexes[i][1]];
double bh = sRGB_to_linear_table[color_hexes[i][2]]; double bh = sRGB_to_linear_table[color_hexes[i][2]];
if (i == NUM_COLORS - 1) if (i == COLOR_PICKER)
{ {
putpixels[img_color_btns[i]->format->BytesPerPixel] putpixels[img_color_btns[i]->format->BytesPerPixel]
(img_color_btns[i], x, y, (img_color_btns[i], x, y,
@ -25946,7 +25989,7 @@ static void setup(void)
getpixels[img_color_picker_thumb->format->BytesPerPixel] (img_color_picker_thumb, x, y)); getpixels[img_color_picker_thumb->format->BytesPerPixel] (img_color_picker_thumb, x, y));
} }
if (i < NUM_COLORS - 1 || a == 255) if (i < COLOR_PICKER || a == 255)
{ {
putpixels[img_color_btns[i]->format->BytesPerPixel] putpixels[img_color_btns[i]->format->BytesPerPixel]
(img_color_btns[i], x, y, (img_color_btns[i], x, y,
@ -25966,7 +26009,7 @@ static void setup(void)
for (i = 0; i < NUM_COLORS * 2; i++) for (i = 0; i < NUM_COLORS * 2; i++)
{ {
SDL_UnlockSurface(img_color_btns[i]); SDL_UnlockSurface(img_color_btns[i]);
if (i == NUM_COLORS - 2 || i == 2 * NUM_COLORS - 2) if (i == COLOR_SELECTOR || i == 2 * COLOR_SELECTOR)
{ {
dest.x = (img_color_btns[i]->w - img_color_sel->w) / 2; dest.x = (img_color_btns[i]->w - img_color_sel->w) / 2;
dest.y = (img_color_btns[i]->h - img_color_sel->h) / 2; dest.y = (img_color_btns[i]->h - img_color_sel->h) / 2;