Usermode/AxWin4 - Minor cleanups (change background colour, remove commented lines)
[tpg/acess2.git] / Usermode / Applications / axwin4_src / Server / ipc.cpp
index 1c5ba99..f522ac2 100644 (file)
@@ -19,6 +19,7 @@ extern "C" {
 };
 #include <CIPCChannel_AcessIPCPipe.hpp>
 #include <draw_control.hpp>
+#include <draw_text.hpp>
 
 namespace AxWin {
 namespace IPC {
@@ -101,9 +102,36 @@ void DeregisterClient(CClient& client)
 }
 
 
-void SendMessage_NotifyDims(CClient& client, unsigned int NewW, unsigned int NewH)
+void SendMessage_NotifyDims(CClient& client, unsigned int WinID, unsigned int NewW, unsigned int NewH)
 {
-       _SysDebug("TODO: CClient::SendNotify_Dims");
+       _SysDebug("TODO: IPC::SendMessage_NotifyDims");
+}
+void SendMessage_MouseButton(CClient& client, unsigned int WinID, unsigned int X, unsigned int Y, uint8_t Button, bool Pressed)
+{
+       CSerialiser     msg;
+       msg.WriteU8(IPCMSG_INPUTEVENT);
+       msg.WriteU8(IPC_INEV_MOUSEBTN);
+       msg.WriteU16(WinID);
+       msg.WriteU16(X);
+       msg.WriteU16(Y);
+       msg.WriteU8(Button);
+       msg.WriteU8(Pressed ? 0 : 1);
+       client.SendMessage(msg);
+}
+void SendMessage_MouseMove(CClient& client, unsigned int WinID, unsigned int X, unsigned int Y)
+{
+       _SysDebug("TODO: IPC::SendMessage_MouseMove");
+}
+void SendMessage_KeyEvent(CClient& client, unsigned int WinID, uint32_t KeySym, bool Pressed, const char *Translated)
+{
+       CSerialiser     msg;
+       msg.WriteU8(IPCMSG_INPUTEVENT);
+       msg.WriteU8(IPC_INEV_KEYBOARD);
+       msg.WriteU16(WinID);
+       msg.WriteU16(KeySym);
+       msg.WriteU8(Pressed ? 0 : 1);
+       msg.WriteString(Translated);
+       client.SendMessage(msg);
 }
 
 
@@ -355,9 +383,9 @@ void HandleMessage_DrawText(CClient& client, CDeserialiser& message)
        uint16_t        y = message.ReadU16();
        uint16_t        w = message.ReadU16();
        uint16_t        h = message.ReadU16();
-       uint16_t        font = message.ReadU16();
+       uint16_t        font_id = message.ReadU16();
        ::std::string   str = message.ReadString();
-       _SysDebug("_DrawText: (%i (%i,%i) %ix%i Font%i \"%s\")", win_id, x, y, w, h, font, str.c_str());
+       _SysDebug("_DrawText: (%i (%i,%i) %ix%i Font%i \"%s\")", win_id, x, y, w, h, font_id, str.c_str());
        
        CWindow*        win = client.GetWindow(win_id);
        if(!win) {
@@ -365,13 +393,66 @@ void HandleMessage_DrawText(CClient& client, CDeserialiser& message)
        }
        
        // 1. Get font from client structure
-       //CFont& font = client.GetFont(font_id);
+       IFontFace& fontface = client.GetFont(font_id);
        
        // 2. Render
-       //CRect area(x, y, w, h);
-       //font->Render(win->m_surface, area, str, h);
+       CRect   area(x, y, w, h);
+       fontface.Render(win->m_surface, area, str, h);
+}
+
+void HandleMessage_FillRect(CClient& client, CDeserialiser& message)
+{
+       uint16_t        win_id = message.ReadU16();
+       uint16_t        x = message.ReadU16();
+       uint16_t        y = message.ReadU16();
+       uint16_t        w = message.ReadU16();
+       uint16_t        h = message.ReadU16();
+       uint32_t        colour = message.ReadU32();
+       _SysDebug("_FillRect: (%i (%i,%i) %ix%i %06x)", win_id, x, y, w, h, colour);
+       
+       CWindow*        win = client.GetWindow(win_id);
+       if(!win) {
+               throw IPC::CClientFailure("_FillRect: Bad window");
+       }
+       
+       while(h -- ) {
+               win->FillScanline(y++, x, w, colour);
+       }
+}
+
+void HandleMessage_DrawRect(CClient& client, CDeserialiser& message)
+{
+       uint16_t        win_id = message.ReadU16();
+       uint16_t        x = message.ReadU16();
+       uint16_t        y = message.ReadU16();
+       uint16_t        w = message.ReadU16();
+       uint16_t        h = message.ReadU16();
+       uint32_t        colour = message.ReadU32();
+       _SysDebug("_DrawRect: (%i (%i,%i) %ix%i %06x)", win_id, x, y, w, h, colour);
        
-       _SysDebug("TODO: HandleMessage_DrawText");
+       CWindow*        win = client.GetWindow(win_id);
+       if(!win) {
+               throw IPC::CClientFailure("_DrawRect: Bad window");
+       }
+       
+       if(h == 0) {
+       }
+       else if(h == 1) {
+               win->FillScanline(y, x, w, colour);
+       }
+       else if(h == 2) {
+               win->FillScanline(y++, x, w, colour);
+               win->FillScanline(y++, x, w, colour);
+       }
+       else {
+               win->FillScanline(y++, x, w, colour);
+               while( h -- > 2 ) {
+                       win->FillScanline(y, x, 1, colour);
+                       win->FillScanline(y, x+w-1, 1, colour);
+                       y ++;
+               }
+               win->FillScanline(y++, x, w, colour);
+       }
 }
 
 typedef void   MessageHandler_op_t(CClient& client, CDeserialiser& message);
@@ -394,13 +475,17 @@ MessageHandler_op_t       *message_handlers[] = {
        [IPCMSG_BLIT]       = &HandleMessage_Blit,      // Copy data from one part of the window to another
        [IPCMSG_DRAWCTL]    = &HandleMessage_DrawCtl,   // Draw a control
        [IPCMSG_DRAWTEXT]   = &HandleMessage_DrawText,  // Draw text
+       [IPCMSG_FILLRECT]   = &HandleMessage_FillRect,  // Fill a rectangle
+       [IPCMSG_DRAWRECT]   = &HandleMessage_DrawRect,  // Draw (outline) a rectangle
 };
 
 void HandleMessage(CClient& client, CDeserialiser& message)
 {
+       const unsigned int num_commands = sizeof(message_handlers)/sizeof(IPC::MessageHandler_op_t*);
        unsigned int command = message.ReadU8();
-       if( command >= sizeof(message_handlers)/sizeof(IPC::MessageHandler_op_t*) ) {
+       if( command >= num_commands ) {
                // Drop, invalid command
+               _SysDebug("HandleMessage: Command %u is invalid (out of range for %u)", command, num_commands);
                return ;
        }
        

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