make mouse-scroll code match mouse-click code

This commit is contained in:
Albert Cahalan 2005-01-03 21:30:44 +00:00
parent 28027be284
commit e31d83e01b

View file

@ -2864,7 +2864,9 @@ static void mainloop(void)
} }
else if (HIT(r_toolopt)) else if (HIT(r_toolopt))
{ {
/* Options on the right have been pressed! */ // Options on the right
// WARNING: this must be kept in sync with the mouse-move
// code (for cursor changes) and mouse-scroll code.
if (cur_tool == TOOL_BRUSH || cur_tool == TOOL_STAMP || if (cur_tool == TOOL_BRUSH || cur_tool == TOOL_STAMP ||
cur_tool == TOOL_SHAPES || cur_tool == TOOL_LINES || cur_tool == TOOL_SHAPES || cur_tool == TOOL_LINES ||
@ -3254,8 +3256,7 @@ static void mainloop(void)
else if (HIT(r_colors) && colors_are_selectable) else if (HIT(r_colors) && colors_are_selectable)
{ {
/* Color! */ /* Color! */
which = GRIDHIT_GD(r_colors,gd_colors);
which = (event.button.x-r_colors.x)/color_button_w + (event.button.y-r_colors.y)/color_button_h*gd_colors.cols;
if (which < NUM_COLORS) if (which < NUM_COLORS)
{ {
@ -3460,10 +3461,18 @@ static void mainloop(void)
event.button.button >= 4 && event.button.button >= 4 &&
event.button.button <= 5) event.button.button <= 5)
{ {
// Scroll wheel code.
// WARNING: this must be kept in sync with the mouse-move
// code (for cursor changes) and mouse-click code.
if (cur_tool == TOOL_BRUSH || cur_tool == TOOL_STAMP || if (cur_tool == TOOL_BRUSH || cur_tool == TOOL_STAMP ||
cur_tool == TOOL_SHAPES || cur_tool == TOOL_LINES || cur_tool == TOOL_SHAPES || cur_tool == TOOL_LINES ||
cur_tool == TOOL_MAGIC || cur_tool == TOOL_TEXT) cur_tool == TOOL_MAGIC || cur_tool == TOOL_TEXT ||
cur_tool == TOOL_ERASER)
{ {
grid_dims gd_controls = {0,0}; // might become 2-by-2
grid_dims gd_items = {2,2}; // generally becoming 2-by-whatever
/* Note set of things we're dealing with */ /* Note set of things we're dealing with */
/* (stamps, brushes, etc.) */ /* (stamps, brushes, etc.) */
@ -3476,11 +3485,15 @@ static void mainloop(void)
{ {
num_things = num_stamps; num_things = num_stamps;
thing_scroll = stamp_scroll; thing_scroll = stamp_scroll;
if(!disable_stamp_controls)
gd_controls = (grid_dims){2,2};
} }
else if (cur_tool == TOOL_TEXT) else if (cur_tool == TOOL_TEXT)
{ {
num_things = num_font_families; num_things = num_font_families;
thing_scroll = font_scroll; thing_scroll = font_scroll;
if(!disable_stamp_controls)
gd_controls = (grid_dims){2,2};
} }
else if (cur_tool == TOOL_SHAPES) else if (cur_tool == TOOL_SHAPES)
{ {
@ -3492,59 +3505,80 @@ static void mainloop(void)
num_things = NUM_MAGICS; num_things = NUM_MAGICS;
thing_scroll = magic_scroll; thing_scroll = magic_scroll;
} }
else if (cur_tool == TOOL_ERASER)
{
num_things = NUM_ERASERS;
thing_scroll = 0;
}
// number of whole or partial rows that will be needed
// (can make this per-tool if variable columns needed)
int num_rows_needed = (num_things+gd_items.cols-1)/gd_items.cols;
do_draw = 0; do_draw = 0;
SDL_Rect r_controls;
r_controls.w = r_toolopt.w;
r_controls.h = gd_controls.rows * button_h;
r_controls.x = r_toolopt.x;
r_controls.y = r_toolopt.y + r_toolopt.h - r_controls.h;
SDL_Rect r_notcontrols;
r_notcontrols.w = r_toolopt.w;
r_notcontrols.h = r_toolopt.h - r_controls.h;
r_notcontrols.x = r_toolopt.x;
r_notcontrols.y = r_toolopt.y;
/* Deal with scroll wheels: */ SDL_Rect r_items = r_notcontrols;
if(num_rows_needed * button_h > r_items.h)
max = 14;
if (cur_tool == TOOL_STAMP && !disable_stamp_controls)
max = 10;
if (cur_tool == TOOL_TEXT && !disable_stamp_controls)
max = 10;
if (num_things > max + TOOLOFFSET)
{ {
if (event.button.button == 4) // too many; we'll need scroll buttons
{ r_items.h -= button_h;
/* Wheelmouse - UP "button" */ r_items.y += button_h/2;
if (thing_scroll > 0)
{
thing_scroll = thing_scroll - 2;
do_draw = 1;
playsound(1, SND_SCROLL, 1);
if (thing_scroll == 0)
do_setcursor(cursor_arrow);
} }
} gd_items.rows = r_items.h / button_h;
else if (event.button.button == 5)
if(0)
{ {
/* Wheelmouse - DOWN "button" */
if (thing_scroll < num_things - (max - 2))
{
thing_scroll = thing_scroll + 2;
do_draw = 1;
playsound(1, SND_SCROLL, 1);
if (thing_scroll == 0)
do_setcursor(cursor_arrow);
}
}
off_y = 24;
} }
else else
{ {
off_y = 0; // scroll button
int is_upper = (event.button.button == 4);
if (
(is_upper && thing_scroll > 0) // upper arrow
||
(!is_upper && thing_scroll/gd_items.cols < num_rows_needed-gd_items.rows) // lower arrow
)
{
thing_scroll += is_upper ? -gd_items.cols : gd_items.cols;
do_draw = 1;
playsound(1, SND_SCROLL, 1);
#if 0
if (!scrolling)
{
memcpy(&scrolltimer_event, &event, sizeof(SDL_Event));
/* FIXME: Make delay value changable: */
scrolltimer = SDL_AddTimer(REPEAT_SPEED, scrolltimer_callback, (void*) &scrolltimer_event);
scrolling = 1;
}
else
{
SDL_RemoveTimer(scrolltimer);
scrolltimer = SDL_AddTimer(REPEAT_SPEED / 3, scrolltimer_callback, (void*) &scrolltimer_event);
}
#endif
if (thing_scroll == 0)
{
do_setcursor(cursor_arrow);
#if 0
if (scrolling)
{
SDL_RemoveTimer(scrolltimer);
scrolling = 0;
}
#endif
}
} }
} }
@ -3553,105 +3587,47 @@ static void mainloop(void)
if (cur_tool == TOOL_BRUSH || cur_tool == TOOL_LINES) if (cur_tool == TOOL_BRUSH || cur_tool == TOOL_LINES)
{ {
cur_brush = cur_thing;
brush_scroll = thing_scroll; brush_scroll = thing_scroll;
render_brush();
if (do_draw) if (do_draw)
draw_brushes(); draw_brushes();
} }
else if (cur_tool == TOOL_ERASER) else if (cur_tool == TOOL_ERASER)
{ {
cur_eraser = cur_thing;
if (do_draw) if (do_draw)
draw_erasers(); draw_erasers();
} }
else if (cur_tool == TOOL_TEXT) else if (cur_tool == TOOL_TEXT)
{ {
cur_font = cur_thing;
font_scroll = thing_scroll; font_scroll = thing_scroll;
if (do_draw) if (do_draw)
draw_fonts(); draw_fonts();
do_render_cur_text(0);
} }
else if (cur_tool == TOOL_STAMP) else if (cur_tool == TOOL_STAMP)
{ {
#ifndef NOSOUND
if (cur_stamp != cur_thing)
{
/* Only play when picking a different stamp, not
simply scrolling */
if (snd_stamps[cur_thing] != NULL)
Mix_PlayChannel(2, snd_stamps[cur_thing], 0);
}
#endif
cur_stamp = cur_thing;
stamp_scroll = thing_scroll; stamp_scroll = thing_scroll;
update_stamp_xor();
if (do_draw) if (do_draw)
draw_stamps(); draw_stamps();
if (txt_stamps[cur_stamp] != NULL)
{
draw_tux_text(TUX_GREAT, txt_stamps[cur_stamp], 1);
}
else
draw_tux_text(TUX_GREAT, "", 0);
/* Enable or disable color selector: */
if ((stamp_colorable(cur_stamp) ||
stamp_tintable(cur_stamp)) !=
(stamp_colorable(old_thing) ||
stamp_tintable(old_thing)))
{
draw_colors(stamp_colorable(cur_stamp) ||
stamp_tintable(cur_stamp));
update_screen_rect(&r_colors);
update_screen_rect(&r_tcolors);
}
} }
else if (cur_tool == TOOL_SHAPES) else if (cur_tool == TOOL_SHAPES)
{ {
cur_shape = cur_thing;
draw_tux_text(TUX_GREAT, shape_tips[cur_shape], 1);
if (do_draw) if (do_draw)
draw_shapes(); draw_shapes();
} }
else if (cur_tool == TOOL_MAGIC) else if (cur_tool == TOOL_MAGIC)
{ {
if (cur_thing != cur_magic)
{
draw_colors(magic_colors[cur_magic]);
update_screen_rect(&r_tcolors);
}
cur_magic = cur_thing;
magic_scroll = thing_scroll; magic_scroll = thing_scroll;
draw_tux_text(TUX_GREAT, magic_tips[cur_magic], 1);
if (do_draw) if (do_draw)
draw_magic(); draw_magic();
} }
/* Update the screen: */ /* Update the screen: */
if (do_draw) if (do_draw)
{
update_screen_rect(&r_toolopt); update_screen_rect(&r_toolopt);
update_screen_rect(&r_ttoolopt); // need this?
} }
} }
else if (event.type == SDL_USEREVENT) else if (event.type == SDL_USEREVENT)
@ -3794,7 +3770,9 @@ static void mainloop(void)
} }
else if (HIT(r_toolopt)) else if (HIT(r_toolopt))
{ {
/* Selector: */ // mouse cursor code
// WARNING: this must be kept in sync with the mouse-click
// and mouse-click code. (it isn't, currently!)
/* Note set of things we're dealing with */ /* Note set of things we're dealing with */
/* (stamps, brushes, etc.) */ /* (stamps, brushes, etc.) */