X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=2113b8247c74c12718af7f72103792f3f066ce7e;hb=a7c06161253796a30a0237a7f5a044f459c8cf35;hp=b3166c4d46f5d2a0297c90aaafeda27dfe41f564;hpb=24101bdeee0ac963cfd48b5220f6d9b0188a6f69;p=rocksndiamonds.git diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index b3166c4d..2113b824 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -1,7 +1,7 @@ /*********************************************************** * Artsoft Retro-Game Library * *----------------------------------------------------------* -* (c) 1994-2002 Artsoft Entertainment * +* (c) 1994-2006 Artsoft Entertainment * * 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 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; @@ -370,10 +381,16 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) 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); +#endif cursor_letter = gi->textarea.value[gi->textarea.cursor_position]; cursor_string[0] = (cursor_letter != '\0' ? cursor_letter : ' '); @@ -731,7 +748,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) 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) @@ -815,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) - 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); @@ -833,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); - 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'; @@ -1382,18 +1399,18 @@ boolean anyTextGadgetActive() 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) { - 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) @@ -1414,8 +1431,8 @@ void ClickOnGadget(struct GadgetInfo *gi, 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; @@ -1441,7 +1458,9 @@ boolean HandleGadgets(int mx, int my, int button) boolean gadget_dragging; boolean gadget_released; boolean gadget_released_inside; +#if 0 boolean gadget_released_inside_select_line; +#endif boolean gadget_released_inside_select_area; boolean gadget_released_off_borders; boolean changed_position = FALSE; @@ -1544,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)) { +#if 0 gadget_released_inside_select_line = insideSelectboxLine(last_gi, mx, my); +#endif gadget_released_inside_select_area = insideSelectboxArea(last_gi, mx, my); } else { +#if 0 gadget_released_inside_select_line = FALSE; +#endif gadget_released_inside_select_area = FALSE; } @@ -1682,8 +1705,6 @@ boolean HandleGadgets(int mx, int my, int button) 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" */ @@ -1783,10 +1804,10 @@ boolean HandleGadgets(int mx, int my, int button) } } -#endif - if (gadget_pressed) { + PlayGadgetSoundActivating(); + if (gi->type == GD_TYPE_CHECK_BUTTON) { gi->checked = !gi->checked; @@ -1965,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 1 gi->state = GD_BUTTON_UNPRESSED; -#endif gi->event.type = GD_EVENT_RELEASED; if (gi->event_mask & GD_EVENT_RELEASED && @@ -1985,10 +2004,10 @@ boolean HandleGadgets(int mx, int my, int button) 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; - 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); @@ -2049,7 +2068,7 @@ boolean HandleGadgetsKeyInput(Key key) } 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); @@ -2096,7 +2115,7 @@ boolean HandleGadgetsKeyInput(Key key) } 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;