2 * Acess2 Window Manager v3
3 * - By John Hodge (thePowersGang)
6 * - Window manager core
9 #include <wm_renderer.h>
13 #include <wm_messages.h>
16 tWMRenderer *gpWM_Renderers;
17 tWindow *gpWM_RootWindow;
20 void WM_Initialise(void)
22 WM_CreateWindow(NULL, 0x0088FF, "Background");
23 gpWM_RootWindow->W = giScreenWidth;
24 gpWM_RootWindow->H = giScreenHeight;
25 gpWM_RootWindow->Flags = WINFLAG_SHOW;
28 void WM_RegisterRenderer(tWMRenderer *Renderer)
30 // TODO: Catch out duplicates
31 Renderer->Next = gpWM_Renderers;
32 gpWM_Renderers = Renderer;
36 tWindow *WM_CreateWindow(tWindow *Parent, int RendererArg, const char *RendererName)
38 tWMRenderer *renderer;
42 for( renderer = gpWM_Renderers; renderer; renderer = renderer->Next )
44 if(strcmp(RendererName, renderer->Name) == 0)
51 Parent = gpWM_RootWindow;
53 // - Call create window function
54 ret = renderer->CreateWindow(RendererArg);
56 ret->Renderer = renderer;
57 ret->Flags = WINFLAG_CLEAN; // Needed to stop invaildate early exiting
63 Parent->LastChild->NextSibling = ret;
65 Parent->FirstChild = ret;
66 ret->PrevSibling = Parent->LastChild;
67 Parent->LastChild = ret;
71 gpWM_RootWindow = ret;
78 tWindow *WM_CreateWindowStruct(size_t ExtraSize)
82 ret = calloc( sizeof(tWindow) + ExtraSize, 1 );
83 ret->RendererInfo = ret + 1; // Get end of tWindow
88 void WM_ShowWindow(tWindow *Window, int bShow)
90 // TODO: Message window
92 Window->Flags |= WINFLAG_SHOW;
94 Window->Flags &= ~WINFLAG_SHOW;
95 WM_Invalidate(Window);
98 int WM_MoveWindow(tWindow *Window, int X, int Y)
101 if(X + Window->W < 0) X = -Window->W + 1;
102 if(Y + Window->H < 0) Y = -Window->H + 1;
103 if(X >= giScreenWidth) X = giScreenWidth - 1;
104 if(Y >= giScreenHeight) Y = giScreenHeight - 1;
106 Window->X = X; Window->Y = Y;
108 WM_Invalidate(Window);
113 int WM_ResizeWindow(tWindow *Window, int W, int H)
115 if(W <= 0 || H <= 0 ) return 1;
116 if(Window->X + W < 0) Window->X = -W + 1;
117 if(Window->Y + H < 0) Window->Y = -H + 1;
119 Window->W = W; Window->H = H;
121 WM_Invalidate(Window);
124 struct sWndMsg_Resize msg;
127 WM_SendMessage(NULL, Window, WNDMSG_RESIZE, sizeof(msg), &msg);
133 int WM_SendMessage(tWindow *Source, tWindow *Dest, int Message, int Length, void *Data)
135 if(Dest == NULL) return -2;
136 if(Length > 0 && Data == NULL) return -1;
138 // ->HandleMessage returns 1 when the message was not handled
139 if( Dest->Renderer->HandleMessage(Dest, Message, Length, Data) != 1 )
141 // TODO: Catch errors from ->HandleMessage
145 // TODO: Pass on to user
146 _SysDebug("WM_SendMessage: TODO - Implement sending to client application");
151 void WM_Invalidate(tWindow *Window)
153 // Don't invalidate twice (speedup)
154 if( !(Window->Flags & WINFLAG_CLEAN) ) return;
156 // _SysDebug("Invalidating %p");
158 // Mark for re-render
159 Window->Flags &= ~WINFLAG_CLEAN;
161 // Mark up the tree that a child window has changed
162 while( (Window = Window->Parent) )
164 // _SysDebug("Childclean removed from %p", Window);
165 Window->Flags &= ~WINFLAG_CHILDCLEAN;
169 // --- Rendering / Update
170 void WM_int_UpdateWindow(tWindow *Window)
174 // Ignore hidden windows
175 if( !(Window->Flags & WINFLAG_SHOW) )
179 if( !(Window->Flags & WINFLAG_CLEAN) )
181 Window->Renderer->Redraw(Window);
182 Window->Flags |= WINFLAG_CLEAN;
186 if( !(Window->Flags & WINFLAG_CHILDCLEAN) )
188 for( child = Window->FirstChild; child; child = child->NextSibling )
190 WM_int_UpdateWindow(child);
192 Window->Flags |= WINFLAG_CHILDCLEAN;
197 void WM_int_BlitWindow(tWindow *Window)
201 // Ignore hidden windows
202 if( !(Window->Flags & WINFLAG_SHOW) )
205 Video_Blit(Window->RenderBuffer, Window->X, Window->Y, Window->W, Window->H);
207 for( child = Window->FirstChild; child; child = child->NextSibling )
209 WM_int_BlitWindow(child);
215 // Don't redraw if nothing has changed
216 if( (gpWM_RootWindow->Flags & WINFLAG_CHILDCLEAN) )
219 // - Iterate through visible windows, updating them as needed
220 WM_int_UpdateWindow(gpWM_RootWindow);
222 // - Draw windows from back to front to the render buffer
223 WM_int_BlitWindow(gpWM_RootWindow);