Usermode/AxWin4 - Rendering random data successfully now
[tpg/acess2.git] / Usermode / Applications / axwin4_src / Server / CSurface.cpp
index d52298c..6d4b090 100644 (file)
@@ -7,12 +7,18 @@
  */
 #include <CSurface.hpp>
 #include <cassert>
+#include <stdexcept>
+#include <cstring>
 
 namespace AxWin {
 
 CSurface::CSurface(int x, int y, unsigned int w, unsigned int h):
        m_rect(x,y, w,h)
 {
+       if( w > 0 && h > 0 )
+       {
+               m_data = new uint32_t[w * h];
+       }
 }
 
 CSurface::~CSurface()
@@ -21,12 +27,35 @@ CSurface::~CSurface()
 
 void CSurface::Resize(unsigned int W, unsigned int H)
 {
-       assert(!"TODO: CSurface::Resize");
+       // Easy realloc
+       // TODO: Should I maintain window contents sanely? NOPE!
+       delete m_data;
+       m_data = new uint32_t[W * H];
+       m_rect.Resize(W, H);
+}
+
+void CSurface::DrawScanline(unsigned int row, unsigned int x_ofs, unsigned int w, const void* data)
+{
+       //_SysDebug("DrawScanline(%i,%i,%i,%p)", row, x_ofs, w, data);
+       if( row >= m_rect.m_h )
+               throw ::std::out_of_range("CSurface::DrawScanline row");
+       if( x_ofs >= m_rect.m_w )
+               throw ::std::out_of_range("CSurface::DrawScanline x_ofs");
+
+       if( w > m_rect.m_w )
+               throw ::std::out_of_range("CSurface::DrawScanline width");
+       
+       ::memcpy( &m_data[row*m_rect.m_w + x_ofs], data, w*4 );
 }
 
 const uint32_t* CSurface::GetScanline(unsigned int row, unsigned int x_ofs) const
 {
-       return 0;
+       if( row >= m_rect.m_h )
+               throw ::std::out_of_range("CSurface::GetScanline row");
+       if( x_ofs >= m_rect.m_w )
+               throw ::std::out_of_range("CSurface::GetScanline x_ofs");
+
+       return &m_data[row * m_rect.m_w + x_ofs];
 }
 
 

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