Usermode/AxWin3 - Working on window rendering, root window renders now :)
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / video.c
index 4121fbe..6a400a8 100644 (file)
@@ -1,12 +1,17 @@
 /*
- * Acess GUI (AxWin) Version 2
- * By John Hodge (thePowersGang)
+ * Acess2 GUI (AxWin) Version 3
+ * - By John Hodge (thePowersGang)
+ *
+ * video.c
+ * - Video methods
  */
-#include "common.h"
+#include <common.h>
 #include <acess/sys.h>
 #include <acess/devices/terminal.h>
 #include <image.h>
 #include "resources/cursor.h"
+#include <stdio.h>
+#include <video.h>
 
 // === PROTOTYPES ===
 void   Video_Setup(void);
@@ -18,6 +23,7 @@ void  Video_DrawRect(short X, short Y, short W, short H, uint32_t Color);
 // === GLOBALS ===
  int   giVideo_CursorX;
  int   giVideo_CursorY;
+uint32_t       *gpScreenBuffer;
 
 // === CODE ===
 void Video_Setup(void)
@@ -61,7 +67,7 @@ void Video_Setup(void)
        
        // Create local framebuffer (back buffer)
        gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
-       memset32( gpScreenBuffer, 0x8888FF, giScreenWidth*giScreenHeight );
+       Video_FillRect(0, 0, giScreenWidth, giScreenHeight, 0x8080FF);
 
        // Set cursor position and bitmap
        ioctl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap);
@@ -72,9 +78,10 @@ void Video_Setup(void)
 
 void Video_Update(void)
 {
-       //seek(giTerminalFD, 0, SEEK_SET);
+       _SysDebug("Video_Update - gpScreenBuffer[0] = 0x%x", gpScreenBuffer[0]);
        seek(giTerminalFD, 0, 1);
        write(giTerminalFD, gpScreenBuffer, giScreenWidth*giScreenHeight*4);
+       _SysDebug("Video_Update - Done");
 }
 
 void Video_SetCursorPos(short X, short Y)
@@ -90,6 +97,7 @@ void Video_SetCursorPos(short X, short Y)
 
 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color)
 {
+        int    i;
        uint32_t        *buf = gpScreenBuffer + Y*giScreenWidth + X;
        
        _SysDebug("Video_FillRect: (X=%i, Y=%i, W=%i, H=%i, Color=%08x)",
@@ -103,8 +111,9 @@ void Video_FillRect(short X, short Y, short W, short H, uint32_t Color)
        
        while( H -- )
        {
-               memset32( buf, Color, W );
-               buf += giScreenWidth;
+               for( i = W; i --; )
+                       *buf++ = Color;
+               buf += giScreenWidth - W;
        }
 }
 
@@ -116,6 +125,36 @@ void Video_DrawRect(short X, short Y, short W, short H, uint32_t Color)
        Video_FillRect(X+W-1, Y, 1, H, Color);
 }
 
+/**
+ * \brief Blit an entire buffer to the screen
+ * \note Assumes Pitch = 4*W
+ */
+void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H)
+{
+        int    i;
+       uint32_t        *buf;
+
+       _SysDebug("Video_Blit: (%p (%i, %i) %ix%i)", Source, DstX, DstY, W, H);
+       
+       // TODO: Handle -ve X/Y by clipping
+       if( DstX < 0 || DstY < 0 )      return ;
+       // TODO: Handle out of bounds by clipping too
+       if( DstX + W > giScreenWidth )  return;
+       if( DstY + H > giScreenHeight ) return;
+
+       if( W <= 0 || H <= 0 )  return;
+       
+       _SysDebug(" Clipped to (%i, %i) %ix%i", DstX, DstY, W, H);
+       _SysDebug(" Source[0] = 0x%x", Source[0]);
+       buf = gpScreenBuffer + DstY*giScreenWidth + DstX;
+       while( H -- )
+       {
+               for( i = W; i --; )
+                       *buf++ = *Source++;
+               buf += giScreenWidth - W;
+       }
+}
+
 /**
  * \brief Draw an image to the screen
  * \todo Maybe have support for an offset in the image

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