Cleaning for opengl rendering prep.

This commit is contained in:
James Grogan 2022-11-14 11:19:51 +00:00
parent 402f381d10
commit 7c6a92f4ec
58 changed files with 570 additions and 533 deletions

View file

@ -24,16 +24,13 @@ list(APPEND ui_elements_LIB_INCLUDES
add_library(ui_elements SHARED ${ui_elements_LIB_INCLUDES})
target_include_directories(ui_elements PUBLIC
"${PROJECT_SOURCE_DIR}/src/core/"
"${PROJECT_SOURCE_DIR}/src/geometry/"
"${PROJECT_SOURCE_DIR}/src/visual_elements"
"${CMAKE_CURRENT_SOURCE_DIR}/"
"${CMAKE_CURRENT_SOURCE_DIR}/widgets"
"${CMAKE_CURRENT_SOURCE_DIR}/widgets/elements"
"${CMAKE_CURRENT_SOURCE_DIR}/ui_events"
"${CMAKE_CURRENT_SOURCE_DIR}/desktop_elements"
)
target_link_libraries(ui_elements PUBLIC core geometry visual_elements image)
target_link_libraries(ui_elements PUBLIC core geometry graphics visual_elements image)
set_property(TARGET ui_elements PROPERTY FOLDER src)

View file

@ -12,7 +12,8 @@ class IPlatformSurface
{
public:
virtual ~IPlatformSurface() = default;
virtual void paint(mt::Screen* screen) = 0;
virtual void beforePaint(mt::Screen* screen) = 0;
virtual void afterPaint(mt::Screen* screen) = 0;
};
class IPlatformWindow : public IPlatformSurface
@ -31,6 +32,7 @@ public:
virtual void map() = 0;
virtual void clear() = 0;
protected:
mt::Window* mWindow{nullptr};
};

View file

@ -1,23 +1,30 @@
#include "Window.h"
#include "IPlatformWindow.h"
#include "PaintEvent.h"
#include "MouseEvent.h"
#include "VisualLayer.h"
#include "KeyboardEvent.h"
#include "Image.h"
#include "Widget.h"
#include "VisualLayer.h"
#include "Scene.h"
#include "TriMesh.h"
#include "AbstractPainter.h"
#include "DrawingContext.h"
#include "IPlatformWindow.h"
#include "Screen.h"
#include "Image.h"
namespace mt
{
Window::Window()
:mWidth(800),
mHeight(600),
mBackingImage(std::make_unique<Image<uint8_t> >(mWidth, mHeight)),
mWidget(Widget::Create())
: DrawingSurface(),
mWidget(Widget::Create())
{
mWidget->setBounds(mWidth, mHeight);
mWidth = 800;
mHeight = 600;
}
Window::~Window()
@ -30,33 +37,27 @@ std::unique_ptr<Window> Window::Create()
return std::make_unique<Window>();
}
std::vector<VisualLayer*> Window::GetLayers()
{
return mWidget->getLayers();
}
void Window::clearPlatformWindow()
{
mPlatformWindow.reset();
}
void Window::OnMouseEvent(const MouseEvent* event)
void Window::onMouseEvent(const MouseEvent* event)
{
mWidget->onMouseEvent(event);
}
void Window::OnKeyboardEvent(const KeyboardEvent* event)
void Window::onKeyboardEvent(const KeyboardEvent* event)
{
mWidget->onKeyboardEvent(event);
}
void Window::OnPaint(const PaintEvent* event)
void Window::onPaint(const PaintEvent* event)
{
mWidget->onPaintEvent(event);
}
void Window::AddWidget(WidgetUPtr widget)
void Window::setWidget(WidgetPtr widget)
{
if (mWidget)
{
@ -66,29 +67,7 @@ void Window::AddWidget(WidgetUPtr widget)
mWidget->setBounds(mWidth, mHeight);
}
Widget* Window::GetWidget() const
{
return mWidget.get();
}
unsigned Window::GetWidth() const
{
return mWidth;
}
unsigned Window::GetHeight() const
{
return mHeight;
}
void Window::SetSize(unsigned width, unsigned height)
{
mWidth = width;
mHeight = height;
mWidget->setBounds(mWidth, mHeight);
}
IPlatformWindow* Window::GetPlatformWindow() const
IPlatformWindow* Window::getPlatformWindow() const
{
if (mPlatformWindow)
{
@ -97,14 +76,10 @@ IPlatformWindow* Window::GetPlatformWindow() const
return nullptr;
}
void Window::SetPlatformWindow(IPlatformWindowPtr window)
void Window::setPlatformWindow(IPlatformWindowPtr window, DrawingMode drawingMode)
{
mPlatformWindow = std::move(window);
}
Image<uint8_t>* Window::getBackingImage() const
{
return mBackingImage.get();
mDrawingContext = std::make_unique<DrawingContext>(this, drawingMode);
}
void Window::map()
@ -127,7 +102,13 @@ void Window::doPaint(mt::Screen* screen)
{
if (mPlatformWindow)
{
mPlatformWindow->paint(screen);
mPlatformWindow->beforePaint(screen);
mDrawingContext->getScene()->setLayers(mWidget->getLayers());
mDrawingContext->paint();
mPlatformWindow->afterPaint(screen);
}
}

View file

@ -1,7 +1,6 @@
#pragma once
#include "Widget.h"
#include "Image.h"
#include "DrawingSurface.h"
#include <memory>
#include <vector>
@ -10,7 +9,11 @@
class PaintEvent;
class MouseEvent;
class KeyboardEvent;
class VisualLayer;
class DrawingContext;
enum class DrawingMode;
class Widget;
using WidgetPtr = std::unique_ptr<Widget>;
class IPlatformWindow;
using IPlatformWindowPtr = std::unique_ptr<IPlatformWindow>;
@ -19,7 +22,7 @@ namespace mt
class Screen;
class Window
class Window : public DrawingSurface
{
public:
@ -30,29 +33,17 @@ public:
static std::unique_ptr<Window> Create();
void AddWidget(WidgetUPtr widget);
void setWidget(WidgetPtr widget);
Widget* GetWidget() const;
void onPaint(const PaintEvent* event);
std::vector<VisualLayer*> GetLayers();
void onMouseEvent(const MouseEvent* event);
unsigned GetWidth() const;
void onKeyboardEvent(const KeyboardEvent* event);
unsigned GetHeight() const;
IPlatformWindow* getPlatformWindow() const;
void SetSize(unsigned width, unsigned height);
void OnPaint(const PaintEvent* event);
void OnMouseEvent(const MouseEvent* event);
void OnKeyboardEvent(const KeyboardEvent* event);
IPlatformWindow* GetPlatformWindow() const;
void SetPlatformWindow(IPlatformWindowPtr window);
Image<uint8_t>* getBackingImage() const;
void setPlatformWindow(IPlatformWindowPtr window, DrawingMode drawingMode);
void map();
@ -65,12 +56,9 @@ public:
void clearPlatformWindow();
private:
int mHandle {-1};
WidgetUPtr mWidget {nullptr};
unsigned mWidth {800};
unsigned mHeight {600};
WidgetPtr mWidget {nullptr};
IPlatformWindowPtr mPlatformWindow {nullptr};
std::unique_ptr<Image<uint8_t> > mBackingImage;
std::unique_ptr<DrawingContext> mDrawingContext;
};
}