74e458ac99af4566179cff4d17fdfc3481837d9d
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / wm.c
1 /*
2  * Acess2 Window Manager v3
3  * - By John Hodge (thePowersGang)
4  *
5  * wm.c
6  * - Window manager core
7  */
8 #include <common.h>
9 #include <wm_renderer.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 // === GLOBALS ===
14 tWMRenderer     *gpWM_Renderers;
15 // - Render order list (gpWM_FirstWindow is rendered first)
16 tWindow *gpWM_RootWindow;
17
18 // === CODE ===
19 void WM_Initialise(void)
20 {
21         WM_CreateWindow(NULL, 0x8888FF, "Background");
22 }
23
24 void WM_RegisterRenderer(tWMRenderer *Renderer)
25 {
26         // TODO: Catch out duplicates
27         Renderer->Next = gpWM_Renderers;
28         gpWM_Renderers = Renderer;
29 }
30
31 tWindow *WM_CreateWindow(tWindow *Parent, int RendererArg, const char *RendererName)
32 {
33         tWMRenderer     *renderer;
34         tWindow *ret;
35         
36         // - Get Renderer
37         for( renderer = gpWM_Renderers; renderer; renderer = renderer->Next )
38         {
39                 if(strcmp(RendererName, renderer->Name) == 0)
40                         break;
41         }
42         if(renderer == NULL)
43                 return NULL;
44
45         // - Call create window function
46         ret = renderer->CreateWindow(RendererArg);
47         ret->Parent = Parent;
48
49         if(!Parent)
50                 Parent = gpWM_RootWindow;
51
52         // Append to parent
53         if(Parent)
54         {
55                 if(Parent->LastChild)
56                         Parent->LastChild->NextSibling = ret;
57                 else
58                         Parent->FirstChild = ret;
59                 ret->PrevSibling = Parent->LastChild;
60                 Parent->LastChild = ret;
61         }
62         else
63         {
64                 gpWM_RootWindow = ret;
65         }
66
67         // - Return!
68         return ret;
69 }
70
71 tWindow *WM_CreateWindowStruct(size_t ExtraSize)
72 {
73         return calloc( sizeof(tWindow) + ExtraSize, 1 );
74 }
75
76 void WM_int_UpdateWindow(tWindow *Window)
77 {
78         tWindow *child;
79
80         // Ignore hidden windows
81         if( !(Window->Flags & WINFLAG_SHOW) )
82                 return ;
83         // Ignore unchanged windows
84         if( Window->Flags & WINFLAG_CLEAN )
85                 return;
86
87         // Render
88         Window->Renderer->Redraw(Window);
89         
90         // Process children
91         for( child = Window->FirstChild; child; child = child->NextSibling )
92         {
93                 WM_int_UpdateWindow(child);
94         }
95         
96         Window->Flags |= WINFLAG_CLEAN;
97 }
98
99 void WM_Update(void)
100 {
101         // - Iterate through visible windows, updating them as needed
102         
103         // - Draw windows from back to front to the render buffer
104         
105         // - Blit the buffer to the screen
106 }
107
108 void WM_Render_FilledRect(tWindow *Window, tColour Colour, int X, int Y, int W, int H)
109 {
110         // Clip to window dimensions
111         if(X < 0) { W += X; X = 0; }
112         if(Y < 0) { H += Y; Y = 0; }
113         if(X >= Window->W)      return;
114         if(Y >= Window->H)      return;
115         if(X + W > Window->W)   W = Window->W - X;
116         if(Y + H > Window->H)   H = Window->H - Y;
117
118         // Render to buffer
119         // Create if needed?
120
121         UNIMPLEMENTED();
122 }
123

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