* - Rectangle
*/
#include <CRect.hpp>
+#include <algorithm>
namespace AxWin {
-CRect::CRect(int x, int y, int w, int h)
- //m_x(x), m_y(y), m_w(w), m_h(h)
+CRect::CRect(int x, int y, unsigned int w, unsigned int h):
+ m_x(x), m_y(y),
+ m_w(w), m_h(h),
+ m_x2(x+w), m_y2(y+h)
{
}
-bool CRect::Contains(const CRect& other) const
+bool CRect::HasIntersection(const CRect& other) const
{
- return false;
+ // If other's origin is past our far corner
+ if( m_x2 < other.m_x )
+ return false;
+ if( m_y2 < other.m_y )
+ return false;
+
+ // If other's far corner is before our origin
+ if( m_x > other.m_x2 )
+ return false;
+ if( m_y > other.m_y2 )
+ return false;
+ return true;
+}
+
+CRect CRect::Intersection(const CRect& other) const
+{
+ int x1 = ::std::max(m_x, other.m_x);
+ int y1 = ::std::max(m_y, other.m_y);
+ int x2 = ::std::min(m_x2, other.m_x2);
+ int y2 = ::std::min(m_y2, other.m_y2);
+
+ if( x1 <= x2 || y2 <= y1 )
+ return CRect();
+
+ return CRect(x1, y1, x2-x1, y2-y2);
+}
+
+CRect CRect::RelativeIntersection(const CRect& area)
+{
+ CRect ret = Intersection(area);
+ ret.m_x -= m_x;
+ ret.m_x2 -= m_x;
+ ret.m_y -= m_y;
+ ret.m_y2 -= m_y;
+ return ret;
}
};
--- /dev/null
+/*
+ * Acess2 GUI v4
+ * - By John Hodge (thePowersGang)
+ *
+ * CWindow.cpp
+ * - Window
+ */
+#include <CSurface.hpp>
+
+namespace AxWin {
+
+CSurface::CSurface(unsigned int x, unsigned int y, unsigned int w, unsigned int h):
+ m_rect(x,y, w,h)
+{
+}
+
+CSurface::~CSurface()
+{
+}
+
+const uint32_t* CSurface::GetScanline(unsigned int row, unsigned int x_ofs) const
+{
+ return 0;
+}
+
+
+}; // namespace AxWin
+
+
CWindow::CWindow(CClient& client, const ::std::string& name):
m_client(client),
m_name(name),
- m_rect(0,0,0,0)
+ m_surface(0,0,0,0)
{
}
void CWindow::Repaint(const CRect& rect)
{
-
+ #if 0
+ for( auto rgn : m_regions )
+ {
+ if( rect.Contains(rgn->m_rect) )
+ {
+ CRect rel_rect(rect, rgn->m_rect);
+ rgn->Repaint();
+ }
+ }
+ #endif
}
};
OBJ := main.o ipc.o CConfig.o video.o input.o timing.o
OBJ += compositor.o CWindow.o
OBJ += serialisation.o CClient.o
-OBJ += CRect.o
+OBJ += CRect.o CSurface.o
BIN := AxWinServer
LDFLAGS += -lc++
namespace AxWin {
-CCompositor::CCompositor()
+CCompositor::CCompositor(CVideo& video):
+ m_video(video)
{
//
}
{
for( auto window : m_windows )
{
- if( rect.Contains( window->m_rect ) )
+ if( rect.HasIntersection( window->m_surface.m_rect ) )
{
- window->Repaint( rect );
+ // TODO: just reblit
+ CRect rel_rect = window->m_surface.m_rect.RelativeIntersection(rect);
+ BlitFromSurface( window->m_surface, rel_rect );
+ //window->Repaint( rel_rect );
}
}
}
// 2. Append after removing intersections
}
+void CCompositor::BlitFromSurface(const CSurface& dest, const CRect& src_rect)
+{
+ for( unsigned int i = 0; i < src_rect.m_h; i ++ )
+ {
+ m_video.BlitLine(
+ dest.GetScanline(src_rect.m_y, src_rect.m_y),
+ dest.m_rect.m_y + src_rect.m_y + i,
+ dest.m_rect.m_x + src_rect.m_x,
+ src_rect.m_w
+ );
+ }
+}
+
} // namespace AxWin
#define _CCOMPOSITOR_H_
#include <list>
+#include <vector>
#include "CRect.hpp"
#include "CWindow.hpp"
namespace AxWin {
class CClient;
+class CVideo;
+
+struct TWindowID
+{
+ uint16_t Client;
+ uint16_t Window;
+};
class CCompositor
{
+ CVideo& m_video;
::std::list<CRect> m_damageRects;
::std::list<CWindow*> m_windows;
+ ::std::vector<TWindowID> m_windowIDBuffer; // One 32-bit value per pixel
+ //::std::vector<CPixel> m_frameBuffer; // Local copy of the framebuffer (needed?)
+
public:
- CCompositor();
+ CCompositor(CVideo& video);
CWindow* CreateWindow(CClient& client);
void Redraw();
void DamageArea(const CRect& rect);
+ void BlitFromSurface(const CSurface& dest, const CRect& src_rect);
};
class CRect
{
public:
- CRect(int X, int Y, int W, int H);
+ CRect():
+ CRect(0,0,0,0)
+ {
+ };
+ CRect(int X, int Y, unsigned int W, unsigned int H);
- bool Contains(const CRect& other) const;
+ bool HasIntersection(const CRect& other) const;
+ CRect Intersection(const CRect& other) const;
+
+ CRect RelativeIntersection(const CRect& area);
+
+ int m_x;
+ int m_y;
+ int m_w;
+ int m_h;
+ int m_x2;
+ int m_y2;
};
}; // namespace AxWin
--- /dev/null
+/*
+ */
+#ifndef _CSURFACE_H_
+#define _CSURFACE_H_
+
+#include <cstdint>
+#include "CRect.hpp"
+
+namespace AxWin {
+
+class CSurface
+{
+public:
+ CSurface(unsigned int x, unsigned int y, unsigned int w, unsigned int h);
+ ~CSurface();
+
+ const uint32_t* GetScanline(unsigned int row, unsigned int x_ofs) const;
+
+ CRect m_rect;
+ uint32_t* m_data;
+};
+
+}; // namespace AxWin
+
+#endif
+
#include <vector>
#include <cstdint>
#include "CRect.hpp"
+#include "CSurface.hpp"
namespace AxWin {
class CWindow
{
- CClient& m_client;
public:
CWindow(CClient& client, const ::std::string &name);
~CWindow();
void MouseMove(int NewX, int NewY);
void KeyEvent(::uint32_t Scancode, const ::std::string &Translated, bool Down);
- CRect m_rect;
+ CSurface m_surface;
private:
const ::std::string m_name;
+ CClient& m_client;
+ //::std::list<CRegion*> m_regions;
};
}; // namespace AxWin
--- /dev/null
+/*
+ */
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+#include <exception>
+
+namespace AxWin {
+
+class InitFailure:
+ public ::std::exception
+{
+ const char *m_what;
+public:
+ InitFailure(const char *reason):
+ m_what(reason)
+ {
+ }
+
+ virtual const char* what() const throw();
+};
+
+} // namespace AxWin
+
+#endif
+
#ifndef _VIDEO_H_
#define _VIDEO_H_
+#include <cstdint>
#include "CConfigVideo.hpp"
namespace AxWin {
-namespace Graphics {
-
-extern void Initialise(const CConfigVideo& config);
+class CVideo
+{
+ int m_fd;
+ unsigned int m_width;
+ unsigned int m_height;
+public:
+ CVideo(const CConfigVideo& config);
+
+ void BlitLine(const uint32_t* src, unsigned int dst_y, unsigned int dst_x, unsigned int width);
};
};
/*
+ * Acess2 GUI v4 (AxWin4)
+ * - By John Hodge (thePowesGang)
+ *
+ * main.cpp
+ * - Program main
*/
#include <CConfig.hpp>
#include <ipc.hpp>
#include <timing.hpp>
#include <exception>
#include <algorithm>
+#include <common.hpp>
extern "C" {
#include <stdio.h>
return 1;
}
// - Open graphics
- Graphics::Initialise(config.m_video);
+ CVideo* vid = new CVideo(config.m_video);
// - Initialise compositor structures
- CCompositor* compositor = new CCompositor(/*config.m_compositor*/);
+ CCompositor* compositor = new CCompositor(/*config.m_compositor,*/ *vid);
// - Open input
Input::Initialise(config.m_input);
// > Handles hotkeys?
return 0;
}
+namespace AxWin {
+
+const char* InitFailure::what() const throw()
+{
+ return m_what;
+}
+
+
+}
+
* video.cpp
* - Graphics output
*/
+#include <cstddef>
#include <video.hpp>
+#include <common.hpp>
-namespace AxWin {
+extern "C" {
+#include <acess/sys.h>
+#include <acess/devices/pty.h>
+}
-namespace Graphics {
+namespace AxWin {
-void Initialise(const CConfigVideo& config)
+CVideo::CVideo(const CConfigVideo& config):
+ m_fd(0)
{
+ {
+ if( _SysIOCtl(m_fd, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL )
+ throw AxWin::InitFailure("stdin isn't a terminal");
+ struct ptydims dims;
+ if( _SysIOCtl(m_fd, PTY_IOCTL_GETDIMS, &dims) == -1 )
+ throw AxWin::InitFailure("Failed to get dimensions from stdin");
+ m_width = dims.PW;
+ m_height = dims.PH;
+ if( m_width == 0 || m_height == 0 )
+ throw AxWin::InitFailure("Terminal not capable of graphics");
+ }
}
-};
+void CVideo::BlitLine(const uint32_t* src, unsigned int dst_y, unsigned int dst_x, unsigned int width)
+{
+ //_SysWriteAt(m_fd, (dst_y * m_width + dst_x) * 4, width * 4, src);
+ _SysSeek(m_fd, (dst_y * m_width + dst_x) * 4, SEEK_SET);
+ _SysWrite(m_fd, src, width * 4);
+}
}; // namespace AxWin