projects
/
rocksndiamonds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rnd-20131216-1-src
[rocksndiamonds.git]
/
src
/
libgame
/
gadgets.c
diff --git
a/src/libgame/gadgets.c
b/src/libgame/gadgets.c
index e939f865a5ace5063ea78374a2b0b69c657c5758..2113b8247c74c12718af7f72103792f3f066ce7e 100644
(file)
--- a/
src/libgame/gadgets.c
+++ b/
src/libgame/gadgets.c
@@
-1,7
+1,7
@@
/***********************************************************
* Artsoft Retro-Game Library *
*----------------------------------------------------------*
/***********************************************************
* Artsoft Retro-Game Library *
*----------------------------------------------------------*
-* (c) 1994-200
2
Artsoft Entertainment *
+* (c) 1994-200
6
Artsoft Entertainment *
* Holger Schemel *
* Detmolder Strasse 189 *
* 33604 Bielefeld *
* Holger Schemel *
* Detmolder Strasse 189 *
* 33604 Bielefeld *
@@
-32,6
+32,17
@@
static struct GadgetInfo *last_info_gi = NULL;
static int next_free_gadget_id = 1;
static boolean gadget_id_wrapped = FALSE;
static int next_free_gadget_id = 1;
static boolean gadget_id_wrapped = FALSE;
+static void (*PlayGadgetSoundActivating)(void) = NULL;
+static void (*PlayGadgetSoundSelecting)(void) = NULL;
+
+
+void InitGadgetsSoundCallback(void (*activating_function)(void),
+ void (*selecting_function)(void))
+{
+ PlayGadgetSoundActivating = activating_function;
+ PlayGadgetSoundSelecting = selecting_function;
+}
+
static struct GadgetInfo *getGadgetInfoFromGadgetID(int id)
{
struct GadgetInfo *gi = gadget_list_first_entry;
static struct GadgetInfo *getGadgetInfoFromGadgetID(int id)
{
struct GadgetInfo *gi = gadget_list_first_entry;
@@
-71,13
+82,18
@@
static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my,
struct GadgetInfo *gi;
/* first check for scrollbars in case of mouse scroll wheel button events */
struct GadgetInfo *gi;
/* first check for scrollbars in case of mouse scroll wheel button events */
- if (
button == 4 || button == 5
)
+ if (
IS_WHEEL_BUTTON(button)
)
{
{
+ /* real horizontal wheel or vertical wheel with modifier key pressed */
+ boolean check_horizontal = (IS_WHEEL_BUTTON_HORIZONTAL(button) ||
+ GetKeyModState() & KMOD_Shift);
+
/* check for the first active scrollbar with matching mouse wheel area */
for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next)
{
if (gi->mapped && gi->active &&
/* check for the first active scrollbar with matching mouse wheel area */
for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next)
{
if (gi->mapped && gi->active &&
- gi->type & GD_TYPE_SCROLLBAR &&
+ ((gi->type & GD_TYPE_SCROLLBAR_HORIZONTAL && check_horizontal) ||
+ (gi->type & GD_TYPE_SCROLLBAR_VERTICAL && !check_horizontal)) &&
mx >= gi->wheelarea.x && mx < gi->wheelarea.x + gi->wheelarea.width &&
my >= gi->wheelarea.y && my < gi->wheelarea.y + gi->wheelarea.height)
return gi;
mx >= gi->wheelarea.x && mx < gi->wheelarea.x + gi->wheelarea.width &&
my >= gi->wheelarea.y && my < gi->wheelarea.y + gi->wheelarea.height)
return gi;
@@
-365,10
+381,16
@@
static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
gi->height - 2 * border_y);
/* gadget text value */
gi->height - 2 * border_y);
/* gadget text value */
+#if 1
+ DrawTextBuffer(gi->x + border_x, gi->y + border_y, gi->textarea.value,
+ font_nr, gi->textarea.xsize, -1, gi->textarea.ysize, 0,
+ BLIT_ON_BACKGROUND, FALSE, FALSE, FALSE);
+#else
DrawTextToTextArea(gi->x + border_x, gi->y + border_y,
gi->textarea.value, font_nr, gi->textarea.xsize,
gi->textarea.xsize, gi->textarea.ysize,
BLIT_ON_BACKGROUND);
DrawTextToTextArea(gi->x + border_x, gi->y + border_y,
gi->textarea.value, font_nr, gi->textarea.xsize,
gi->textarea.xsize, gi->textarea.ysize,
BLIT_ON_BACKGROUND);
+#endif
cursor_letter = gi->textarea.value[gi->textarea.cursor_position];
cursor_string[0] = (cursor_letter != '\0' ? cursor_letter : ' ');
cursor_letter = gi->textarea.value[gi->textarea.cursor_position];
cursor_string[0] = (cursor_letter != '\0' ? cursor_letter : ' ');
@@
-726,7
+748,7
@@
static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
case GDI_INFO_TEXT:
{
case GDI_INFO_TEXT:
{
- int max_textsize = MAX_INFO_TEXTSIZE
- 1
;
+ int max_textsize = MAX_INFO_TEXTSIZE;
char *text = va_arg(ap, char *);
if (text != NULL)
char *text = va_arg(ap, char *);
if (text != NULL)
@@
-763,20
+785,14
@@
static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
break;
case GDI_ACTIVE:
break;
case GDI_ACTIVE:
- /* take care here: "boolean" is typedef'ed as "unsigned char",
- which gets promoted to "int" */
gi->active = (boolean)va_arg(ap, int);
break;
case GDI_DIRECT_DRAW:
gi->active = (boolean)va_arg(ap, int);
break;
case GDI_DIRECT_DRAW:
- /* take care here: "boolean" is typedef'ed as "unsigned char",
- which gets promoted to "int" */
gi->direct_draw = (boolean)va_arg(ap, int);
break;
case GDI_CHECKED:
gi->direct_draw = (boolean)va_arg(ap, int);
break;
case GDI_CHECKED:
- /* take care here: "boolean" is typedef'ed as "unsigned char",
- which gets promoted to "int" */
gi->checked = (boolean)va_arg(ap, int);
break;
gi->checked = (boolean)va_arg(ap, int);
break;
@@
-816,7
+832,7
@@
static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
int max_textsize = MAX_GADGET_TEXTSIZE;
if (gi->textinput.size)
int max_textsize = MAX_GADGET_TEXTSIZE;
if (gi->textinput.size)
- max_textsize = MIN(gi->textinput.size, MAX_GADGET_TEXTSIZE
- 1
);
+ max_textsize = MIN(gi->textinput.size, MAX_GADGET_TEXTSIZE);
strncpy(gi->textinput.value, va_arg(ap, char *), max_textsize);
strcpy(gi->textinput.last_value, gi->textinput.value);
strncpy(gi->textinput.value, va_arg(ap, char *), max_textsize);
strcpy(gi->textinput.last_value, gi->textinput.value);
@@
-834,7
+850,7
@@
static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap)
case GDI_TEXT_SIZE:
{
int tag_value = va_arg(ap, int);
case GDI_TEXT_SIZE:
{
int tag_value = va_arg(ap, int);
- int max_textsize = MIN(tag_value, MAX_GADGET_TEXTSIZE
- 1
);
+ int max_textsize = MIN(tag_value, MAX_GADGET_TEXTSIZE);
gi->textinput.size = max_textsize;
gi->textinput.value[max_textsize] = '\0';
gi->textinput.size = max_textsize;
gi->textinput.value[max_textsize] = '\0';
@@
-1383,18
+1399,18
@@
boolean anyTextGadgetActive()
static boolean insideSelectboxLine(struct GadgetInfo *gi, int mx, int my)
{
static boolean insideSelectboxLine(struct GadgetInfo *gi, int mx, int my)
{
- return(gi != NULL &&
- gi->type & GD_TYPE_SELECTBOX &&
- mx >= gi->x && mx < gi->x + gi->width &&
- my >= gi->y && my < gi->y + gi->height);
+ return
(gi != NULL &&
+
gi->type & GD_TYPE_SELECTBOX &&
+
mx >= gi->x && mx < gi->x + gi->width &&
+
my >= gi->y && my < gi->y + gi->height);
}
static boolean insideSelectboxArea(struct GadgetInfo *gi, int mx, int my)
{
}
static boolean insideSelectboxArea(struct GadgetInfo *gi, int mx, int my)
{
- return(gi != NULL &&
- gi->type & GD_TYPE_SELECTBOX &&
- mx >= gi->selectbox.x && mx < gi->selectbox.x + gi->selectbox.width &&
- my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height);
+ return
(gi != NULL &&
+
gi->type & GD_TYPE_SELECTBOX &&
+
mx >= gi->selectbox.x && mx < gi->selectbox.x + gi->selectbox.width &&
+
my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height);
}
void ClickOnGadget(struct GadgetInfo *gi, int button)
}
void ClickOnGadget(struct GadgetInfo *gi, int button)
@@
-1415,8
+1431,8
@@
void ClickOnGadget(struct GadgetInfo *gi, int button)
boolean HandleGadgets(int mx, int my, int button)
{
boolean HandleGadgets(int mx, int my, int button)
{
- static unsigned
long
pressed_delay = 0;
- static unsigned
long
pressed_delay_value = GADGET_FRAME_DELAY;
+ static unsigned
int
pressed_delay = 0;
+ static unsigned
int
pressed_delay_value = GADGET_FRAME_DELAY;
static int last_button = 0;
static int last_mx = 0, last_my = 0;
static int pressed_mx = 0, pressed_my = 0;
static int last_button = 0;
static int last_mx = 0, last_my = 0;
static int pressed_mx = 0, pressed_my = 0;
@@
-1442,7
+1458,9
@@
boolean HandleGadgets(int mx, int my, int button)
boolean gadget_dragging;
boolean gadget_released;
boolean gadget_released_inside;
boolean gadget_dragging;
boolean gadget_released;
boolean gadget_released_inside;
+#if 0
boolean gadget_released_inside_select_line;
boolean gadget_released_inside_select_line;
+#endif
boolean gadget_released_inside_select_area;
boolean gadget_released_off_borders;
boolean changed_position = FALSE;
boolean gadget_released_inside_select_area;
boolean gadget_released_off_borders;
boolean changed_position = FALSE;
@@
-1496,7
+1514,7
@@
boolean HandleGadgets(int mx, int my, int button)
(gadget_pressed_inside_select_line && !mouse_inside_select_area)))
{
struct GadgetInfo *gi = last_gi;
(gadget_pressed_inside_select_line && !mouse_inside_select_area)))
{
struct GadgetInfo *gi = last_gi;
- boolean gadget_changed = (
gi->event_mask & GD_EVENT_TEXT_LEAVING
);
+ boolean gadget_changed = (
(gi->event_mask & GD_EVENT_TEXT_LEAVING) != 0
);
/* check if text gadget has changed its value */
if (gi->type & GD_TYPE_TEXT_INPUT)
/* check if text gadget has changed its value */
if (gi->type & GD_TYPE_TEXT_INPUT)
@@
-1545,12
+1563,16
@@
boolean HandleGadgets(int mx, int my, int button)
/* when handling selectbox, set additional state values */
if (gadget_released_inside && (last_gi->type & GD_TYPE_SELECTBOX))
{
/* when handling selectbox, set additional state values */
if (gadget_released_inside && (last_gi->type & GD_TYPE_SELECTBOX))
{
+#if 0
gadget_released_inside_select_line = insideSelectboxLine(last_gi, mx, my);
gadget_released_inside_select_line = insideSelectboxLine(last_gi, mx, my);
+#endif
gadget_released_inside_select_area = insideSelectboxArea(last_gi, mx, my);
}
else
{
gadget_released_inside_select_area = insideSelectboxArea(last_gi, mx, my);
}
else
{
+#if 0
gadget_released_inside_select_line = FALSE;
gadget_released_inside_select_line = FALSE;
+#endif
gadget_released_inside_select_area = FALSE;
}
gadget_released_inside_select_area = FALSE;
}
@@
-1683,8
+1705,6
@@
boolean HandleGadgets(int mx, int my, int button)
last_info_gi = new_gi;
}
last_info_gi = new_gi;
}
-#if 1
-
gadget_draggable = (gi && gi->type & GD_TYPE_SCROLLBAR);
/* reset drag position for newly pressed scrollbar to "not dragging" */
gadget_draggable = (gi && gi->type & GD_TYPE_SCROLLBAR);
/* reset drag position for newly pressed scrollbar to "not dragging" */
@@
-1722,10
+1742,11
@@
boolean HandleGadgets(int mx, int my, int button)
{
int mpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx : my);
int gpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? gi->x : gi->y);
{
int mpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx : my);
int gpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? gi->x : gi->y);
+ int slider_start = gpos + gi->scrollbar.position;
+ int slider_end = gpos + gi->scrollbar.position + gi->scrollbar.size - 1;
+ boolean inside_slider = (mpos >= slider_start && mpos <= slider_end);
- if (button > 3 ||
- mpos < gpos + gi->scrollbar.position ||
- mpos >= gpos + gi->scrollbar.position + gi->scrollbar.size)
+ if (IS_WHEEL_BUTTON(button) || !inside_slider)
{
/* click scrollbar one scrollbar length up/left or down/right */
{
/* click scrollbar one scrollbar length up/left or down/right */
@@
-1734,10
+1755,13
@@
boolean HandleGadgets(int mx, int my, int button)
int item_steps = gs->items_visible - 1;
int item_direction = (mpos < gpos + gi->scrollbar.position ? -1 : +1);
int item_steps = gs->items_visible - 1;
int item_direction = (mpos < gpos + gi->scrollbar.position ? -1 : +1);
- if (
button > 3
)
+ if (
IS_WHEEL_BUTTON(button)
)
{
{
- item_steps = 3;
- item_direction = (button == 4 ? -1 : +1);
+ boolean scroll_single_step = ((GetKeyModState() & KMOD_Alt) != 0);
+
+ item_steps = (scroll_single_step ? 1 : DEFAULT_WHEEL_STEPS);
+ item_direction = (button == MB_WHEEL_UP ||
+ button == MB_WHEEL_LEFT ? -1 : +1);
}
changed_position = FALSE;
}
changed_position = FALSE;
@@
-1780,10
+1804,10
@@
boolean HandleGadgets(int mx, int my, int button)
}
}
}
}
-#endif
-
if (gadget_pressed)
{
if (gadget_pressed)
{
+ PlayGadgetSoundActivating();
+
if (gi->type == GD_TYPE_CHECK_BUTTON)
{
gi->checked = !gi->checked;
if (gi->type == GD_TYPE_CHECK_BUTTON)
{
gi->checked = !gi->checked;
@@
-1812,10
+1836,11
@@
boolean HandleGadgets(int mx, int my, int button)
{
int mpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx : my);
int gpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? gi->x : gi->y);
{
int mpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? mx : my);
int gpos = (gi->type == GD_TYPE_SCROLLBAR_HORIZONTAL ? gi->x : gi->y);
+ int slider_start = gpos + gi->scrollbar.position;
+ int slider_end = gpos + gi->scrollbar.position + gi->scrollbar.size - 1;
+ boolean inside_slider = (mpos >= slider_start && mpos <= slider_end);
- if (button >= 1 && button <= 3 &&
- mpos >= gpos + gi->scrollbar.position &&
- mpos < gpos + gi->scrollbar.position + gi->scrollbar.size)
+ if (!IS_WHEEL_BUTTON(button) && inside_slider)
{
/* start dragging scrollbar */
gi->scrollbar.drag_position =
{
/* start dragging scrollbar */
gi->scrollbar.drag_position =
@@
-1961,9
+1986,7
@@
boolean HandleGadgets(int mx, int my, int button)
if (gi->type & GD_TYPE_SCROLLBAR)
DrawGadget(gi, DG_UNPRESSED, gi->direct_draw);
if (gi->type & GD_TYPE_SCROLLBAR)
DrawGadget(gi, DG_UNPRESSED, gi->direct_draw);
-#if 1
gi->state = GD_BUTTON_UNPRESSED;
gi->state = GD_BUTTON_UNPRESSED;
-#endif
gi->event.type = GD_EVENT_RELEASED;
if (gi->event_mask & GD_EVENT_RELEASED &&
gi->event.type = GD_EVENT_RELEASED;
if (gi->event_mask & GD_EVENT_RELEASED &&
@@
-1981,10
+2004,10
@@
boolean HandleGadgets(int mx, int my, int button)
static void insertCharIntoTextArea(struct GadgetInfo *gi, char c)
{
static void insertCharIntoTextArea(struct GadgetInfo *gi, char c)
{
- char text[MAX_GADGET_TEXTSIZE];
+ char text[MAX_GADGET_TEXTSIZE
+ 1
];
int cursor_position = gi->textarea.cursor_position;
int cursor_position = gi->textarea.cursor_position;
- if (strlen(gi->textarea.value)
=
= MAX_GADGET_TEXTSIZE) /* no space left */
+ if (strlen(gi->textarea.value)
>
= MAX_GADGET_TEXTSIZE) /* no space left */
return;
strcpy(text, gi->textarea.value);
return;
strcpy(text, gi->textarea.value);
@@
-2006,7
+2029,7
@@
boolean HandleGadgetsKeyInput(Key key)
if (key == KSYM_Return) /* valid for both text input and selectbox */
{
if (key == KSYM_Return) /* valid for both text input and selectbox */
{
- boolean gadget_changed = (
gi->event_mask & GD_EVENT_TEXT_RETURN
);
+ boolean gadget_changed = (
(gi->event_mask & GD_EVENT_TEXT_RETURN) != 0
);
if (gi->type & GD_TYPE_TEXT_INPUT)
{
if (gi->type & GD_TYPE_TEXT_INPUT)
{
@@
-2045,7
+2068,7
@@
boolean HandleGadgetsKeyInput(Key key)
}
else if (gi->type & GD_TYPE_TEXT_INPUT) /* only valid for text input */
{
}
else if (gi->type & GD_TYPE_TEXT_INPUT) /* only valid for text input */
{
- char text[MAX_GADGET_TEXTSIZE];
+ char text[MAX_GADGET_TEXTSIZE
+ 1
];
int text_length = strlen(gi->textinput.value);
int cursor_pos = gi->textinput.cursor_position;
char letter = getCharFromKey(key);
int text_length = strlen(gi->textinput.value);
int cursor_pos = gi->textinput.cursor_position;
char letter = getCharFromKey(key);
@@
-2092,7
+2115,7
@@
boolean HandleGadgetsKeyInput(Key key)
}
else if (gi->type & GD_TYPE_TEXT_AREA) /* only valid for text area */
{
}
else if (gi->type & GD_TYPE_TEXT_AREA) /* only valid for text area */
{
- char text[MAX_GADGET_TEXTSIZE];
+ char text[MAX_GADGET_TEXTSIZE
+ 1
];
int text_length = strlen(gi->textarea.value);
int area_ysize = gi->textarea.ysize;
int cursor_x_pref = gi->textarea.cursor_x_preferred;
int text_length = strlen(gi->textarea.value);
int area_ysize = gi->textarea.ysize;
int cursor_x_pref = gi->textarea.cursor_x_preferred;