From e62ce4c06895976eeabd6f91803f5a4194ccc902 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 18 Nov 2011 17:19:44 +0800 Subject: [PATCH] Usermode/AxWin3 - Reworked widget minimum sizes, fixed bugs --- .../Applications/axwin3_src/Interface/main.c | 1 - Usermode/Applications/axwin3_src/WM/Makefile | 1 + .../axwin3_src/WM/include/renderer_widget.h | 4 +- .../axwin3_src/WM/renderers/widget.c | 119 ++++++++---------- .../axwin3_src/WM/renderers/widget/colours.h | 2 +- .../axwin3_src/WM/renderers/widget/disptext.c | 10 +- .../axwin3_src/WM/renderers/widget/image.c | 14 +-- .../axwin3_src/WM/renderers/widget/spacer.c | 53 ++++++++ .../WM/renderers/widget/textinput.c | 6 +- .../WM/renderers/widget/widget_decorator.c | 6 - Usermode/Applications/axwin3_src/WM/wm.c | 12 +- 11 files changed, 126 insertions(+), 102 deletions(-) create mode 100644 Usermode/Applications/axwin3_src/WM/renderers/widget/spacer.c diff --git a/Usermode/Applications/axwin3_src/Interface/main.c b/Usermode/Applications/axwin3_src/Interface/main.c index a51984f8..8764b8b5 100644 --- a/Usermode/Applications/axwin3_src/Interface/main.c +++ b/Usermode/Applications/axwin3_src/Interface/main.c @@ -103,7 +103,6 @@ void mainmenu_app_textedit(void *unused) void mainmenu_run_dialog(void *unused) { - _SysDebug("TODO: Show run dialog"); AxWin3_ShowWindow(gRunDialog, 1); } diff --git a/Usermode/Applications/axwin3_src/WM/Makefile b/Usermode/Applications/axwin3_src/WM/Makefile index 60669b77..303e5c02 100644 --- a/Usermode/Applications/axwin3_src/WM/Makefile +++ b/Usermode/Applications/axwin3_src/WM/Makefile @@ -18,6 +18,7 @@ OBJ += renderers/widget/button.o OBJ += renderers/widget/image.o OBJ += renderers/widget/disptext.o OBJ += renderers/widget/textinput.o +OBJ += renderers/widget/spacer.o LDFLAGS += -limage_sif -luri -lnet diff --git a/Usermode/Applications/axwin3_src/WM/include/renderer_widget.h b/Usermode/Applications/axwin3_src/WM/include/renderer_widget.h index 15bba75d..3cbed87f 100644 --- a/Usermode/Applications/axwin3_src/WM/include/renderer_widget.h +++ b/Usermode/Applications/axwin3_src/WM/include/renderer_widget.h @@ -48,8 +48,8 @@ struct sAxWin_Element // -- Attributes maitained by the element code // Not touched by the user - short MinWith; //!< Minimum long size - short MinCross; //!< Minimum cross size + short MinW; //!< Minimum long size + short MinH; //!< Minimum cross size void *Data; //!< Per-type data // -- Render Cache diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget.c b/Usermode/Applications/axwin3_src/WM/renderers/widget.c index 68f81cbf..f3de26f5 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget.c @@ -14,7 +14,7 @@ #include "widget/common.h" #define DEFAULT_ELETABLE_SIZE 64 -#define BORDER_EVERYTHING 1 +#define BORDER_EVERYTHING 0 // === PROTOTYPES === int Renderer_Widget_Init(void); @@ -161,6 +161,7 @@ void Widget_UpdateDimensions(tElement *Element) int maxCross = 0; int fixedSize = 0; int fullCross, dynWith = 0; + int bVertical = Element->Flags & ELEFLAG_VERTICAL; // Check if this element can have children if( (gaWM_WidgetTypes[Element->Type]->Flags & WIDGETTYPE_FLAG_NOCHILDREN) ) @@ -170,6 +171,9 @@ void Widget_UpdateDimensions(tElement *Element) // - Get the fixed and minimum sizes of the element for( child = Element->FirstChild; child; child = child->NextSibling ) { + int minWith = bVertical ? child->MinH : child->MinW; + int minCross = bVertical ? child->MinW : child->MinH; + // Ignore elements that will not be rendered if( child->Flags & ELEFLAG_NORENDER ) continue ; @@ -185,19 +189,17 @@ void Widget_UpdateDimensions(tElement *Element) else if( child->Flags & ELEFLAG_NOSTRETCH ) { nFixed ++; - fixedSize += child->MinWith; + fixedSize += minWith; } - if( child->FixedCross && maxCross < child->FixedCross ) - maxCross = child->FixedCross; - if( child->MinCross && maxCross < child->MinCross ) - maxCross = child->MinCross; + if( maxCross < child->FixedCross ) maxCross = child->FixedCross; + if( maxCross < minCross ) maxCross = minCross; nChildren ++; } // Get the dynamic with size from the unused space in the element if( nChildren > nFixed ) { - if( Element->Flags & ELEFLAG_VERTICAL ) + if( bVertical ) dynWith = Element->CachedH - Element->PaddingT - Element->PaddingB; else dynWith = Element->CachedW - Element->PaddingL - Element->PaddingR; @@ -211,7 +213,7 @@ void Widget_UpdateDimensions(tElement *Element) } // Get the cross size - if( Element->Flags & ELEFLAG_VERTICAL ) + if( bVertical ) fullCross = Element->CachedW - Element->PaddingL - Element->PaddingR; else fullCross = Element->CachedH - Element->PaddingT - Element->PaddingB; @@ -228,52 +230,39 @@ void Widget_UpdateDimensions(tElement *Element) // Pass 2 - Set sizes and recurse for( child = Element->FirstChild; child; child = child->NextSibling ) { - int cross, with; + int w, h; // Ignore elements that will not be rendered if( child->Flags & ELEFLAG_NORENDER ) continue ; // Don't resize floating elements if( child->Flags & ELEFLAG_ABSOLUTEPOS ) continue ; - // --- Cross Size --- - // TODO: Expand to fill? - // TODO: Extra flag so options are (Expand, Equal, Wrap) - if( child->FixedCross ) - cross = child->FixedCross; - else if( child->Flags & ELEFLAG_NOEXPAND ) - cross = child->MinCross; - else - cross = fullCross; - - // --- With Size --- - if( child->FixedWith ) - with = child->FixedWith; - else if( child->Flags & ELEFLAG_NOSTRETCH ) - with = child->MinWith; + // --- Width --- + if( child->Flags & ELEFLAG_NOEXPAND ) + w = child->MinW; + else if( bVertical ) + w = child->FixedCross ? child->FixedCross : fullCross; else - with = dynWith; + w = child->FixedWith ? child->FixedWith : dynWith; + // --- Height --- + if( child->Flags & ELEFLAG_NOSTRETCH ) + h = child->MinH; + else if( bVertical ) + h = child->FixedWith ? child->FixedWith : dynWith; + else + h = child->FixedCross ? child->FixedCross : fullCross; - if(with < child->MinWith) with = child->MinWith; - if(cross < child->MinCross) cross = child->MinCross; + if(w < child->MinW) w = child->MinW; + if(h < child->MinH) h = child->MinH; - _SysDebug("with = %i", with); + _SysDebug("Child %ix%i (min %ix%i)", w, h, child->MinW, child->MinH); // Update the dimensions if they have changed - if( Element->Flags & ELEFLAG_VERTICAL ) { - // If no change, don't recurse - if( child->CachedW == cross && child->CachedH == with ) - continue ; - child->CachedW = cross; - child->CachedH = with; - } - else { - // If no change, don't recurse - if( child->CachedW == with && child->CachedH == cross ) - continue ; - child->CachedW = with; - child->CachedH = cross; - } + if( child->CachedW == w && child->CachedH == h ) + continue ; + child->CachedW = w; + child->CachedH = h; // Force the positions of child elements to be recalculated child->CachedX = -1; @@ -359,48 +348,44 @@ void Widget_UpdateMinDims(tElement *Element) { tElement *child; int minW, minH; + int nChildren; if(!Element) return; minW = 0; minH = 0; + nChildren = 0; for(child = Element->FirstChild; child; child = child->NextSibling) { + int cross; + + if(Element->Flags & ELEFLAG_NORENDER) continue ; + if( (Element->Flags & ELEFLAG_VERTICAL) ) { - if(child->FixedCross) - minW += child->FixedCross; - else - minW += child->MinCross; - if(child->FixedWith) - minH += child->FixedWith; - else - minH += child->MinWith; + cross = child->FixedCross ? child->FixedCross : child->MinW; + if(minW < cross) minW = cross; + minH += child->FixedWith ? child->FixedWith : child->MinH; } else { - if(child->FixedCross) - minH += child->FixedCross; - else - minH += child->MinCross; - if(child->FixedWith) - minW += child->FixedWith; - else - minW += child->MinWith; + cross = child->FixedCross ? child->FixedCross : child->MinH; + minW += child->FixedWith ? child->FixedWith : child->MinW; + if(minH < cross) minH = cross; } - } +// _SysDebug("%i/%i cross = %i", Element->ID, child->ID, cross); - if( Element->Parent && (Element->Parent->Flags & ELEFLAG_VERTICAL) ) - { - Element->MinCross = Element->PaddingL + minW + Element->PaddingR; - Element->MinWith = Element->PaddingT + minH + Element->PaddingB; + nChildren ++; } + + if( Element->Flags & ELEFLAG_VERTICAL ) + minH += (nChildren - 1) * Element->GapSize; else - { - Element->MinWith = Element->PaddingL + minW + Element->PaddingR; - Element->MinCross = Element->PaddingL + minH + Element->PaddingR; - } + minW += (nChildren - 1) * Element->GapSize; + + Element->MinW = Element->PaddingL + minW + Element->PaddingR; + Element->MinH = Element->PaddingT + minH + Element->PaddingB; // Recurse upwards Widget_UpdateMinDims(Element->Parent); diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/colours.h b/Usermode/Applications/axwin3_src/WM/renderers/widget/colours.h index 75500223..d10e8324 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/colours.h +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/colours.h @@ -9,7 +9,7 @@ #define _RENDERER_WIDGET_COLOURS_H #define BOX_BGCOLOUR 0xC0C0C0 -#define BOX_BORDER 0xA0A0A0 +#define BOX_BORDER 0x202020 #define BUTTON_BGCOLOUR 0xD0D0D0 #define BUTTON_BORDER 0xF0F0F0 #define TEXT_COLOUR 0x000000 diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/disptext.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/disptext.c index 590945f5..dfdb3580 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/disptext.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/disptext.c @@ -33,14 +33,8 @@ void Widget_DispText_UpdateText(tElement *Element, const char *Text) // Apply edge padding w += 2; h += 2; - if(Element->Parent && (Element->Parent->Flags & ELEFLAG_VERTICAL)) { - Element->MinCross = w; - Element->MinWith = h; - } - else { - Element->MinWith = w; - Element->MinCross = h; - } + Element->MinW = w; + Element->MinH = h; Widget_UpdateMinDims(Element->Parent); } diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/image.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/image.c index 8a357642..c721454f 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/image.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/image.c @@ -31,19 +31,13 @@ void Widget_Image_UpdateText(tElement *Element, const char *Text) Element->CachedW = ((tImage*)Element->Data)->Width; Element->CachedH = ((tImage*)Element->Data)->Height; - - if(Element->Parent && (Element->Parent->Flags & ELEFLAG_VERTICAL) ) { - Element->MinCross = ((tImage*)Element->Data)->Width; - Element->MinWith = ((tImage*)Element->Data)->Height; - } - else { - Element->MinWith = ((tImage*)Element->Data)->Width; - Element->MinCross = ((tImage*)Element->Data)->Height; - } + Element->MinW = ((tImage*)Element->Data)->Width; + Element->MinH = ((tImage*)Element->Data)->Width; + Widget_UpdateMinDims(Element->Parent); - // NOTE: Doesn't update Element->Text because it's useless + // NOTE: Doesn't update Element->Text because it's not really needed here } DEFWIDGETTYPE(ELETYPE_IMAGE, diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/spacer.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/spacer.c new file mode 100644 index 00000000..54f20292 --- /dev/null +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/spacer.c @@ -0,0 +1,53 @@ +/* + * Acess2 Window Manager v3 + * - By John Hodge (thePowersGang) + * + * renderer/widget/spacer. + * - Horizontal / Verical Line + */ +#include +#include "./common.h" +#include "./colours.h" + +#define SPACER_RULE_SIZE 3 +#define SPACER_RULE_OFFSET 1 + +void Widget_Spacer_Render(tWindow *Window, tElement *Element) +{ +// _SysDebug("Spacer at (%i,%i) %ix%i", +// Element->CachedX, Element->CachedY, +// Element->CachedW, Element->CachedH +// ); + if( Element->Parent && (Element->Parent->Flags & ELEFLAG_VERTICAL) ) + { + WM_Render_DrawRect( + Window, + Element->CachedX+1, Element->CachedY+1, + Element->CachedW-2, SPACER_RULE_SIZE, + BOX_BORDER + ); + } + else + { + WM_Render_DrawRect( + Window, + Element->CachedX+1, Element->CachedY+1, + SPACER_RULE_SIZE, Element->CachedH-2, + BOX_BORDER + ); + } +} + +void Widget_Spacer_Init(tElement *Element) +{ + Element->MinH = SPACER_RULE_SIZE+1; + Element->MinW = SPACER_RULE_SIZE+1; +} + +DEFWIDGETTYPE(ELETYPE_SPACER, + WIDGETTYPE_FLAG_NOCHILDREN, + .Render = Widget_Spacer_Render, + .Init = Widget_Spacer_Init + ); + + diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c index b2b68e04..abfb8206 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c @@ -41,10 +41,8 @@ void Widget_TextInput_Init(tElement *Element) h += 2+2; // Border padding - if( Element->Parent && (Element->Parent->Flags & ELEFLAG_VERTICAL) ) - Element->MinWith = h; - else - Element->MinCross = h; + Element->MinH = h; + Element->MinW = 4; _SysDebug("h = %i", h); diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/widget_decorator.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/widget_decorator.c index 64671a28..6e9f9336 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/widget_decorator.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/widget_decorator.c @@ -56,12 +56,6 @@ void Widget_Decorator_RenderWidget(tWindow *Window, tElement *Element) break; case ELETYPE_SPACER: // Spacer (subtle line) - WM_Render_FillRect( - Window, - Element->CachedX+3, Element->CachedY+3, - Element->CachedW-6, Element->CachedH-6, - BOX_BORDER - ); break; case ELETYPE_BUTTON: // Button diff --git a/Usermode/Applications/axwin3_src/WM/wm.c b/Usermode/Applications/axwin3_src/WM/wm.c index dad3b6eb..35a53084 100644 --- a/Usermode/Applications/axwin3_src/WM/wm.c +++ b/Usermode/Applications/axwin3_src/WM/wm.c @@ -170,8 +170,10 @@ void WM_ShowWindow(tWindow *Window, int bShow) WM_FocusWindow(Window->Parent); } // Just a little memory saving for large hidden windows - if(Window->RenderBuffer) + if(Window->RenderBuffer) { free(Window->RenderBuffer); + Window->RenderBuffer = NULL; + } WM_Invalidate(Window); } @@ -187,8 +189,10 @@ void WM_DecorateWindow(tWindow *Window, int bDecorate) Window->Flags |= WINFLAG_NODECORATE; // Needed because the window size changes - if(Window->RenderBuffer) + if(Window->RenderBuffer) { free(Window->RenderBuffer); + Window->RenderBuffer = NULL; + } WM_Invalidate(Window); } @@ -216,8 +220,10 @@ int WM_ResizeWindow(tWindow *Window, int W, int H) Window->W = W; Window->H = H; - if(Window->RenderBuffer) + if(Window->RenderBuffer) { free(Window->RenderBuffer); + Window->RenderBuffer = NULL; + } WM_Invalidate(Window); { -- 2.20.1