Usermode/axwin3 - Commenting
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / decorator.c
1 /*
2  * Acess2 Window Manager v3 (axwin3)
3  * - By John Hodge (thePowersGang)
4  *
5  * decorator.c
6  * - Window Decorator
7  */
8 #include <common.h>
9 #include <wm.h>
10 #include <decorator.h>
11 #include <wm_messages.h>
12
13 // === IMPORTS ===
14 extern tWindow  *gpWM_FocusedWindow;
15
16 // === PROTOTYPES ===
17 void    Decorator_UpdateBorderSize(tWindow *Window);
18 void    Decorator_Redraw(tWindow *Window);
19  int    Decorator_HandleMessage(tWindow *Window, int Message, int Length, const void *Data);
20
21 // === CONSTANTS ===
22 tColour cColourActive_Titlebar   = 0x00CC44;
23 tColour cColourActive_TitleText  = 0x000000;
24 tColour cColourInactive_Titlebar = 0xD0D0D0;
25 tColour cColourInactive_TitleText= 0x000000;
26 tColour cColour_TitleTopBorder   = 0xFFFFFF;
27 tColour cColour_SideBorder       = 0x008000;
28 tColour cColour_BottomBorder     = 0x008000;
29  int    ciTitlebarHeight        = 18;
30  int    ciSideBorderWidth       = 2;
31  int    ciBottomBorderWidth     = 4;
32
33 // === CODE ===
34 void Decorator_UpdateBorderSize(tWindow *Window)
35 {
36         Window->BorderT = ciTitlebarHeight;
37         Window->BorderB = 0;
38         Window->BorderL = 0;
39         Window->BorderR = 0;
40         
41         if( Window->Flags & WINFLAG_MAXIMIZED )
42                 return ;
43
44         Window->BorderB = ciBottomBorderWidth;
45         Window->BorderR = ciSideBorderWidth;
46         Window->BorderL = ciSideBorderWidth;
47 }
48
49 void Decorator_Redraw(tWindow *Window)
50 {
51          int    bActive = 0;
52          int    text_width, text_height;
53         
54         // TODO: This could possibly be expensive, but is there a better way?
55         {
56                 tWindow *win;
57                 for(win = gpWM_FocusedWindow; win; win = win->Owner)
58                 {
59                         if(win == Window) {
60                                 bActive = 1;
61                                 break;
62                         }
63                 }
64         }
65
66         // Draw title bar
67         // - Body
68         WM_Render_FillRect(Window,
69                 0, -ciTitlebarHeight, Window->W, ciTitlebarHeight,
70                 (bActive ? cColourActive_Titlebar : cColourInactive_Titlebar)
71                 );
72         // - Top Border
73         WM_Render_FillRect(Window,
74                 0, -ciTitlebarHeight, Window->W, 1,
75                 cColour_TitleTopBorder
76                 );
77         // - Sides
78         WM_Render_FillRect(Window,
79                 0, -ciTitlebarHeight, 1, ciTitlebarHeight,
80                 cColour_SideBorder
81                 );
82         WM_Render_FillRect(Window,
83                 Window->W, -ciTitlebarHeight, 1, ciTitlebarHeight,
84                 cColour_SideBorder
85                 );
86
87         // Get the font height
88         WM_Render_GetTextDims(
89                 NULL,   // TODO: Select font
90                 Window->Title ? Window->Title : "jI", -1,
91                 &text_width, &text_height
92                 );
93         // - Use that to draw the window title on the left of the window
94         WM_Render_DrawText(Window,
95                 ciTitlebarHeight + 4, -(ciTitlebarHeight - (ciTitlebarHeight/2 - text_height/2)),
96                 Window->W - ciTitlebarHeight - 4, text_height,
97                 NULL,   // TODO: Select font
98                 (bActive ? cColourActive_TitleText : cColourInactive_TitleText),
99                 Window->Title ? Window->Title : "--", -1
100                 );
101
102         // TODO: Minimise, Maximise and Close   
103
104         // Maximized windows don't have any other borders
105         if( Window->Flags & WINFLAG_MAXIMIZED )
106                 return ;
107         
108         // Left Border
109         WM_Render_FillRect(Window,
110                 -ciSideBorderWidth, -ciTitlebarHeight,
111                 ciSideBorderWidth, Window->H + ciTitlebarHeight + ciBottomBorderWidth,
112                 cColour_SideBorder
113                 );
114         // Right Border
115         WM_Render_FillRect(Window,
116                 Window->W, -ciTitlebarHeight,
117                 ciSideBorderWidth, Window->H + ciTitlebarHeight + ciBottomBorderWidth,
118                 cColour_SideBorder
119                 );
120         // Bottom Border (hard line)
121         WM_Render_FillRect(Window,
122                 -ciSideBorderWidth, Window->H,
123                 ciSideBorderWidth*2+Window->W, 1,
124                 0x000000
125                 );
126         // Bottom Border
127         WM_Render_FillRect(Window,
128                 -ciSideBorderWidth, Window->H+1,
129                 ciSideBorderWidth*2+Window->W, ciBottomBorderWidth-1,
130                 cColour_BottomBorder
131                 );
132 }
133
134 int Decorator_HandleMessage(tWindow *Window, int Message, int Length, const void *Data)
135 {
136         switch(Message)
137         {
138         case WNDMSG_MOUSEMOVE: {
139                 const struct sWndMsg_MouseMove  *msg = Data;
140                 if(msg->Y >= 0) return 1;       // Pass
141                 
142                 // TODO: Handle
143                 return 0; }
144         case WNDMSG_MOUSEBTN: {
145                 const struct sWndMsg_MouseButton        *msg = Data;
146                 if(msg->Y >= 0) return 1;       // Pass
147                 
148                 // TODO: Handle
149                 return 0; }
150         default:        // Anything unhandled is passed on
151                 return 1;
152         }
153 }
154

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