Usermode/AxWin4 - Rendering random data successfully now
[tpg/acess2.git] / Usermode / Applications / axwin4_src / Server / CSurface.cpp
1 /*
2  * Acess2 GUI v4
3  * - By John Hodge (thePowersGang)
4  *
5  * CWindow.cpp
6  * - Window
7  */
8 #include <CSurface.hpp>
9 #include <cassert>
10 #include <stdexcept>
11 #include <cstring>
12
13 namespace AxWin {
14
15 CSurface::CSurface(int x, int y, unsigned int w, unsigned int h):
16         m_rect(x,y, w,h)
17 {
18         if( w > 0 && h > 0 )
19         {
20                 m_data = new uint32_t[w * h];
21         }
22 }
23
24 CSurface::~CSurface()
25 {
26 }
27
28 void CSurface::Resize(unsigned int W, unsigned int H)
29 {
30         // Easy realloc
31         // TODO: Should I maintain window contents sanely? NOPE!
32         delete m_data;
33         m_data = new uint32_t[W * H];
34         m_rect.Resize(W, H);
35 }
36
37 void CSurface::DrawScanline(unsigned int row, unsigned int x_ofs, unsigned int w, const void* data)
38 {
39         //_SysDebug("DrawScanline(%i,%i,%i,%p)", row, x_ofs, w, data);
40         if( row >= m_rect.m_h )
41                 throw ::std::out_of_range("CSurface::DrawScanline row");
42         if( x_ofs >= m_rect.m_w )
43                 throw ::std::out_of_range("CSurface::DrawScanline x_ofs");
44
45         if( w > m_rect.m_w )
46                 throw ::std::out_of_range("CSurface::DrawScanline width");
47         
48         ::memcpy( &m_data[row*m_rect.m_w + x_ofs], data, w*4 );
49 }
50
51 const uint32_t* CSurface::GetScanline(unsigned int row, unsigned int x_ofs) const
52 {
53         if( row >= m_rect.m_h )
54                 throw ::std::out_of_range("CSurface::GetScanline row");
55         if( x_ofs >= m_rect.m_w )
56                 throw ::std::out_of_range("CSurface::GetScanline x_ofs");
57
58         return &m_data[row * m_rect.m_w + x_ofs];
59 }
60
61
62 };      // namespace AxWin
63
64

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