2 * Acess2 Window Manager v3
3 * - By John Hodge (thePowersGang)
6 * - Window rendering functions
10 #include <wm_internals.h>
14 void WM_Render_FillRect(tWindow *Window, int X, int Y, int W, int H, tColour Colour)
22 // Clip to window dimensions
23 if(X < 0) { W += X; X = 0; }
24 if(Y < 0) { H += Y; Y = 0; }
25 if(W <= 0 || H <= 0) return;
26 if(X >= Window->RealW) return;
27 if(Y >= Window->RealH) return;
28 if(X + W > Window->RealW) W = Window->RealW - X;
29 if(Y + H > Window->RealH) H = Window->RealH - Y;
31 // TODO: Catch overflow into decorator area
33 if(!Window->RenderBuffer) {
34 Window->RenderBuffer = malloc(Window->RealW*Window->RealH*4);
37 dest = (uint32_t*)Window->RenderBuffer + Y*Window->RealW + X;
42 dest += Window->RealW - W;
46 void WM_Render_DrawRect(tWindow *Window, int X, int Y, int W, int H, tColour Colour)
48 WM_Render_FillRect(Window, X, Y, W, 1, Colour);
49 WM_Render_FillRect(Window, X, Y+H-1, W, 1, Colour);
50 WM_Render_FillRect(Window, X, Y, 1, H, Colour);
51 WM_Render_FillRect(Window, X+W-1, Y, 1, H, Colour);
55 * \brief Draw an image to the screen
56 * \todo Maybe have support for an offset in the image
58 void WM_Render_DrawImage(tWindow *Window, int X, int Y, int W, int H, tImage *Image)
68 if(!Window->RenderBuffer) {
69 Window->RenderBuffer = malloc(Window->W*Window->H*4);
77 if( X >= Window->RealW ) return ;
78 if( Y >= Window->RealH ) return ;
81 if( W > Image->Width ) W = Image->Width;
82 if( H > Image->Height ) H = Image->Height;
84 // Wrap to screen size
85 if( X + W > Window->RealW ) W = Window->RealW - X;
86 if( Y + H > Window->RealH ) H = Window->RealH - Y;
88 // TODO: Catch overflow into decorator area
90 if( !Window->bDrawingDecorations )
92 if( X < Window->BorderL ) return ;
93 if( Y < Window->BorderT ) return ;
94 if( X + W > Window->BorderL + Window->W ) W = X - (Window->BorderL + Window->W);
95 if( Y + H > Window->BorderT + Window->H ) H = Y - (Window->BorderT + Window->H);
99 dest = (uint32_t*)Window->RenderBuffer + Y * Window->RealW + X;
103 switch( Image->Format )
106 for( y = 0; y < H; y ++ )
108 int r, g, b, a; // New
109 int or, og, ob; // Original
110 for( x = 0; x < W; x ++ )
112 b = data[x*4+0]; g = data[x*4+1]; r = data[x*4+2]; a = data[x*4+3];
113 if( a == 0 ) continue; // 100% transparent
114 ob = dest[x]&0xFF; og = (dest[x] >> 8)&0xFF; or = (dest[x] >> 16)&0xFF;
118 // Transparent: Handled above
129 r = (or * (255-a) + r * a) / 255;
130 g = (og * (255-a) + g * a) / 255;
131 b = (ob * (255-a) + b * a) / 255;
134 dest[x] = b | (g << 8) | (r << 16);
136 data += Image->Width * 4;
137 dest += Window->RealW;
143 for( y = 0; y < H; y ++ )
145 for( x = 0; x < W; x ++ )
148 dest[x] = data[x*3+2] | (data[x*3+1] << 8) | (data[x*3+0] << 16);
151 dest += Window->RealW;
155 _SysDebug("ERROR: Unknown image format %i\n", Image->Format);
160 void WM_Render_SetTextCursor(tWindow *Window, int X, int Y, int W, int H, tColour Colour)
162 if( X < 0 || Y < 0 ) return ;
163 if( X >= Window->W ) return ;
164 if( Y >= Window->H ) return ;
165 if( X + W >= Window->W ) W = Window->W - X;
166 if( Y + H >= Window->H ) H = Window->H - Y;