X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fbuttons.c;h=88ff994e07ae633a0ff980c11607358bfed95d06;hb=228a5718ede5ee00512ed2e333b3cee47baa124c;hp=78e28d168a762814388b2d08c988bd2d721ac4ac;hpb=20e58eb6573a45a41c25958e17e8d9c20f738edc;p=rocksndiamonds.git diff --git a/src/buttons.c b/src/buttons.c index 78e28d16..88ff994e 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -138,13 +138,13 @@ void DrawVideoDisplay(unsigned long state, unsigned long value) { int cx = DOOR_GFX_PAGEX3, cy = DOOR_GFX_PAGEY2; - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + VIDEO_REC_LABEL_XPOS, - cy + VIDEO_REC_LABEL_YPOS, - VIDEO_PBEND_LABEL_XSIZE, - VIDEO_PBEND_LABEL_YSIZE, - VX + VIDEO_REC_LABEL_XPOS, - VY + VIDEO_REC_LABEL_YPOS); + BlitBitmap(pix[PIX_DOOR], drawto, + cx + VIDEO_REC_LABEL_XPOS, + cy + VIDEO_REC_LABEL_YPOS, + VIDEO_PBEND_LABEL_XSIZE, + VIDEO_PBEND_LABEL_YSIZE, + VX + VIDEO_REC_LABEL_XPOS, + VY + VIDEO_REC_LABEL_YPOS); } for(i=0;i<10;i++) @@ -159,21 +159,21 @@ void DrawVideoDisplay(unsigned long state, unsigned long value) cx = DOOR_GFX_PAGEX3; /* i gerade => STATE_OFF / PRESS_ON */ if (video_pos[pos][part_label][0] && value != VIDEO_DISPLAY_SYMBOL_ONLY) - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + video_pos[pos][part_label][xpos], - cy + video_pos[pos][part_label][ypos], - video_pos[pos][part_label][xsize], - video_pos[pos][part_label][ysize], - VX + video_pos[pos][part_label][xpos], - VY + video_pos[pos][part_label][ypos]); + BlitBitmap(pix[PIX_DOOR], drawto, + cx + video_pos[pos][part_label][xpos], + cy + video_pos[pos][part_label][ypos], + video_pos[pos][part_label][xsize], + video_pos[pos][part_label][ysize], + VX + video_pos[pos][part_label][xpos], + VY + video_pos[pos][part_label][ypos]); if (video_pos[pos][part_symbol][0] && value != VIDEO_DISPLAY_LABEL_ONLY) - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + video_pos[pos][part_symbol][xpos], - cy + video_pos[pos][part_symbol][ypos], - video_pos[pos][part_symbol][xsize], - video_pos[pos][part_symbol][ysize], - VX + video_pos[pos][part_symbol][xpos], - VY + video_pos[pos][part_symbol][ypos]); + BlitBitmap(pix[PIX_DOOR], drawto, + cx + video_pos[pos][part_symbol][xpos], + cy + video_pos[pos][part_symbol][ypos], + video_pos[pos][part_symbol][xsize], + video_pos[pos][part_symbol][ysize], + VX + video_pos[pos][part_symbol][xpos], + VY + video_pos[pos][part_symbol][ypos]); } } @@ -181,26 +181,26 @@ void DrawVideoDisplay(unsigned long state, unsigned long value) { int cx = DOOR_GFX_PAGEX4, cy = DOOR_GFX_PAGEY2; - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + VIDEO_PLAY_SYMBOL_XPOS, - cy + VIDEO_PLAY_SYMBOL_YPOS, - VIDEO_PLAY_SYMBOL_XSIZE - 2, - VIDEO_PLAY_SYMBOL_YSIZE, - VX + VIDEO_PLAY_SYMBOL_XPOS - 9, - VY + VIDEO_PLAY_SYMBOL_YPOS); + BlitBitmap(pix[PIX_DOOR], drawto, + cx + VIDEO_PLAY_SYMBOL_XPOS, + cy + VIDEO_PLAY_SYMBOL_YPOS, + VIDEO_PLAY_SYMBOL_XSIZE - 2, + VIDEO_PLAY_SYMBOL_YSIZE, + VX + VIDEO_PLAY_SYMBOL_XPOS - 9, + VY + VIDEO_PLAY_SYMBOL_YPOS); } if (state & VIDEO_STATE_PBEND_ON) { int cx = DOOR_GFX_PAGEX6, cy = DOOR_GFX_PAGEY1; - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + VIDEO_PBEND_LABEL_XPOS, - cy + VIDEO_PBEND_LABEL_YPOS, - VIDEO_PBEND_LABEL_XSIZE, - VIDEO_PBEND_LABEL_YSIZE, - VX + VIDEO_REC_LABEL_XPOS, - VY + VIDEO_REC_LABEL_YPOS); + BlitBitmap(pix[PIX_DOOR], drawto, + cx + VIDEO_PBEND_LABEL_XPOS, + cy + VIDEO_PBEND_LABEL_YPOS, + VIDEO_PBEND_LABEL_XSIZE, + VIDEO_PBEND_LABEL_YSIZE, + VX + VIDEO_REC_LABEL_XPOS, + VY + VIDEO_REC_LABEL_YPOS); } if (state & VIDEO_STATE_DATE_ON) @@ -238,13 +238,13 @@ void DrawVideoDisplay(unsigned long state, unsigned long value) void DrawCompleteVideoDisplay() { - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - DOOR_GFX_PAGEX3,DOOR_GFX_PAGEY2, VXSIZE,VYSIZE, VX,VY); - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - DOOR_GFX_PAGEX4+VIDEO_CONTROL_XPOS, - DOOR_GFX_PAGEY2+VIDEO_CONTROL_YPOS, - VIDEO_CONTROL_XSIZE,VIDEO_CONTROL_YSIZE, - VX+VIDEO_CONTROL_XPOS,VY+VIDEO_CONTROL_YPOS); + BlitBitmap(pix[PIX_DOOR], drawto, + DOOR_GFX_PAGEX3,DOOR_GFX_PAGEY2, VXSIZE,VYSIZE, VX,VY); + BlitBitmap(pix[PIX_DOOR], drawto, + DOOR_GFX_PAGEX4+VIDEO_CONTROL_XPOS, + DOOR_GFX_PAGEY2+VIDEO_CONTROL_YPOS, + VIDEO_CONTROL_XSIZE,VIDEO_CONTROL_YSIZE, + VX+VIDEO_CONTROL_XPOS,VY+VIDEO_CONTROL_YPOS); DrawVideoDisplay(VIDEO_ALL_OFF,0); if (tape.date && tape.length) @@ -253,8 +253,8 @@ void DrawCompleteVideoDisplay() DrawVideoDisplay(VIDEO_STATE_TIME_ON,tape.length_seconds); } - XCopyArea(display,drawto,pix[PIX_DB_DOOR],gc, - VX,VY, VXSIZE,VYSIZE, DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY2); + BlitBitmap(drawto, pix[PIX_DB_DOOR], + VX,VY, VXSIZE,VYSIZE, DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY2); } @@ -345,14 +345,14 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) case GD_TYPE_NORMAL_BUTTON: case GD_TYPE_CHECK_BUTTON: case GD_TYPE_RADIO_BUTTON: - XCopyArea(display, gd->pixmap, drawto, gc, - gd->x, gd->y, gi->width, gi->height, gi->x, gi->y); - if (gi->deco.design.pixmap) - XCopyArea(display, gi->deco.design.pixmap, drawto, gc, - gi->deco.design.x, gi->deco.design.y, - gi->deco.width, gi->deco.height, - gi->x + gi->deco.x + (pressed ? gi->deco.xshift : 0), - gi->y + gi->deco.y + (pressed ? gi->deco.yshift : 0)); + BlitBitmap(gd->bitmap, drawto, + gd->x, gd->y, gi->width, gi->height, gi->x, gi->y); + if (gi->deco.design.bitmap) + BlitBitmap(gi->deco.design.bitmap, drawto, + gi->deco.design.x, gi->deco.design.y, + gi->deco.width, gi->deco.height, + gi->x + gi->deco.x + (pressed ? gi->deco.xshift : 0), + gi->y + gi->deco.y + (pressed ? gi->deco.yshift : 0)); break; case GD_TYPE_TEXTINPUT_ALPHANUMERIC: @@ -362,28 +362,29 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) char cursor_letter; char cursor_string[3]; char text[MAX_GADGET_TEXTSIZE + 1]; - int font_color = FC_YELLOW; - int border = gi->design_border; + int font_type = gi->text.font_type; + int font_width = getFontWidth(FS_SMALL, font_type); + int border = gi->border.size; strcpy(text, gi->text.value); strcat(text, " "); /* left part of gadget */ - XCopyArea(display, gd->pixmap, drawto, gc, - gd->x, gd->y, border, gi->height, gi->x, gi->y); + BlitBitmap(gd->bitmap, drawto, + gd->x, gd->y, border, gi->height, gi->x, gi->y); /* middle part of gadget */ for (i=0; i<=gi->text.size; i++) - XCopyArea(display, gd->pixmap, drawto, gc, - gd->x + border, gd->y, FONT2_XSIZE, gi->height, - gi->x + border + i * FONT2_XSIZE, gi->y); + BlitBitmap(gd->bitmap, drawto, + gd->x + border, gd->y, font_width, gi->height, + gi->x + border + i * font_width, gi->y); /* right part of gadget */ - XCopyArea(display, gd->pixmap, drawto, gc, - gd->x + ED_WIN_COUNT_XSIZE - border, gd->y, - border, gi->height, gi->x + gi->width - border, gi->y); + BlitBitmap(gd->bitmap, drawto, + gd->x + gi->border.width - border, gd->y, + border, gi->height, gi->x + gi->width - border, gi->y); /* gadget text value */ - DrawText(gi->x + border, gi->y + border, text, FS_SMALL, font_color); + DrawText(gi->x + border, gi->y + border, text, FS_SMALL, font_type); cursor_letter = gi->text.value[gi->text.cursor_position]; cursor_string[0] = '~'; @@ -392,8 +393,8 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) /* draw cursor, if active */ if (pressed) - DrawText(gi->x + border + gi->text.cursor_position * FONT2_XSIZE, - gi->y + border, cursor_string, FS_SMALL, font_color); + DrawText(gi->x + border + gi->text.cursor_position * font_width, + gi->y + border, cursor_string, FS_SMALL, font_type); } break; @@ -403,41 +404,40 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) int xpos = gi->x; int ypos = gi->y + gi->scrollbar.position; int design_full = gi->width; - int design_body = design_full - 2 * gi->design_border; + int design_body = design_full - 2 * gi->border.size; int size_full = gi->scrollbar.size; - int size_body = size_full - 2 * gi->design_border; + int size_body = size_full - 2 * gi->border.size; int num_steps = size_body / design_body; int step_size_remain = size_body - num_steps * design_body; /* clear scrollbar area */ - XFillRectangle(display, backbuffer, gc, - gi->x, gi->y, gi->width, gi->height); + ClearRectangle(backbuffer, gi->x, gi->y, gi->width, gi->height); /* upper part of gadget */ - XCopyArea(display, gd->pixmap, drawto, gc, - gd->x, gd->y, - gi->width, gi->design_border, - xpos, ypos); + BlitBitmap(gd->bitmap, drawto, + gd->x, gd->y, + gi->width, gi->border.size, + xpos, ypos); /* middle part of gadget */ for (i=0; ipixmap, drawto, gc, - gd->x, gd->y + gi->design_border, - gi->width, design_body, - xpos, ypos + gi->design_border + i * design_body); + BlitBitmap(gd->bitmap, drawto, + gd->x, gd->y + gi->border.size, + gi->width, design_body, + xpos, ypos + gi->border.size + i * design_body); /* remaining middle part of gadget */ if (step_size_remain > 0) - XCopyArea(display, gd->pixmap, drawto, gc, - gd->x, gd->y + gi->design_border, - gi->width, step_size_remain, - xpos, ypos + gi->design_border + num_steps * design_body); + BlitBitmap(gd->bitmap, drawto, + gd->x, gd->y + gi->border.size, + gi->width, step_size_remain, + xpos, ypos + gi->border.size + num_steps * design_body); /* lower part of gadget */ - XCopyArea(display, gd->pixmap, drawto, gc, - gd->x, gd->y + design_full - gi->design_border, - gi->width, gi->design_border, - xpos, ypos + size_full - gi->design_border); + BlitBitmap(gd->bitmap, drawto, + gd->x, gd->y + design_full - gi->border.size, + gi->width, gi->border.size, + xpos, ypos + size_full - gi->border.size); } break; @@ -447,41 +447,40 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) int xpos = gi->x + gi->scrollbar.position; int ypos = gi->y; int design_full = gi->height; - int design_body = design_full - 2 * gi->design_border; + int design_body = design_full - 2 * gi->border.size; int size_full = gi->scrollbar.size; - int size_body = size_full - 2 * gi->design_border; + int size_body = size_full - 2 * gi->border.size; int num_steps = size_body / design_body; int step_size_remain = size_body - num_steps * design_body; /* clear scrollbar area */ - XFillRectangle(display, backbuffer, gc, - gi->x, gi->y, gi->width, gi->height); + ClearRectangle(backbuffer, gi->x, gi->y, gi->width, gi->height); /* left part of gadget */ - XCopyArea(display, gd->pixmap, drawto, gc, - gd->x, gd->y, - gi->design_border, gi->height, - xpos, ypos); + BlitBitmap(gd->bitmap, drawto, + gd->x, gd->y, + gi->border.size, gi->height, + xpos, ypos); /* middle part of gadget */ for (i=0; ipixmap, drawto, gc, - gd->x + gi->design_border, gd->y, - design_body, gi->height, - xpos + gi->design_border + i * design_body, ypos); + BlitBitmap(gd->bitmap, drawto, + gd->x + gi->border.size, gd->y, + design_body, gi->height, + xpos + gi->border.size + i * design_body, ypos); /* remaining middle part of gadget */ if (step_size_remain > 0) - XCopyArea(display, gd->pixmap, drawto, gc, - gd->x + gi->design_border, gd->y, - step_size_remain, gi->height, - xpos + gi->design_border + num_steps * design_body, ypos); + BlitBitmap(gd->bitmap, drawto, + gd->x + gi->border.size, gd->y, + step_size_remain, gi->height, + xpos + gi->border.size + num_steps * design_body, ypos); /* right part of gadget */ - XCopyArea(display, gd->pixmap, drawto, gc, - gd->x + design_full - gi->design_border, gd->y, - gi->design_border, gi->height, - xpos + size_full - gi->design_border, ypos); + BlitBitmap(gd->bitmap, drawto, + gd->x + design_full - gi->border.size, gd->y, + gi->border.size, gi->height, + xpos + size_full - gi->border.size, ypos); } break; @@ -490,8 +489,8 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) } if (direct) - XCopyArea(display, drawto, window, gc, - gi->x, gi->y, gi->width, gi->height, gi->x, gi->y); + BlitBitmap(drawto, window, + gi->x, gi->y, gi->width, gi->height, gi->x, gi->y); else redraw_mask |= (gi->x < SX + SXSIZE ? REDRAW_FIELD : gi->y < DY + DYSIZE ? REDRAW_DOOR_1 : @@ -599,45 +598,47 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) gi->text.size = max_textsize; gi->text.value[max_textsize] = '\0'; - - if (gi->width == 0 && gi->height == 0) - { - gi->width = (gi->text.size + 1) * FONT2_XSIZE + 6; - gi->height = ED_WIN_COUNT_YSIZE; - } } break; + case GDI_TEXT_FONT: + gi->text.font_type = va_arg(ap, int); + break; + case GDI_DESIGN_UNPRESSED: - gi->design[GD_BUTTON_UNPRESSED].pixmap = va_arg(ap, Pixmap); + gi->design[GD_BUTTON_UNPRESSED].bitmap = va_arg(ap, Bitmap); gi->design[GD_BUTTON_UNPRESSED].x = va_arg(ap, int); gi->design[GD_BUTTON_UNPRESSED].y = va_arg(ap, int); break; case GDI_DESIGN_PRESSED: - gi->design[GD_BUTTON_PRESSED].pixmap = va_arg(ap, Pixmap); + gi->design[GD_BUTTON_PRESSED].bitmap = va_arg(ap, Bitmap); gi->design[GD_BUTTON_PRESSED].x = va_arg(ap, int); gi->design[GD_BUTTON_PRESSED].y = va_arg(ap, int); break; case GDI_ALT_DESIGN_UNPRESSED: - gi->alt_design[GD_BUTTON_UNPRESSED].pixmap= va_arg(ap, Pixmap); + gi->alt_design[GD_BUTTON_UNPRESSED].bitmap= va_arg(ap, Bitmap); gi->alt_design[GD_BUTTON_UNPRESSED].x = va_arg(ap, int); gi->alt_design[GD_BUTTON_UNPRESSED].y = va_arg(ap, int); break; case GDI_ALT_DESIGN_PRESSED: - gi->alt_design[GD_BUTTON_PRESSED].pixmap = va_arg(ap, Pixmap); + gi->alt_design[GD_BUTTON_PRESSED].bitmap = va_arg(ap, Bitmap); gi->alt_design[GD_BUTTON_PRESSED].x = va_arg(ap, int); gi->alt_design[GD_BUTTON_PRESSED].y = va_arg(ap, int); break; - case GDI_DESIGN_BORDER: - gi->design_border = va_arg(ap, int); + case GDI_BORDER_SIZE: + gi->border.size = va_arg(ap, int); + break; + + case GDI_TEXTINPUT_DESIGN_WIDTH: + gi->border.width = va_arg(ap, int); break; case GDI_DECORATION_DESIGN: - gi->deco.design.pixmap = va_arg(ap, Pixmap); + gi->deco.design.bitmap = va_arg(ap, Bitmap); gi->deco.design.x = va_arg(ap, int); gi->deco.design.y = va_arg(ap, int); break; @@ -728,12 +729,21 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) /* check if gadget complete */ if (gi->type != GD_TYPE_DRAWING_AREA && - (!gi->design[GD_BUTTON_UNPRESSED].pixmap || - !gi->design[GD_BUTTON_PRESSED].pixmap)) - Error(ERR_EXIT, "gadget incomplete (missing Pixmap)"); + (!gi->design[GD_BUTTON_UNPRESSED].bitmap || + !gi->design[GD_BUTTON_PRESSED].bitmap)) + Error(ERR_EXIT, "gadget incomplete (missing Bitmap)"); /* adjust gadget values in relation to other gadget values */ + if (gi->type & GD_TYPE_TEXTINPUT) + { + int font_width = getFontWidth(FS_SMALL, gi->text.font_type); + int font_height = getFontHeight(FS_SMALL, gi->text.font_type); + + gi->width = 2 * gi->border.size + (gi->text.size + 1) * font_width; + gi->height = 2 * gi->border.size + font_height; + } + if (gi->type & GD_TYPE_TEXTINPUT_NUMERIC) { struct GadgetTextInput *text = &gi->text; @@ -760,6 +770,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) gs->size = gs->size_max * gs->items_visible / gs->items_max; gs->position = gs->size_max * gs->item_position / gs->items_max; gs->position_max = gs->size_max - gs->size; + gs->correction = gs->size_max / gs->items_max / 2; /* finetuning for maximal right/bottom position */ if (gs->item_position == gs->items_max - gs->items_visible) @@ -992,7 +1003,9 @@ void HandleGadgets(int mx, int my, int button) if (new_gi == last_gi) { /* if mouse button pressed inside activated text gadget, set cursor */ - gi->text.cursor_position = (mx - gi->x) / FONT2_XSIZE; + gi->text.cursor_position = + (mx - gi->x - gi->border.size) / + getFontWidth(FS_SMALL, gi->text.font_type); if (gi->text.cursor_position < 0) gi->text.cursor_position = 0; @@ -1007,6 +1020,8 @@ void HandleGadgets(int mx, int my, int button) CheckRangeOfNumericInputGadget(gi); DrawGadget(gi, DG_UNPRESSED, DG_DIRECT); + gi->event.type = GD_EVENT_TEXT_LEAVING; + if (gi->event_mask & GD_EVENT_TEXT_LEAVING) gi->callback_action(gi); @@ -1213,7 +1228,13 @@ void HandleGadgets(int mx, int my, int button) if (gs->position > gs->position_max) gs->position = gs->position_max; - gs->item_position = gs->items_max * gs->position / gs->size_max; + gs->item_position = + gs->items_max * (gs->position + gs->correction) / gs->size_max; + + if (gs->item_position < 0) + gs->item_position = 0; + if (gs->item_position > gs->items_max - 1) + gs->item_position = gs->items_max - 1; if (old_item_position != gs->item_position) { @@ -1259,7 +1280,7 @@ void HandleGadgets(int mx, int my, int button) } } -void HandleGadgetsKeyInput(KeySym key) +void HandleGadgetsKeyInput(Key key) { struct GadgetInfo *gi = last_gi; char text[MAX_GADGET_TEXTSIZE]; @@ -1273,7 +1294,7 @@ void HandleGadgetsKeyInput(KeySym key) text_length = strlen(gi->text.value); cursor_pos = gi->text.cursor_position; - letter = getCharFromKeySym(key); + letter = getCharFromKey(key); legal_letter = (gi->type == GD_TYPE_TEXTINPUT_NUMERIC ? letter >= '0' && letter <= '9' : letter != 0); @@ -1286,34 +1307,36 @@ void HandleGadgetsKeyInput(KeySym key) gi->text.cursor_position++; DrawGadget(gi, DG_PRESSED, DG_DIRECT); } - else if (key == XK_Left && cursor_pos > 0) + else if (key == KSYM_Left && cursor_pos > 0) { gi->text.cursor_position--; DrawGadget(gi, DG_PRESSED, DG_DIRECT); } - else if (key == XK_Right && cursor_pos < text_length) + else if (key == KSYM_Right && cursor_pos < text_length) { gi->text.cursor_position++; DrawGadget(gi, DG_PRESSED, DG_DIRECT); } - else if (key == XK_BackSpace && cursor_pos > 0) + else if (key == KSYM_BackSpace && cursor_pos > 0) { strcpy(text, gi->text.value); strcpy(&gi->text.value[cursor_pos - 1], &text[cursor_pos]); gi->text.cursor_position--; DrawGadget(gi, DG_PRESSED, DG_DIRECT); } - else if (key == XK_Delete && cursor_pos < text_length) + else if (key == KSYM_Delete && cursor_pos < text_length) { strcpy(text, gi->text.value); strcpy(&gi->text.value[cursor_pos], &text[cursor_pos + 1]); DrawGadget(gi, DG_PRESSED, DG_DIRECT); } - else if (key == XK_Return) + else if (key == KSYM_Return) { CheckRangeOfNumericInputGadget(gi); DrawGadget(gi, DG_UNPRESSED, DG_DIRECT); + gi->event.type = GD_EVENT_TEXT_RETURN; + if (gi->event_mask & GD_EVENT_TEXT_RETURN) gi->callback_action(gi);