Usermode/AxWin4 - Server implemenation moving along
[tpg/acess2.git] / Usermode / Applications / axwin4_src / Server / compositor.cpp
1 /*
2  * Acess2 GUI v4
3  * - By John Hodge (thePowersGang)
4  *
5  * compositor.cpp
6  * - Window compositor
7  */
8 #include <video.hpp>
9 #include <CCompositor.hpp>
10 #include <cassert>
11
12 namespace AxWin {
13
14 CCompositor::CCompositor(CVideo& video):
15         m_video(video)
16 {
17         // 
18 }
19
20 CWindow* CCompositor::CreateWindow(CClient& client, const ::std::string& name)
21 {
22         return new CWindow(*this, client, name);
23 }
24
25 bool CCompositor::GetScreenDims(unsigned int ScreenID, unsigned int* W, unsigned int* H)
26 {
27         assert(W && H);
28         if( ScreenID != 0 )
29         {
30                 *W = 0;
31                 *H = 0;
32                 return false;
33         }
34         else
35         {
36                 m_video.GetDims(*W, *H);
37                 return true;
38         }
39 }
40
41 void CCompositor::Redraw()
42 {
43         // Redraw the screen and clear damage rects
44         if( m_damageRects.empty() )
45                 return ;
46         
47         // Build up foreground grid (Rects and windows)
48         // - This should already be built (mutated on window move/resize/reorder)
49         
50         // For all windows, check for intersection with damage rects
51         for( auto rect : m_damageRects )
52         {
53                 // window list should be sorted by draw order (lowest first)
54                 for( auto window : m_windows )
55                 {
56                         if( rect.HasIntersection( window->m_surface.m_rect ) )
57                         {
58                                 // TODO: just reblit
59                                 CRect   rel_rect = window->m_surface.m_rect.RelativeIntersection(rect);
60                                 BlitFromSurface( window->m_surface, rel_rect );
61                                 //window->Repaint( rel_rect );
62                         }
63                 }
64                 
65                 // TODO: Blit from windows to a local surface, then blit from there to screen here
66         }
67
68         m_damageRects.clear();
69         m_video.Flush();
70 }
71
72 void CCompositor::DamageArea(const CRect& area)
73 {
74         m_damageRects.push_back( area );
75         // 1. Locate intersection with any existing damaged areas
76         // 2. Append after removing intersections
77 }
78
79 void CCompositor::BlitFromSurface(const CSurface& dest, const CRect& src_rect)
80 {
81         for( unsigned int i = 0; i < src_rect.m_h; i ++ )
82         {
83                 m_video.BlitLine(
84                         dest.GetScanline(src_rect.m_y, src_rect.m_y),
85                         dest.m_rect.m_y + src_rect.m_y + i,
86                         dest.m_rect.m_x + src_rect.m_x,
87                         src_rect.m_w
88                         );
89         }
90 }
91
92 }       // namespace AxWin
93

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