3 * - By John Hodge (thePowersGang)
9 #include <CCompositor.hpp>
10 #include <CClient.hpp>
16 CCompositor::CCompositor(CVideo& video):
17 // TODO: Support multiple screens
19 m_windowIDBuffer(video.width(), video.height())
24 void CCompositor::ShowWindow(CWindow* window)
26 DamageArea(window->m_surface.m_rect);
27 // TODO: Append to separate sub-lists (or to separate lists all together)
28 // if flags AXWIN4_WNDFLAG_KEEPBELOW or AXWIN4_WNDFLAG_KEEPABOVE are set
29 m_windows.push_back(window);
31 void CCompositor::HideWindow(CWindow* window)
33 DamageArea(window->m_surface.m_rect);
34 m_windows.remove(window);
37 bool CCompositor::GetScreenDims(unsigned int ScreenID, unsigned int* W, unsigned int* H)
48 m_video.GetDims(*W, *H);
53 void CCompositor::Redraw()
55 // Redraw the screen and clear damage rects
56 if( m_damageRects.empty() ) {
57 _SysDebug("- No damaged regions");
61 // Build up foreground grid (Rects and windows)
62 // - This should already be built (mutated on window move/resize/reorder)
64 // For all windows, check for intersection with damage rects
65 for( auto rect : m_damageRects )
67 // window list should be sorted by draw order (lowest first)
68 for( auto window : m_windows )
70 if( window->m_is_shown && rect.HasIntersection( window->m_surface.m_rect ) )
73 CRect rel_rect = window->m_surface.m_rect.RelativeIntersection(rect);
74 _SysDebug("Reblit (%i,%i) %ix%i", rel_rect.m_x, rel_rect.m_y, rel_rect.m_w, rel_rect.m_h);
75 BlitFromSurface( window->m_surface, rel_rect );
76 //window->Repaint( rel_rect );
77 m_windowIDBuffer.set(rel_rect.m_x, rel_rect.m_y, rel_rect.m_w, rel_rect.m_h, window);
81 // TODO: Blit from windows to a local surface, then blit from there to screen here
84 m_damageRects.clear();
88 void CCompositor::DamageArea(const CRect& area)
90 m_damageRects.push_back( area );
91 // 1. Locate intersection with any existing damaged areas
92 // 2. Append after removing intersections
95 void CCompositor::BlitFromSurface(const CSurface& dest, const CRect& src_rect)
97 for( unsigned int i = 0; i < src_rect.m_h; i ++ )
100 dest.GetScanline(src_rect.m_y+i, src_rect.m_x),
101 dest.m_rect.m_y + src_rect.m_y + i,
102 dest.m_rect.m_x + src_rect.m_x,
108 void CCompositor::MouseMove(unsigned int Cursor, unsigned int X, unsigned int Y, int dX, int dY)
110 _SysDebug("MouseButton(%i, %i,%i, %+i,%+i)", Cursor, X, Y, dX, dY);
111 m_video.SetCursorPos(X+dX, Y+dY);
112 CWindow *dstwin = getWindowForCoord(X, Y);
115 // TODO: Pass event on to window
119 void CCompositor::MouseButton(unsigned int Cursor, unsigned int X, unsigned int Y, eMouseButton Button, bool Press)
121 _SysDebug("MouseButton(%i, %i,%i, %i=%i)", Cursor, X, Y, Button, Press);
122 CWindow *dstwin = getWindowForCoord(X, Y);
125 // 1. Give focus and bring to front
127 // TODO: Pass event on to window
131 void CCompositor::KeyState(unsigned int KeyboardID, uint32_t KeySym, bool Press, uint32_t Codepoint)
133 _SysDebug("KeyState(%i, 0x%x, %b, 0x%x)", KeyboardID, KeySym, Press, Codepoint);
136 CWindow* CCompositor::getWindowForCoord(unsigned int X, unsigned int Y)
138 return m_windowIDBuffer.get(X, Y);
141 // --------------------------------------------------------------------
142 CWindowIDBuffer::CWindowIDBuffer(unsigned int W, unsigned int H):
147 void CWindowIDBuffer::set(unsigned int X, unsigned int Y, unsigned int W, unsigned int H, CWindow* win)
150 .Client = win->client().id(),
155 CWindow* CWindowIDBuffer::get(unsigned int X, unsigned int Y)
159 unsigned int pos = Y*m_w + X;
160 if( pos >= m_buf.size() )
162 auto id = m_buf[pos];
163 auto client = ::AxWin::IPC::GetClientByID(id.Client);
164 if( client == nullptr )
166 return client->GetWindow(id.Window);