X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fgadgets.c;h=e150a089809ae1f633b3d377a69219b42dd742fa;hb=HEAD;hp=0f221a731e77e9695e633828796deb961531936e;hpb=969b64ecce695a468b80108184194be0a2c1ae6d;p=rocksndiamonds.git diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 0f221a73..b917b43d 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -156,6 +156,16 @@ static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my, return gi; } + // full text areas may overlap other active gadgets, so check them first + for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next) + { + if (gi->mapped && gi->active && + gi->type & GD_TYPE_TEXT_AREA && gi->textarea.full_open && + mx >= gi->textarea.full_x && mx < gi->textarea.full_x + gi->width && + my >= gi->textarea.full_y && my < gi->textarea.full_y + gi->height) + return gi; + } + // check all other gadgets for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next) { @@ -308,7 +318,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) border_x, gi->height, gi->x, gi->y); // middle part of gadget - for (i=0; i < gi->textbutton.size; i++) + for (i = 0; i < gi->textbutton.size; i++) BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y, font_width, gi->height, gi->x + border_x + i * font_width, gi->y); @@ -336,15 +346,19 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) char text[MAX_GADGET_TEXTSIZE + 1]; int font_nr = (pressed ? gi->font_active : gi->font); int font_width = getFontWidth(font_nr); + int font_height = getFontHeight(font_nr); + struct FontBitmapInfo *font = getFontBitmapInfo(font_nr); int border_x = gi->border.xsize; int border_y = gi->border.ysize; + int text_x = gi->x + font->draw_xoffset; + int text_y = gi->y + font->draw_yoffset; // left part of gadget BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y, border_x, gi->height, gi->x, gi->y); // middle part of gadget - for (i=0; i < gi->textinput.size + 1; i++) + for (i = 0; i < gi->textinput.size + 1; i++) BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y, font_width, gi->height, gi->x + border_x + i * font_width, gi->y); @@ -359,6 +373,15 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) strcpy(text, gi->textinput.value); strcat(text, " "); + // dirty workaround to erase text if input gadget font has draw offset + if (font->draw_xoffset != 0 || font->draw_yoffset != 0) + for (i = 0; i < gi->textinput.size + 1; i++) + BlitBitmapOnBackground(gd->bitmap, drawto, + gd->x + border_x, gd->y + border_y, + font_width, font_height, + text_x + border_x + i * font_width, + text_y + border_y); + // gadget text value DrawTextExt(drawto, gi->x + border_x, gi->y + border_y, text, @@ -389,69 +412,113 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) int border_x = gi->border.xsize; int border_y = gi->border.ysize; int gd_height = 2 * border_y + font_height; + int x = gi->x; + int y = gi->y; + int width = gi->width; + int height = gi->height; + int xsize = gi->textarea.xsize; + int ysize = gi->textarea.ysize; + + if (gi->textarea.cropped) + { + if (pressed) + { + x = gi->textarea.full_x; + y = gi->textarea.full_y; + + if (!gi->textarea.full_open) + { + gi->textarea.full_open = TRUE; + + // save background under fully opened text area + BlitBitmap(drawto, gfx.field_save_buffer, + gi->textarea.full_x, gi->textarea.full_y, + gi->width, gi->height, + gi->textarea.full_x, gi->textarea.full_y); + } + } + else + { + width = gi->textarea.crop_width; + height = gi->textarea.crop_height; + xsize = gi->textarea.crop_xsize; + ysize = gi->textarea.crop_ysize; + + if (gi->textarea.full_open) + { + gi->textarea.full_open = FALSE; + + // restore background under fully opened text area + BlitBitmap(gfx.field_save_buffer, drawto, + gi->textarea.full_x, gi->textarea.full_y, + gi->width, gi->height, + gi->textarea.full_x, gi->textarea.full_y); + } + } + } // top left part of gadget border BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y, - border_x, border_y, gi->x, gi->y); + border_x, border_y, x, y); // top middle part of gadget border - for (i=0; i < gi->textarea.xsize; i++) + for (i = 0; i < xsize; i++) BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y, font_width, border_y, - gi->x + border_x + i * font_width, gi->y); + x + border_x + i * font_width, y); // top right part of gadget border BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + gi->border.width - border_x, gd->y, border_x, border_y, - gi->x + gi->width - border_x, gi->y); + x + width - border_x, y); // left and right part of gadget border for each row - for (i=0; i < gi->textarea.ysize; i++) + for (i = 0; i < ysize; i++) { BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y + border_y, border_x, font_height, - gi->x, gi->y + border_y + i * font_height); + x, y + border_y + i * font_height); BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + gi->border.width - border_x, gd->y + border_y, border_x, font_height, - gi->x + gi->width - border_x, - gi->y + border_y + i * font_height); + x + width - border_x, + y + border_y + i * font_height); } // bottom left part of gadget border BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y + gd_height - border_y, border_x, border_y, - gi->x, gi->y + gi->height - border_y); + x, y + height - border_y); // bottom middle part of gadget border - for (i=0; i < gi->textarea.xsize; i++) + for (i = 0; i < xsize; i++) BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y + gd_height - border_y, font_width, border_y, - gi->x + border_x + i * font_width, - gi->y + gi->height - border_y); + x + border_x + i * font_width, + y + height - border_y); // bottom right part of gadget border BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + gi->border.width - border_x, gd->y + gd_height - border_y, border_x, border_y, - gi->x + gi->width - border_x, - gi->y + gi->height - border_y); + x + width - border_x, + y + height - border_y); ClearRectangleOnBackground(drawto, - gi->x + border_x, - gi->y + border_y, - gi->width - 2 * border_x, - gi->height - 2 * border_y); + x + border_x, + y + border_y, + width - 2 * border_x, + height - 2 * border_y); // gadget text value - DrawTextArea(gi->x + border_x, gi->y + border_y, gi->textarea.value, - font_nr, gi->textarea.xsize, -1, gi->textarea.ysize, 0, + DrawTextArea(x + border_x, y + border_y, gi->textarea.value, + font_nr, xsize, -1, ysize, 0, BLIT_ON_BACKGROUND, FALSE, FALSE, FALSE); cursor_letter = gi->textarea.value[gi->textarea.cursor_position]; @@ -461,8 +528,8 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) // draw cursor, if active if (pressed) DrawTextExt(drawto, - gi->x + border_x + gi->textarea.cursor_x * font_width, - gi->y + border_y + gi->textarea.cursor_y * font_height, + x + border_x + gi->textarea.cursor_x * font_width, + y + border_y + gi->textarea.cursor_y * font_height, cursor_string, font_nr, BLIT_INVERSE); } @@ -488,7 +555,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) border_x, gi->height, gi->x, gi->y); // middle part of gadget - for (i=0; i < gi->selectbox.size; i++) + for (i = 0; i < gi->selectbox.size; i++) BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y, font_width, gi->height, gi->x + border_x + i * font_width, gi->y); @@ -541,7 +608,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) gi->selectbox.x, gi->selectbox.y); // top middle part of gadget border - for (i=0; i < gi->selectbox.size; i++) + for (i = 0; i < gi->selectbox.size; i++) BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y, font_width, border_y, gi->selectbox.x + border_x + i * font_width, @@ -562,7 +629,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) gi->selectbox.y); // left and right part of gadget border for each row - for (i=0; i < gi->selectbox.num_values; i++) + for (i = 0; i < gi->selectbox.num_values; i++) { BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y + border_y, border_x, font_height, @@ -584,7 +651,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) gi->selectbox.y + box_height - border_y); // bottom middle part of gadget border - for (i=0; i < gi->selectbox.size; i++) + for (i = 0; i < gi->selectbox.size; i++) BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + border_x, gd->y + gi->height - border_y, @@ -615,7 +682,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) gi->selectbox.height - 2 * border_y); // selectbox text values - for (i=0; i < gi->selectbox.num_values; i++) + for (i = 0; i < gi->selectbox.num_values; i++) { int mask_mode = BLIT_MASKED; @@ -690,7 +757,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) xpos, ypos); // middle part of gadget - for (i=0; i < num_steps; i++) + for (i = 0; i < num_steps; i++) BlitBitmapOnBackground(gd->bitmap, drawto, gd->x, gd->y + gi->border.ysize, gi->width, design_body, @@ -737,7 +804,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) xpos, ypos); // middle part of gadget - for (i=0; i < num_steps; i++) + for (i = 0; i < num_steps; i++) BlitBitmapOnBackground(gd->bitmap, drawto, gd->x + gi->border.xsize, gd->y, design_body, gi->height, @@ -1386,6 +1453,8 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) int font_height = getFontHeight(font_nr); int border_xsize = gi->border.xsize; int border_ysize = gi->border.ysize; + int right_screen_border = getGadgetScreenBorderRight(); + int bottom_screen_border = getGadgetScreenBorderBottom(); if (gi->width == 0 || gi->height == 0) { @@ -1397,6 +1466,42 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) gi->textarea.xsize = (gi->width - 2 * border_xsize) / font_width; gi->textarea.ysize = (gi->height - 2 * border_ysize) / font_height; } + + gi->textarea.full_x = gi->x; + gi->textarea.full_y = gi->y; + gi->textarea.crop_width = gi->width; + gi->textarea.crop_height = gi->height; + gi->textarea.crop_xsize = gi->textarea.xsize; + gi->textarea.crop_ysize = gi->textarea.ysize; + + gi->textarea.cropped = FALSE; + + if (gi->x + gi->width > right_screen_border) + { + gi->textarea.full_x = MAX(0, right_screen_border - gi->width); + gi->textarea.crop_width = right_screen_border - gi->x; + gi->textarea.crop_xsize = + (gi->textarea.crop_width - 2 * border_xsize) / font_width; + gi->textarea.crop_width = + 2 * border_xsize + gi->textarea.crop_xsize * font_width; + + gi->textarea.cropped = TRUE; + } + + if (gi->y + gi->height > bottom_screen_border) + { + gi->textarea.full_y = MAX(0, bottom_screen_border - gi->height); + gi->textarea.crop_height = bottom_screen_border - gi->y; + gi->textarea.crop_ysize = + (gi->textarea.crop_height - 2 * border_ysize) / font_height; + gi->textarea.crop_height = + 2 * border_ysize + gi->textarea.crop_ysize * font_height; + + gi->textarea.cropped = TRUE; + } + + // always start with unselected text area (which is potentially cropped) + gi->textarea.full_open = FALSE; } } @@ -1887,8 +1992,10 @@ boolean HandleGadgets(int mx, int my, int button) else if (gi->type & GD_TYPE_TEXT_AREA && button != 0 && !motion_status) { int old_cursor_position = gi->textarea.cursor_position; - int x = (mx - gi->x - gi->border.xsize) / getFontWidth(gi->font); - int y = (my - gi->y - gi->border.ysize) / getFontHeight(gi->font); + int gadget_x = mx - gi->textarea.full_x - gi->border.xsize; + int gadget_y = my - gi->textarea.full_y - gi->border.ysize; + int x = gadget_x / getFontWidth(gi->font); + int y = gadget_y / getFontHeight(gi->font); x = (x < 0 ? 0 : x >= gi->textarea.xsize ? gi->textarea.xsize - 1 : x); y = (y < 0 ? 0 : y >= gi->textarea.ysize ? gi->textarea.ysize - 1 : y);