Usermode/AxWin3 - Implementing more of the widget code
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / wm.c
index eddd12d..464901e 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <video.h>
+#include <wm_messages.h>
 
 // === GLOBALS ===
 tWMRenderer    *gpWM_Renderers;
@@ -118,16 +119,41 @@ int WM_ResizeWindow(tWindow *Window, int W, int H)
        Window->W = W;  Window->H = H;
 
        WM_Invalidate(Window);
+
+       {
+               struct sWndMsg_Resize   msg;
+               msg.W = W;
+               msg.H = H;
+               WM_SendMessage(NULL, Window, WNDMSG_RESIZE, sizeof(msg), &msg);
+       }
        
        return 0;
 }
 
+int WM_SendMessage(tWindow *Source, tWindow *Dest, int Message, int Length, void *Data)
+{
+       if(Dest == NULL)        return -2;
+       if(Length > 0 && Data == NULL)  return -1;
+       
+       // ->HandleMessage returns 1 when the message was not handled
+       if( Dest->Renderer->HandleMessage(Dest, Message, Length, Data) != 1 )
+       {
+               // TODO: Catch errors from ->HandleMessage
+               return 0;
+       }
+       
+       // TODO: Pass on to user
+       _SysDebug("WM_SendMessage: TODO - Implement sending to client application");
+       
+       return 1;
+}
+
 void WM_Invalidate(tWindow *Window)
 {
        // Don't invalidate twice (speedup)
        if( !(Window->Flags & WINFLAG_CLEAN) )  return;
 
-       _SysDebug("Invalidating %p");
+//     _SysDebug("Invalidating %p");
        
        // Mark for re-render
        Window->Flags &= ~WINFLAG_CLEAN;
@@ -135,7 +161,7 @@ void WM_Invalidate(tWindow *Window)
        // Mark up the tree that a child window has changed     
        while( (Window = Window->Parent) )
        {
-               _SysDebug("Childclean removed from %p", Window);
+//             _SysDebug("Childclean removed from %p", Window);
                Window->Flags &= ~WINFLAG_CHILDCLEAN;
        }
 }
@@ -199,140 +225,3 @@ void WM_Update(void)
        Video_Update();
 }
 
-// --- WM Render Routines
-// TODO: Move to another file?
-void WM_Render_FillRect(tWindow *Window, int X, int Y, int W, int H, tColour Colour)
-{
-       uint32_t        *dest;
-        int    i;
-       _SysDebug("WM_Render_FilledRect(%p, 0x%x...", Window, Colour);
-       _SysDebug(" (%i,%i), %ix%i)", X, Y, W, H);
-       // Clip to window dimensions
-       if(X < 0) { W += X; X = 0; }
-       if(Y < 0) { H += Y; Y = 0; }
-       if(X >= Window->W)      return;
-       if(Y >= Window->H)      return;
-       if(X + W > Window->W)   W = Window->W - X;
-       if(Y + H > Window->H)   H = Window->H - Y;
-       _SysDebug(" Clipped to (%i,%i), %ix%i", X, Y, W, H);
-
-       // Render to buffer
-       // Create if needed?
-
-       if(!Window->RenderBuffer) {
-               Window->RenderBuffer = malloc(Window->W*Window->H*4);
-       }
-
-       dest = (uint32_t*)Window->RenderBuffer + Y*Window->W + X;
-       while( H -- )
-       {
-               for( i = W; i --; )
-                       *dest++ = Colour;
-               dest += Window->W - W;
-       }
-}
-
-void WM_Render_DrawRect(tWindow *Window, int X, int Y, int W, int H, tColour Colour)
-{      
-       WM_Render_FillRect(Window, X, Y, W, 1, Colour);
-       WM_Render_FillRect(Window, X, Y+H-1, W, 1, Colour);
-       WM_Render_FillRect(Window, X, Y, 1, H, Colour);
-       WM_Render_FillRect(Window, X+W-1, Y, 1, H, Colour);
-}
-
-void WM_Render_DrawText(tWindow *Window, int X, int Y, int W, int H, void *Font, tColour Colour, const char *Text)
-{
-       // TODO: Implement
-}
-
-/**
- * \brief Draw an image to the screen
- * \todo Maybe have support for an offset in the image
- */
-void WM_Render_DrawImage(tWindow *Window, int X, int Y, int W, int H, tImage *Image)
-{
-        int    x, y;
-       uint32_t        *dest;
-       uint8_t *data;
-       
-       // Sanity please
-       if( !Image )    return ;
-
-       // Allocate
-       if(!Window->RenderBuffer) {
-               Window->RenderBuffer = malloc(Window->W*Window->H*4);
-       }
-       
-       // Bounds Check
-       if( X >= Window->W )    return ;
-       if( Y >= Window->H )    return ;
-       
-       // Wrap to image size
-       if( W > Image->Width )  W = Image->Width;
-       if( H > Image->Height ) H = Image->Height;
-       
-       // Wrap to screen size
-       if( X + W > Window->W ) W = Window->W - X;
-       if( Y + H > Window->H ) H = Window->H - Y;
-
-       dest = (uint32_t*)Window->RenderBuffer + Y * Window->W + X;
-       data = Image->Data;
-
-       // Do the render
-       switch( Image->Format )
-       {
-       case IMGFMT_BGRA:
-               for( y = 0; y < H; y ++ )
-               {
-                        int    r, g, b, a;     // New
-                        int    or, og, ob;     // Original
-                       for( x = 0; x < W; x ++ )
-                       {
-                               b = data[x*4+0]; g = data[x*4+1]; r = data[x*4+2]; a = data[x*4+3];
-                               if( a == 0 )    continue;       // 100% transparent
-                               ob = dest[x]&0xFF; og = (dest[x] >> 8)&0xFF; or = (dest[x] >> 16)&0xFF;
-                               // Handle Alpha
-                               switch(a)
-                               {
-                               // Transparent: Handled above
-                               // Solid
-                               case 0xFF:      break;
-                               // Half
-                               case 0x80:
-                                       r = (or + r) / 2;
-                                       g = (og + g) / 2;
-                                       b = (ob + b) / 2;
-                                       break;
-                               // General
-                               default:
-                                       r = (or * (255-a) + r * a) / 255;
-                                       g = (og * (255-a) + g * a) / 255;
-                                       b = (ob * (255-a) + b * a) / 255;
-                                       break;
-                               }
-                               dest[x] = b | (g << 8) | (r << 16);
-                       }
-                       data += Image->Width * 4;
-                       dest += Window->W;
-               }
-               break;
-       
-       // RGB
-       case IMGFMT_RGB:
-               for( y = 0; y < H; y ++ )
-               {
-                       for( x = 0; x < W; x ++ )
-                       {
-                               //        Blue           Green                Red
-                               dest[x] = data[x*3+2] | (data[x*3+1] << 8) | (data[x*3+0] << 16);
-                       }
-                       data += W * 3;
-                       dest += Window->W;
-               }
-               break;
-       default:
-               _SysDebug("ERROR: Unknown image format %i\n", Image->Format);
-               break;
-       }
-}
-

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