From: John Hodge Date: Sat, 5 Nov 2011 03:13:00 +0000 (+0800) Subject: Usermode/AxWin3 - Implementing widget support in userland X-Git-Tag: rel0.14~148 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=d4f7058c6c83d0088efa6872a6746ecb0748c018;p=tpg%2Facess2.git Usermode/AxWin3 - Implementing widget support in userland - Also working on render/WM_Update process --- diff --git a/Usermode/Applications/axwin3_src/WM/Makefile b/Usermode/Applications/axwin3_src/WM/Makefile index 83e93234..5afff6f0 100644 --- a/Usermode/Applications/axwin3_src/WM/Makefile +++ b/Usermode/Applications/axwin3_src/WM/Makefile @@ -8,7 +8,7 @@ DIR := Apps/AxWin/3.0 BIN := AxWinWM OBJ := main.o wm.o input.o video.o ipc.o OBJ += messageio.o -OBJ += renderer_classes.o renderer_passthru.o renderer_widget.o +OBJ += renderer_classes.o renderer_passthru.o renderer_widget.o renderer_background.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 680fb4f6..fd79acf5 100644 --- a/Usermode/Applications/axwin3_src/WM/include/renderer_widget.h +++ b/Usermode/Applications/axwin3_src/WM/include/renderer_widget.h @@ -9,6 +9,7 @@ #define _RENDERER_WIDGET_H_ #include +#include enum { @@ -17,91 +18,6 @@ enum MSG_WIDGET_SETTEXT }; -enum eElementTypes -{ - ELETYPE_NONE, - - ELETYPE_WINDOW, //!< Window root element - - ELETYPE_BOX, //!< Content box (invisible in itself) - ELETYPE_TABBAR, //!< Tab Bar - ELETYPE_TOOLBAR, //!< Tool Bar - - ELETYPE_BUTTON, //!< Push Button - - ELETYPE_TEXT, //!< Text - ELETYPE_IMAGE, //!< Image - - ELETYPE_SPACER, //!< Visual Spacer (horizontal / vertical rule) - - MAX_ELETYPES = 0x100 -}; - -enum eElementFlags -{ - /** - * \brief Rendered - * - * If set, the element will be ignored in calculating sizes and - * rendering. - */ - ELEFLAG_NORENDER = 0x001, - /** - * \brief Element visibility - * - * If set, the element is not drawn (but still is used for size calculations) - */ - ELEFLAG_INVISIBLE = 0x002, - - /** - * \brief Position an element absulutely (ignored in size calcs) - */ - ELEFLAG_ABSOLUTEPOS = 0x004, - - /** - * \brief Fixed size element - */ - ELEFLAG_FIXEDSIZE = 0x008, - - /** - * \brief Element "orientation" - * - * Vertical means that the children of this element are stacked, - * otherwise they list horizontally - */ - ELEFLAG_VERTICAL = 0x010,// ELEFLAG_HORIZONTAL = 0x000, - /** - * \brief Action for text that overflows - */ - ELEFLAG_WRAP = 0x020,// ELEFLAG_NOWRAP = 0x000, - /** - * \brief Cross size action - * - * If this flag is set, the element will only be as large (across - * its parent) as is needed to encase the contents of the element. - * Otherwise, the element will expand to fill all avaliable space. - */ - ELEFLAG_NOEXPAND = 0x040, - - /** - * \brief With (length) size action - * If this flag is set, the element will only be as large as - * is required along it's parent - */ - ELEFLAG_NOSTRETCH = 0x080, - - /** - * \brief Center alignment - */ - ELEFLAG_ALIGN_CENTER= 0x100, - /** - * \brief Right/Bottom alignment - * - * If set, the element aligns to the end of avaliable space (instead - * of the beginning) - */ - ELEFLAG_ALIGN_END = 0x200 -}; typedef struct { diff --git a/Usermode/Applications/axwin3_src/WM/include/wm.h b/Usermode/Applications/axwin3_src/WM/include/wm.h index a5a779fc..75292b55 100644 --- a/Usermode/Applications/axwin3_src/WM/include/wm.h +++ b/Usermode/Applications/axwin3_src/WM/include/wm.h @@ -13,7 +13,11 @@ * \brief Window Flags * \{ */ +//! Render the window #define WINFLAG_SHOW 0x00000001 +//! Window contents are valid +#define WINFLAG_CLEAN 0x00000001 + #define WINFLAG_RENDER_MASK 0x00FFFF00 #define WINFLAG_USR_MASK 0xFF000000 /** diff --git a/Usermode/Applications/axwin3_src/WM/include/wm_internals.h b/Usermode/Applications/axwin3_src/WM/include/wm_internals.h index 51c43f33..aada7203 100644 --- a/Usermode/Applications/axwin3_src/WM/include/wm_internals.h +++ b/Usermode/Applications/axwin3_src/WM/include/wm_internals.h @@ -12,8 +12,10 @@ struct sWindow { - tWindow *GlobalNext; - tWindow *RenderNext; + tWindow *NextSibling; + tWindow *PrevSibling; + + tWindow *Parent; tWindow *FirstChild; tWindow *LastChild; diff --git a/Usermode/Applications/axwin3_src/WM/renderer_background.c b/Usermode/Applications/axwin3_src/WM/renderer_background.c new file mode 100644 index 00000000..d17cf9d6 --- /dev/null +++ b/Usermode/Applications/axwin3_src/WM/renderer_background.c @@ -0,0 +1,71 @@ +/* + * Acess2 Window Manager v3 + * - By John Hodge (thePowersGang) + * + * render_widget.c + * - AxWin2 Background port + */ +#include +#include + +// === TYPES === + +// === STRUCTURES === +struct sBgWin +{ + uint32_t Colour; +}; + +// === PROTOTYPES === +tWindow *Renderer_Background_Create(int Flags); +void Renderer_Background_Redraw(tWindow *Window); +int Renderer_Background_HandleMessage(tWindow *Target, int Msg, int Len, void *Data); + +// === GLOBALS === +tWMRenderer gRenderer_Background = { + .Name = "Background", + .CreateWindow = Renderer_Background_Create, + .Redraw = Renderer_Background_Redraw, + .HandleMessage = Renderer_Background_HandleMessage +}; + +// === CODE === +int Renderer_Background_Init(void) +{ + WM_RegisterRenderer(&gRenderer_Background); + + return 0; +} + +tWindow *Renderer_Background_Create(int Arg) +{ + tWindow *ret; + ret = WM_CreateWindowStruct( sizeof(struct sBgWin) ); + + ((struct sBgWin*)ret->RendererInfo)->Colour = Arg; + + return ret; +} + +void Renderer_Background_Redraw(tWindow *Window) +{ + struct sBgWin *info = Window->RendererInfo; + + WM_Render_FilledRect(Window, 0, 0, 0xFFFF, 0xFFFF, info->Colour); +} + +int Renderer_Background_HandleMessage(tWindow *Target, int Msg, int Len, void *Data) +{ + switch(Msg) + { + // TODO: Handle resize + + default: + break; + } + return 0; +} + + + + diff --git a/Usermode/Applications/axwin3_src/WM/wm.c b/Usermode/Applications/axwin3_src/WM/wm.c index a30c470b..74e458ac 100644 --- a/Usermode/Applications/axwin3_src/WM/wm.c +++ b/Usermode/Applications/axwin3_src/WM/wm.c @@ -12,8 +12,15 @@ // === GLOBALS === tWMRenderer *gpWM_Renderers; +// - Render order list (gpWM_FirstWindow is rendered first) +tWindow *gpWM_RootWindow; // === CODE === +void WM_Initialise(void) +{ + WM_CreateWindow(NULL, 0x8888FF, "Background"); +} + void WM_RegisterRenderer(tWMRenderer *Renderer) { // TODO: Catch out duplicates @@ -37,7 +44,26 @@ tWindow *WM_CreateWindow(tWindow *Parent, int RendererArg, const char *RendererN // - Call create window function ret = renderer->CreateWindow(RendererArg); - + ret->Parent = Parent; + + if(!Parent) + Parent = gpWM_RootWindow; + + // Append to parent + if(Parent) + { + if(Parent->LastChild) + Parent->LastChild->NextSibling = ret; + else + Parent->FirstChild = ret; + ret->PrevSibling = Parent->LastChild; + Parent->LastChild = ret; + } + else + { + gpWM_RootWindow = ret; + } + // - Return! return ret; } @@ -47,6 +73,29 @@ tWindow *WM_CreateWindowStruct(size_t ExtraSize) return calloc( sizeof(tWindow) + ExtraSize, 1 ); } +void WM_int_UpdateWindow(tWindow *Window) +{ + tWindow *child; + + // Ignore hidden windows + if( !(Window->Flags & WINFLAG_SHOW) ) + return ; + // Ignore unchanged windows + if( Window->Flags & WINFLAG_CLEAN ) + return; + + // Render + Window->Renderer->Redraw(Window); + + // Process children + for( child = Window->FirstChild; child; child = child->NextSibling ) + { + WM_int_UpdateWindow(child); + } + + Window->Flags |= WINFLAG_CLEAN; +} + void WM_Update(void) { // - Iterate through visible windows, updating them as needed diff --git a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c index 64d2023b..64c15b33 100644 --- a/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c +++ b/Usermode/Applications/axwin3_src/libaxwin3.so_src/r_widget.c @@ -10,8 +10,16 @@ #include "include/internal.h" // === STRUCTURES === +struct sAxWin3_Widget +{ + tHWND Window; + tAxWin3_Widget_Callback Callback; +}; + typedef struct { + int nElements; + tAxWin3_Widget **Elements; // Callbacks for each element } tWidgetWindowInfo; diff --git a/Usermode/include/axwin3/axwin.h b/Usermode/include/axwin3/axwin.h index 49fc4df3..b4ad45a4 100644 --- a/Usermode/include/axwin3/axwin.h +++ b/Usermode/include/axwin3/axwin.h @@ -9,6 +9,7 @@ #define _AXWIN3_AXWIN_H_ typedef struct sAxWin3_Window *tHWND; +typedef unsigned int tAxWin3_Colour; // TODO: Actual 32-bit typedef void (*tAxWin3_MessageCallback)(int SourceTID, int Length); diff --git a/Usermode/include/axwin3/widget.h b/Usermode/include/axwin3/widget.h index 5542e3a8..4fef39ce 100644 --- a/Usermode/include/axwin3/widget.h +++ b/Usermode/include/axwin3/widget.h @@ -10,7 +10,107 @@ #include "axwin.h" +typedef struct sAxWin3_Widget tAxWin3_Widget; + +typedef int (*tAxWin3_Widget_Callback)(tAxWin3_Widget Widget, int EventType, unsigned long EventArg); + extern tHWND AxWin3_Widget_CreateWindow(tHWND Parent, int W, int H, int RootEleFlags); +extern void AxWin3_Widget_DestroyWindow(tHWND Window); +extern tAxWin3_Widget *AxWin3_WidgeT_GetRoot(tHWND Window); + +extern tAxWin3_Widget *AxWin3_Widget_AddWidget(tAxWin3_Widget *Parent, int Type, int Flags, const char *DebugName); +extern void AxWin3_Widget_DelWidget(tAxWin3_Widget *Widget); + +extern void AxWin3_Widget_SetSize(tAxWin3_Widget *Widget, int Size); +extern void AxWin3_Widget_SetText(tAxWin3_Widget *Widget, const char *Text); +extern void AxWin3_Widget_SetColour(tAxWin3_Widget *Widget, int Index, tAxWin3_Colour Colour); + +enum eElementTypes +{ + ELETYPE_NONE, + + ELETYPE_WINDOW, //!< Window root element + + ELETYPE_BOX, //!< Content box (invisible in itself) + ELETYPE_TABBAR, //!< Tab Bar + ELETYPE_TOOLBAR, //!< Tool Bar + + ELETYPE_BUTTON, //!< Push Button + + ELETYPE_TEXT, //!< Text + ELETYPE_IMAGE, //!< Image + + ELETYPE_SPACER, //!< Visual Spacer (horizontal / vertical rule) + + MAX_ELETYPES = 0x100 +}; + +enum eElementFlags +{ + /** + * \brief Rendered + * + * If set, the element will be ignored in calculating sizes and + * rendering. + */ + ELEFLAG_NORENDER = 0x001, + /** + * \brief Element visibility + * + * If set, the element is not drawn (but still is used for size calculations) + */ + ELEFLAG_INVISIBLE = 0x002, + + /** + * \brief Position an element absulutely (ignored in size calcs) + */ + ELEFLAG_ABSOLUTEPOS = 0x004, + + /** + * \brief Fixed size element + */ + ELEFLAG_FIXEDSIZE = 0x008, + + /** + * \brief Element "orientation" + * + * Vertical means that the children of this element are stacked, + * otherwise they list horizontally + */ + ELEFLAG_VERTICAL = 0x010,// ELEFLAG_HORIZONTAL = 0x000, + /** + * \brief Action for text that overflows + */ + ELEFLAG_WRAP = 0x020,// ELEFLAG_NOWRAP = 0x000, + /** + * \brief Cross size action + * + * If this flag is set, the element will only be as large (across + * its parent) as is needed to encase the contents of the element. + * Otherwise, the element will expand to fill all avaliable space. + */ + ELEFLAG_NOEXPAND = 0x040, + + /** + * \brief With (length) size action + * If this flag is set, the element will only be as large as + * is required along it's parent + */ + ELEFLAG_NOSTRETCH = 0x080, + + /** + * \brief Center alignment + */ + ELEFLAG_ALIGN_CENTER= 0x100, + /** + * \brief Right/Bottom alignment + * + * If set, the element aligns to the end of avaliable space (instead + * of the beginning) + */ + ELEFLAG_ALIGN_END = 0x200 +}; + #endif