Merge branch 'master' of git://git.ucc.asn.au/tpg/acess2
[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         WM_Render_FillRect(Window,
68                 0, -ciTitlebarHeight, Window->W, ciTitlebarHeight,
69                 (bActive ? cColourActive_Titlebar : cColourInactive_Titlebar)
70                 );
71         WM_Render_FillRect(Window,
72                 0, -ciTitlebarHeight, Window->W, 1,
73                 cColour_TitleTopBorder
74                 );
75         WM_Render_FillRect(Window,
76                 0, -ciTitlebarHeight, 1, ciTitlebarHeight,
77                 cColour_SideBorder
78                 );
79         WM_Render_FillRect(Window,
80                 Window->W, -ciTitlebarHeight, 1, ciTitlebarHeight,
81                 cColour_SideBorder
82                 );
83
84         WM_Render_GetTextDims(
85                 NULL,   // TODO: Select font
86                 Window->Title ? Window->Title : "jI", -1,
87                 &text_width, &text_height
88                 );
89         WM_Render_DrawText(Window,
90                 ciTitlebarHeight + 4, -(ciTitlebarHeight - (ciTitlebarHeight/2 - text_height/2)),
91                 Window->W - ciTitlebarHeight - 4, text_height,
92                 NULL,   // TODO: Select font
93                 (bActive ? cColourActive_TitleText : cColourInactive_TitleText),
94                 Window->Title ? Window->Title : "--", -1
95                 );
96         
97         // Maximized windows don't have any other borders
98         if( Window->Flags & WINFLAG_MAXIMIZED )
99                 return ;
100         
101         // Left
102         WM_Render_FillRect(Window,
103                 -ciSideBorderWidth, -ciTitlebarHeight,
104                 ciSideBorderWidth, Window->H + ciTitlebarHeight + ciBottomBorderWidth,
105                 cColour_SideBorder
106                 );
107         // Right
108         WM_Render_FillRect(Window,
109                 Window->W, -ciTitlebarHeight,
110                 ciSideBorderWidth, Window->H + ciTitlebarHeight + ciBottomBorderWidth,
111                 cColour_SideBorder
112                 );
113         // Bottom
114         WM_Render_FillRect(Window,
115                 -ciSideBorderWidth, Window->H,
116                 ciSideBorderWidth*2+Window->W, 1,
117                 0x000000
118                 );
119         WM_Render_FillRect(Window,
120                 -ciSideBorderWidth, Window->H+1,
121                 ciSideBorderWidth*2+Window->W, ciBottomBorderWidth-1,
122                 cColour_BottomBorder
123                 );
124 }
125
126 int Decorator_HandleMessage(tWindow *Window, int Message, int Length, const void *Data)
127 {
128         switch(Message)
129         {
130         case WNDMSG_MOUSEMOVE: {
131                 const struct sWndMsg_MouseMove  *msg = Data;
132                 if(msg->Y >= 0) return 1;       // Pass
133                 
134                 // TODO: Handle
135                 return 0; }
136         case WNDMSG_MOUSEBTN: {
137                 const struct sWndMsg_MouseButton        *msg = Data;
138                 if(msg->Y >= 0) return 1;       // Pass
139                 
140                 // TODO: Handle
141                 return 0; }
142         default:        // Anything unhandled is passed on
143                 return 1;
144         }
145 }
146

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