429657a345cb7a684141ed0bbb0cfef675f30b78
[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         _SysDebug(" memcpy(%p, %p, %i)", &m_data[row*m_rect.m_w + x_ofs], data, w*4 );
49         ::memcpy( &m_data[row*m_rect.m_w + x_ofs], data, w*4 );
50 }
51
52 const uint32_t* CSurface::GetScanline(unsigned int row, unsigned int x_ofs) const
53 {
54         if( row >= m_rect.m_h )
55                 throw ::std::out_of_range("CSurface::GetScanline row");
56         if( x_ofs >= m_rect.m_w )
57                 throw ::std::out_of_range("CSurface::GetScanline x_ofs");
58
59         return &m_data[row * m_rect.m_w + x_ofs];
60 }
61
62
63 };      // namespace AxWin
64
65

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