From 194e5335d55e2af36ed62c52a217c1f4dee49df1 Mon Sep 17 00:00:00 2001 From: dwk Date: Sat, 17 May 2008 12:34:41 -0400 Subject: [PATCH] Small bugfixes. - Empty textboxes now display cursors - get_label_image_pos() was re-written -- it now takes sensible parameters, and uses font_height() instead of the height of rendered SDL_Surfaces - This allows empty textboxes to have cursors, even though they do not have rendered SDL_Surfaces - When a character only partially visible is selected in a textbox, the textbox scrolls so that this character is fully visible - xuni no longer crashes with libfreetype6 2.3.5-1+b1 with font point size 1 (the smallest possible point size has been made 2) - Images are now rotated and then rescaled - Scrollbar buttons look much better now - Listboxes now clip very well (though it remains a temporary solution) --- TODO | 4 +-- src/gui.c | 10 ++++++ src/widget/font.c | 5 +++ src/widget/image.c | 19 ++++++++++-- src/widget/label.c | 87 +++++++++++++++++++++++++++++++--------------------- src/widget/listbox.c | 12 +++++--- 6 files changed, 92 insertions(+), 45 deletions(-) diff --git a/TODO b/TODO index 0426f86..be996a1 100644 --- a/TODO +++ b/TODO @@ -328,11 +328,11 @@ textbox_t::text is not used at the moment. Perhaps it should be eliminated. Listbox data panels are offset according to the roundness of the current theme. When the roundness changes, they need to be moved, in rescale_listbox() most likely. -A text cursor needs to be painted when textboxes are empty. +[done] A text cursor needs to be painted when textboxes are empty. When textboxes revert, the text jumps to the end. This is because clear_active() calls rescale_label(): here, reposition_label_data() is only called when it needs to be. -When the mouse selects a character that is only partially visible, the textbox text needs to scroll so that this character is fully visible. +[done] When the mouse selects a character that is only partially visible, the textbox text needs to scroll so that this character is fully visible. Make the images for the glowbox theme smaller. diff --git a/src/gui.c b/src/gui.c index 4289b8f..bce22da 100644 --- a/src/gui.c +++ b/src/gui.c @@ -1148,6 +1148,16 @@ void activate_widget(struct widget_t *widget, struct xuni_t *xuni, else { edit->pos = 0; } + + /* Reposition the textbox so that the cursor is inside the visible + portion of the textbox. If a half-invisible character is selected, + for example, this will scroll the textbox slightly so that the + cursor is visible. + + This would be unnecessary if textbox selection was based on the + label instead of the box of the textbox. + */ + widget_event(xuni, widget, WIDGET_EVENT_REPOSITION); } } diff --git a/src/widget/font.c b/src/widget/font.c index e504146..d7b66ca 100644 --- a/src/widget/font.c +++ b/src/widget/font.c @@ -179,6 +179,11 @@ static int pick_font_point(struct xuni_t *xuni) { /*printf("Picking font size %i\n", (int)point);*/ + /* restrict the font point size to a minimum of 2 + libfreetype6 2.3.5-1+b1 often crashes with point size 1 + */ + if(point <= 1) return 2; + return point; } diff --git a/src/widget/image.c b/src/widget/image.c index d0ec984..f89aff6 100644 --- a/src/widget/image.c +++ b/src/widget/image.c @@ -103,6 +103,8 @@ void prepare_paint_image(struct xuni_t *xuni, struct widget_t *widget) { #if 1 static void generate_image(struct xuni_t *xuni, struct widget_t *widget) { + SDL_Surface *use; + if(!widget->p.image->original) { if(!widget->p.image->filename) { log_message(ERROR_TYPE_WARNING, 0, __FILE__, __LINE__, @@ -123,7 +125,14 @@ static void generate_image(struct xuni_t *xuni, struct widget_t *widget) { * widget->p.image->screen->h / widget->p.image->original->h, SMOOTHING_ON);*/ - widget->p.image->image = zoomSurface(widget->p.image->original, + use = widget->p.image->original; + + if(widget->p.image->angle) { + use = rotozoomSurface(widget->p.image->original, + radians_to_degrees(widget->p.image->angle), 1.0, SMOOTHING_ON); + } + + widget->p.image->image = zoomSurface(use, widget->pos->scale.w / 100.0 / ((double)xuni->smode->screen->w / widget->base->pos->real.w) * xuni->smode->screen->w / widget->p.image->original->w, @@ -132,12 +141,16 @@ static void generate_image(struct xuni_t *xuni, struct widget_t *widget) { * xuni->smode->screen->h / widget->p.image->original->h, SMOOTHING_ON); - if(widget->p.image->image && widget->p.image->angle) { + if(widget->p.image->angle) { + SDL_FreeSurface(use); + } + + /*if(widget->p.image->image && widget->p.image->angle) { SDL_Surface *temp = rotozoomSurface(widget->p.image->image, radians_to_degrees(widget->p.image->angle), 1.0, SMOOTHING_ON); SDL_FreeSurface(widget->p.image->image); widget->p.image->image = temp; - } + }*/ xuni_memory_add_block(widget->p.image->image, MEMORY_BLOCK_TYPE_SDL_SURFACE); diff --git a/src/widget/label.c b/src/widget/label.c index fd90293..3ff4f48 100644 --- a/src/widget/label.c +++ b/src/widget/label.c @@ -20,8 +20,8 @@ static void rescale_label(struct xuni_t *xuni, struct widget_t *widget); static void paint_label(struct xuni_t *xuni, struct widget_t *widget); static void update_text_label(struct xuni_t *xuni, struct widget_t *widget); -static void get_label_image_pos(enum label_type_t type, const SDL_Rect *real, - const SDL_Surface *image, int *x, int *y); +static void get_label_image_pos(struct xuni_t *xuni, struct widget_t *widget, + int *x, int *y); static int label_pos_to_width(struct xuni_t *xuni, struct widget_edit_t *edit, struct widget_t *font); static void paint_label_clip(SDL_Surface *image, SDL_Surface *screen, @@ -74,23 +74,32 @@ static void free_label(struct xuni_t *xuni, struct widget_t *widget) { } } -static void get_label_image_pos(enum label_type_t type, const SDL_Rect *real, - const SDL_Surface *image, int *x, int *y) { +static void get_label_image_pos(struct xuni_t *xuni, struct widget_t *widget, + int *x, int *y) { - switch(type) { + const SDL_Rect *real = &widget->pos->real; + int height + = font_height(xuni, get_theme_widget(xuni, widget->p.label->font)); + int width = 0; + + if(widget->p.label->label) { + width = widget->p.label->label->w; + } + + switch(widget->p.label->type) { case LABEL_ALIGN_LEFT: - *y += (real->h - image->h) / 2; + *y += (real->h - height) / 2; break; case LABEL_ALIGN_CENTRE: - *x += (real->w - image->w) / 2; - *y += (real->h - image->h) / 2; + *x += (real->w - width) / 2; + *y += (real->h - height) / 2; break; case LABEL_ALIGN_RIGHT: - *x += real->w - image->w; - *y += (real->h - image->h) / 2; + *x += real->w - width; + *y += (real->h - height) / 2; break; default: - printf("*** Unknown label type: %i\n", (int)type); + printf("*** Unknown label type: %i\n", (int)widget->p.label->type); break; } } @@ -98,6 +107,8 @@ static void get_label_image_pos(enum label_type_t type, const SDL_Rect *real, static void paint_label_clip(SDL_Surface *image, SDL_Surface *screen, int x, int y, struct clip_pos_t *clip) { + if(!image) return; + if(!clip) { blit_surface(screen, image, x, y); } @@ -190,17 +201,18 @@ static void paint_edit_label(struct xuni_t *xuni, struct widget_edit_t *edit, static void paint_label(struct xuni_t *xuni, struct widget_t *widget) { int x = 0, y = 0; - if(!widget->p.label->label) { - return; - } - /*if(widget->sel) { SDL_FillRect(xuni->smode->screen, &widget->pos->real, SDL_MapRGB(xuni->smode->screen->format, 0, 0, 128)); }*/ - get_label_image_pos(widget->p.label->type, &widget->pos->real, - widget->p.label->label, &x, &y); + /*if(widget->p.label->label->h != + font_height(xuni, get_theme_widget(xuni, widget->p.label->font))) { + + printf("Not equal!\n"); + }*/ + + get_label_image_pos(xuni, widget, &x, &y); x += widget->pos->real.x; y += widget->pos->real.y; @@ -284,12 +296,20 @@ void reposition_label_data(struct xuni_t *xuni, struct label_t *label, static void reposition_label(struct xuni_t *xuni, struct widget_t *widget) { int offset; + int scroll = 0; /* !!! hack to allow textbox scrolling */ - if(/*widget->p.label->label &&*/ widget->base && widget->base->pos - && (widget->base->type == WIDGET_TEXTBOX - || widget->base->type == WIDGET_PANEL)) { + if(/*widget->p.label->label &&*/ widget->base && widget->base->pos) { + if(widget->base->type == WIDGET_TEXTBOX) scroll = 1; + if(widget->base->type == WIDGET_PANEL && widget->base->base + && widget->base->base->type == WIDGET_LISTBOX) { + + /*scroll = 1;*/ + } + } + + if(scroll) { double width = get_box_width(xuni, xuni->theme->current) / 100.0 * xuni->smode->width; int labelw; @@ -305,28 +325,25 @@ static void reposition_label(struct xuni_t *xuni, struct widget_t *widget) { offset = labelw - widget->base->pos->real.w + width * 2; /*printf("base width: %i\n", widget->base->pos->real.w); print_inline_widget_backtrace(widget);*/ - if(widget->base->type == WIDGET_TEXTBOX) { - if(offset > 0) { - add_widget_clip(xuni, widget, 0, 0, offset, 0, 0, 0); - } - - add_widget_clip(xuni, widget, width, 0, 0, 0, -width * 2, 0); + + if(offset > 0) { + add_widget_clip(xuni, widget, 0, 0, offset, 0, 0, 0); } + add_widget_clip(xuni, widget, width, 0, 0, 0, -width * 2, 0); + if(offset < 0) widget->pos->real.w = labelw; else { widget->pos->real.w = widget->base->pos->real.w - width * 2; } - /*if(widget->base->type == WIDGET_TEXTBOX) {*/ - if(widget == xuni->gui->edit.datawidget) { - reposition_label_data(xuni, xuni->gui->edit.data, - &xuni->gui->edit, xuni->gui->edit.pos); - } - /*else { - add_widget_clip(xuni, widget, 0, 0, - -widget->base->p.textbox->leftpos, 0, 0, 0); - } + if(widget == xuni->gui->edit.datawidget) { + reposition_label_data(xuni, xuni->gui->edit.data, + &xuni->gui->edit, xuni->gui->edit.pos); + } + /*else { + add_widget_clip(xuni, widget, 0, 0, + -widget->base->p.textbox->leftpos, 0, 0, 0); }*/ /* !!! too small most likely */ diff --git a/src/widget/listbox.c b/src/widget/listbox.c index f2b22a2..459e737 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -78,10 +78,12 @@ void init_listbox(struct widget_t *widget, struct xuni_t *xuni, double width = calculate_scrollbar_width(widget, xuni); double height = calculate_scrollbar_height(widget, xuni); /*double boxsize = 100.0 / 20.0;*/ - double boxsize = get_box_width(xuni, xuni->theme->current) * 2; - double boxsizeh = get_box_height(xuni, xuni->theme->current) * 2; + double boxsize = get_box_width(xuni, xuni->theme->current) * 4; + double boxsizeh = get_box_height(xuni, xuni->theme->current) * 4; int w = 0, h = 0; + /*printf("%f %f\n", boxsize, boxsizeh);*/ + if(force & SCROLLBAR_USE_VERTICAL) w = width; if(force & SCROLLBAR_USE_HORIZONTAL) h = height; @@ -240,16 +242,16 @@ static void free_listbox(struct xuni_t *xuni, struct widget_t *widget) { static void paint_listbox(struct xuni_t *xuni, struct widget_t *widget) { /*size_t x, start = 3;*/ - int height, width; + /*int height, width;*/ int yclip; widget_event(xuni, widget->compose->widget[WID_LISTBOX_BOX], WIDGET_EVENT_PAINT); - height = get_box_height(xuni, xuni->theme->current) / 100.0 + /*height = get_box_height(xuni, xuni->theme->current) / 100.0 * xuni->smode->height; width = get_box_width(xuni, xuni->theme->current) / 100.0 - * xuni->smode->width; + * xuni->smode->width;*/ yclip = get_scrollbar_pos_int( widget->compose->widget[WID_LISTBOX_VSCROLL]); -- 2.11.4.GIT