Preparing a space for Magic size control

Magic Controls (paint vs fullscreen) and Sizes (coming soon)
can be enabled/disabled independently, and the list of Magic tools
sizes itself accordingly.
This commit is contained in:
Bill Kendrick 2023-04-12 22:31:05 -07:00
parent b4962b32f3
commit 263b382338
2 changed files with 106 additions and 35 deletions

View file

@ -25,7 +25,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
Last updated: February 12, 2023
Last updated: April 12, 2023
*/
#include <stdio.h>
@ -39,7 +39,7 @@
// Prototypes
Uint32 blur_api_version(void);
int blur_init(magic_api * api);
int blur_init(magic_api * api, Uint32 disabled_features);
int blur_get_tool_count(magic_api * api);
SDL_Surface *blur_get_icon(magic_api * api, int which);
char *blur_get_name(magic_api * api, int which);
@ -55,7 +55,11 @@ void blur_release(magic_api * api, int which, SDL_Surface * canvas,
void blur_shutdown(magic_api * api);
void blur_set_color(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
void blur_set_size(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 sz, SDL_Rect * update_rect);
int blur_requires_colors(magic_api * api, int which);
Uint8 blur_accepted_sizes(magic_api * api, int which);
Uint8 blur_default_size(magic_api * api, int which);
void blur_switchin(magic_api * api, int which, int mode,
SDL_Surface * canvas);
void blur_switchout(magic_api * api, int which, int mode,
@ -99,9 +103,8 @@ Uint32 blur_api_version(void)
}
//Load sounds
int blur_init(magic_api * api)
int blur_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
{
int i;
char fname[1024];
@ -315,6 +318,12 @@ void blur_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED
{
}
// Record the size from Tux Paint:
void blur_set_size(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, Uint8 sz, SDL_Rect * update_rect) {
/* FIXME */
}
// Use colors:
int blur_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED)
@ -322,6 +331,17 @@ int blur_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
return 0;
}
Uint8 blur_accepted_sizes(magic_api * api, int which) {
/* FIXME */
return 1;
}
Uint8 blur_default_size(magic_api * api, int which) {
/* FIXME */
return 1;
}
void blur_switchin(magic_api * api ATTRIBUTE_UNUSED,
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)

View file

@ -22,7 +22,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
June 14, 2002 - April 11, 2023
June 14, 2002 - April 12, 2023
*/
#include "platform.h"
@ -595,6 +595,8 @@ static void apply_label_node(int old_x, int old_y);
static void reposition_onscreen_keyboard(int y);
int calc_magic_control_rows(void);
static void reset_stamps(int *stamp_xored_rt, int *stamp_place_x,
int *stamp_place_y, int *stamp_tool_mode);
@ -4226,23 +4228,11 @@ static void mainloop(void)
gd_controls.cols = 2;
}
}
else if (cur_tool == TOOL_MAGIC)
{
if (!disable_magic_controls)
{
/* Account for magic controls and group changing (left/right) buttons */
gd_controls.rows = 2;
gd_controls.cols = 2;
}
else
{
/* Magic controls are disabled; account for group changing (left/right) buttons */
gd_controls.rows = 1;
gd_controls.cols = 2;
}
gd_controls.cols = 2;
gd_controls.rows = calc_magic_control_rows();
}
else if (cur_tool == TOOL_SHAPES)
{
if (!disable_shape_controls)
@ -6024,16 +6014,8 @@ static void mainloop(void)
}
else if (cur_tool == TOOL_MAGIC)
{
if (!disable_magic_controls)
{
gd_controls.rows = 2;
gd_controls.cols = 2;
}
else
{
gd_controls.rows = 1;
gd_controls.cols = 2;
}
gd_controls.cols = 2;
gd_controls.rows = calc_magic_control_rows();
}
else if (cur_tool == TOOL_SHAPES)
{
@ -6669,11 +6651,7 @@ static void mainloop(void)
if (cur_tool == TOOL_TEXT && !disable_stamp_controls)
control_rows = 2;
if (cur_tool == TOOL_MAGIC)
{
control_rows = 1;
if (!disable_magic_controls)
control_rows = 2;
}
control_rows = calc_magic_control_rows();
if (cur_tool == TOOL_SHAPES && !disable_shape_controls)
control_rows = 1;
if ((cur_tool == TOOL_BRUSH || cur_tool == TOOL_LINES)
@ -10342,9 +10320,11 @@ static void draw_magic(void)
/* How many can we show? */
most = (buttons_tall * gd_toolopt.cols) - gd_toolopt.cols - TOOLOFFSET - 2;
most = (buttons_tall * gd_toolopt.cols) - (gd_toolopt.cols * 2) - TOOLOFFSET - 2;
if (disable_magic_controls)
most = most + gd_toolopt.cols;
if (disable_magic_sizes)
most = most + gd_toolopt.cols;
if (num_magics[magic_group] > most + TOOLOFFSET)
{
@ -10543,6 +10523,51 @@ static void draw_magic(void)
h) / 2);
SDL_BlitSurface(img_magic_fullscreen, NULL, screen, &dest);
}
/* Draw magic size controls: */
if (!disable_magic_sizes)
{
SDL_Surface *button_color;
int grp, cur;
int down;
down = 4;
if (disable_magic_controls)
down = 2;
grp = magic_group;
cur = cur_magic[magic_group];
/* FIXME */
button_color = img_btn_off; /* Unavailable */
dest.x = WINDOW_WIDTH - r_ttoolopt.w;
dest.y =
r_ttoolopt.h +
((most / gd_toolopt.cols +
(TOOLOFFSET + down) / gd_toolopt.cols) * button_h);
SDL_BlitSurface(button_color, NULL, screen, &dest);
/* FIXME */
button_color = img_btn_off; /* Unavailable */
dest.x = WINDOW_WIDTH - button_w;
dest.y =
r_ttoolopt.h +
((most / gd_toolopt.cols +
(TOOLOFFSET + down) / gd_toolopt.cols) * button_h);
SDL_BlitSurface(button_color, NULL, screen, &dest);
}
}
@ -33388,3 +33413,29 @@ static void reposition_onscreen_keyboard(int y)
update_screen_rect(&kbd_rect);
}
}
/**
* How many rows of controls (not actual Magic tool items)
* are to be displayed at the bottom of the selector?
* (Based on whether magic controls and/or magic sizes are
* disabled)
*
* @return int
*/
int calc_magic_control_rows(void) {
int r;
/* Start with group changing (left/right) buttons */
r = 1;
/* Add magic controls (paint vs fullscreen) */
if (!disable_magic_controls)
r++;
/* Add magic size controls */
if (!disable_magic_sizes)
r++;
return r;
}