Usermode/AxWin3 - Bugfixing rendering/layout issues
[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 // === PROTOTYPES ===
14 void    Decorator_UpdateBorderSize(tWindow *Window);
15 void    Decorator_Redraw(tWindow *Window);
16  int    Decorator_HandleMessage(tWindow *Window, int Message, int Length, const void *Data);
17
18 // === CONSTANTS ===
19 tColour cColourActive_Titlebar   = 0xFF8800;
20 tColour cColourActive_TitleText  = 0x000000;
21 tColour cColourInactive_Titlebar = 0xD0D0D0;
22 tColour cColourInactive_TitleText= 0x000000;
23 tColour cColour_TitleTopBorder   = 0xFFFFFF;
24 tColour cColour_SideBorder       = 0xD0D0D0;
25 tColour cColour_BottomBorder     = 0xD0D0D0;
26  int    ciTitlebarHeight        = 18;
27  int    ciSideBorderWidth       = 2;
28  int    ciBottomBorderWidth     = 4;
29
30 // === CODE ===
31 void Decorator_UpdateBorderSize(tWindow *Window)
32 {
33         Window->BorderT = 0;
34         Window->BorderB = 0;
35         Window->BorderL = 0;
36         Window->BorderR = 0;
37         
38         Window->BorderT = ciTitlebarHeight;
39         if( Window->Flags & WINFLAG_MAXIMIZED )
40                 return ;
41         
42         Window->BorderB = ciBottomBorderWidth;
43         Window->BorderR = ciSideBorderWidth;
44         Window->BorderL = ciSideBorderWidth;
45 }
46
47 void Decorator_Redraw(tWindow *Window)
48 {
49          int    bActive = 1;
50          int    text_width, text_height;
51         
52         // TODO: Detect if window has focus
53         
54         // Draw title bar
55         WM_Render_FillRect(Window,
56                 0, -ciTitlebarHeight, Window->W, ciTitlebarHeight,
57                 (bActive ? cColourActive_Titlebar : cColourInactive_Titlebar)
58                 );
59         WM_Render_FillRect(Window,
60                 0, -ciTitlebarHeight, Window->W, 1,
61                 cColour_TitleTopBorder
62                 );
63         WM_Render_FillRect(Window,
64                 0, -ciTitlebarHeight, 1, ciTitlebarHeight,
65                 cColour_SideBorder
66                 );
67         WM_Render_FillRect(Window,
68                 Window->W, -ciTitlebarHeight, 1, ciTitlebarHeight,
69                 cColour_SideBorder
70                 );
71
72         WM_Render_GetTextDims(
73                 NULL,   // TODO: Select font
74                 Window->Title ? Window->Title : "jI",
75                 &text_width, &text_height
76                 );
77         WM_Render_DrawText(Window,
78                 ciTitlebarHeight + 4, -(ciTitlebarHeight - (ciTitlebarHeight/2 - text_height/2)),
79                 Window->W - ciTitlebarHeight - 4, text_height,
80                 NULL,   // TODO: Select font
81                 (bActive ? cColourActive_TitleText : cColourInactive_TitleText),
82                 Window->Title ? Window->Title : "--"
83                 );
84         
85         // Maximized windows don't have any other borders
86         if( Window->Flags & WINFLAG_MAXIMIZED )
87                 return ;
88         
89         // Left
90         WM_Render_FillRect(Window,
91                 -ciSideBorderWidth, -ciTitlebarHeight,
92                 ciSideBorderWidth, Window->H + ciTitlebarHeight + ciBottomBorderWidth,
93                 cColour_SideBorder
94                 );
95         // Right
96         WM_Render_FillRect(Window,
97                 Window->W, -ciTitlebarHeight,
98                 ciSideBorderWidth, Window->H + ciTitlebarHeight + ciBottomBorderWidth,
99                 cColour_SideBorder
100                 );
101         // Bottom
102         WM_Render_FillRect(Window,
103                 -ciSideBorderWidth, Window->H,
104                 ciSideBorderWidth*2+Window->W, ciBottomBorderWidth,
105                 cColour_BottomBorder
106                 );
107 }
108
109 int Decorator_HandleMessage(tWindow *Window, int Message, int Length, const void *Data)
110 {
111         switch(Message)
112         {
113         case WNDMSG_MOUSEMOVE: {
114                 const struct sWndMsg_MouseMove  *msg = Data;
115                 if(msg->Y >= 0) return 1;       // Pass
116                 
117                 // TODO: Handle
118                 return 0; }
119         case WNDMSG_MOUSEBTN: {
120                 const struct sWndMsg_MouseButton        *msg = Data;
121                 if(msg->Y >= 0) return 1;       // Pass
122                 
123                 // TODO: Handle
124                 return 0; }
125         default:        // Anything unhandled is passed on
126                 return 1;
127         }
128 }
129

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