Usermode/AxWin3 - Reworked widget minimum sizes, fixed bugs
authorJohn Hodge <[email protected]>
Fri, 18 Nov 2011 09:19:44 +0000 (17:19 +0800)
committerJohn Hodge <[email protected]>
Fri, 18 Nov 2011 09:19:44 +0000 (17:19 +0800)
Usermode/Applications/axwin3_src/Interface/main.c
Usermode/Applications/axwin3_src/WM/Makefile
Usermode/Applications/axwin3_src/WM/include/renderer_widget.h
Usermode/Applications/axwin3_src/WM/renderers/widget.c
Usermode/Applications/axwin3_src/WM/renderers/widget/colours.h
Usermode/Applications/axwin3_src/WM/renderers/widget/disptext.c
Usermode/Applications/axwin3_src/WM/renderers/widget/image.c
Usermode/Applications/axwin3_src/WM/renderers/widget/spacer.c [new file with mode: 0644]
Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c
Usermode/Applications/axwin3_src/WM/renderers/widget/widget_decorator.c
Usermode/Applications/axwin3_src/WM/wm.c

index a51984f..8764b8b 100644 (file)
@@ -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);
 }
 
index 60669b7..303e5c0 100644 (file)
@@ -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
 
index 15bba75..3cbed87 100644 (file)
@@ -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
index 68f81cb..f3de26f 100644 (file)
@@ -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);
index 7550022..d10e832 100644 (file)
@@ -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
index 590945f..dfdb358 100644 (file)
@@ -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);
 }
index 8a35764..c721454 100644 (file)
@@ -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 (file)
index 0000000..54f2029
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Acess2 Window Manager v3
+ * - By John Hodge (thePowersGang)
+ * 
+ * renderer/widget/spacer.
+ * - Horizontal / Verical Line
+ */
+#include <common.h>
+#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
+       );
+
+
index b2b68e0..abfb820 100644 (file)
@@ -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);
 
index 64671a2..6e9f933 100644 (file)
@@ -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
index dad3b6e..35a5308 100644 (file)
@@ -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);
 
        {

UCC git Repository :: git.ucc.asn.au