Cleaning for opengl rendering prep.
This commit is contained in:
parent
402f381d10
commit
7c6a92f4ec
58 changed files with 570 additions and 533 deletions
|
@ -8,9 +8,6 @@ endif()
|
|||
|
||||
# Sample Console
|
||||
add_executable(sample_console console-main.cpp)
|
||||
target_include_directories(sample_console PUBLIC
|
||||
"${PROJECT_SOURCE_DIR}/src/console"
|
||||
)
|
||||
target_link_libraries(sample_console PUBLIC console core network
|
||||
database geometry audio web)
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ MediaTool::MediaTool(std::unique_ptr<CommandLineArgs> args)
|
|||
|
||||
void MediaTool::initializeViews()
|
||||
{
|
||||
auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow();
|
||||
mainWindow->SetSize(800, 600);
|
||||
auto mainWindow = mDesktopManager->getWindowManager()->getMainWindow();
|
||||
mainWindow->setSize(800, 600);
|
||||
|
||||
/*
|
||||
auto tabbedPanel = TabbedPanelWidget::Create();
|
||||
|
@ -65,5 +65,5 @@ void MediaTool::initializeViews()
|
|||
horizontal_spacer->addWidgetWithScale(std::move(button), 1);
|
||||
horizontal_spacer->addWidgetWithScale(std::move(background_widget), 1);
|
||||
|
||||
mainWindow->AddWidget(std::move(horizontal_spacer));
|
||||
mainWindow->setWidget(std::move(horizontal_spacer));
|
||||
}
|
||||
|
|
|
@ -70,8 +70,6 @@ list(APPEND audio_LIB_INCLUDES
|
|||
add_library(audio SHARED ${audio_LIB_INCLUDES} ${platform_INCLUDES} ${audio_HEADERS} ${platform_HEADERS})
|
||||
target_include_directories(audio PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/src/core/file_utilities"
|
||||
"${PROJECT_SOURCE_DIR}/src/core/loggers"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/audio_interfaces"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/midi"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/midi/reader"
|
||||
|
|
|
@ -20,8 +20,6 @@ target_include_directories(client PUBLIC
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/audio_editor"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/image_editor"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/web_client"
|
||||
"${PROJECT_SOURCE_DIR}/src/console"
|
||||
"${PROJECT_SOURCE_DIR}/src/ui_elements/widgets"
|
||||
)
|
||||
set_property(TARGET client PROPERTY FOLDER src)
|
||||
set_target_properties( client PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
|
@ -39,7 +39,6 @@ void GuiApplication::setUiInterfaceBackend(UiInterfaceFactory::Backend backend)
|
|||
|
||||
void GuiApplication::run()
|
||||
{
|
||||
auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow();
|
||||
initializeViews();
|
||||
|
||||
MLOG_INFO("Creating Window Interface");
|
||||
|
|
|
@ -5,18 +5,7 @@ list(APPEND console_LIB_INCLUDES MainApplication.cpp)
|
|||
add_library(console SHARED ${console_LIB_INCLUDES} ${console_HEADERS})
|
||||
|
||||
target_include_directories(console PUBLIC
|
||||
"${PROJECT_SOURCE_DIR}/src/core/"
|
||||
"${PROJECT_SOURCE_DIR}/src/core/file_utilities"
|
||||
"${PROJECT_SOURCE_DIR}/src/core/loggers"
|
||||
"${PROJECT_SOURCE_DIR}/src/database"
|
||||
"${PROJECT_SOURCE_DIR}/src/database/database_interfaces"
|
||||
"${PROJECT_SOURCE_DIR}/src/network"
|
||||
"${PROJECT_SOURCE_DIR}/src/network/sockets"
|
||||
"${PROJECT_SOURCE_DIR}/src/audio"
|
||||
"${PROJECT_SOURCE_DIR}/src/audio/midi"
|
||||
"${PROJECT_SOURCE_DIR}/src/audio/audio_interfaces"
|
||||
"${PROJECT_SOURCE_DIR}/src/graphics"
|
||||
"${PROJECT_SOURCE_DIR}/src/web"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
)
|
||||
set_property(TARGET console PROPERTY FOLDER src)
|
||||
target_link_libraries(console PUBLIC core audio network database web graphics)
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
#include "DrawingManager.h"
|
||||
#include "DrawingSurface.h"
|
||||
#include "DrawingContext.h"
|
||||
#include "Rasterizer.h"
|
||||
#include "Grid.h"
|
||||
#include "Image.h"
|
||||
#include "TriMesh.h"
|
||||
|
||||
#include "AbstractPainter.h"
|
||||
#include "TextNode.h"
|
||||
#include "DiscretePoint.h"
|
||||
#include "Scene.h"
|
||||
|
||||
|
||||
#include <filesystem>
|
||||
|
|
|
@ -41,6 +41,7 @@ target_include_directories(core PUBLIC
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/loggers"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/memory"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/streams"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/http"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/data_structures"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/serializers"
|
||||
)
|
||||
|
|
|
@ -1,15 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
class Rectangle;
|
||||
class Point;
|
||||
|
||||
template<class T>
|
||||
class Grid;
|
||||
|
||||
class AbstractGeometricItem
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~AbstractGeometricItem() = default;
|
||||
struct Bounds
|
||||
{
|
||||
Bounds(double width, double height)
|
||||
: mWidth(width),
|
||||
mHeight(height)
|
||||
{
|
||||
|
||||
//Rectangle GetBounds() const = 0;
|
||||
}
|
||||
|
||||
virtual void Sample(Grid* grid) const = 0;
|
||||
double mWidth{0.0};
|
||||
double mHeight{0.0};
|
||||
};
|
||||
|
||||
virtual ~AbstractGeometricItem() = default;
|
||||
|
||||
virtual Bounds getSize() const = 0;
|
||||
|
||||
virtual const Point& getLocation() const = 0;
|
||||
|
||||
virtual void sample(Grid<unsigned char>* grid) const = 0;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
#include "Grid.h"
|
||||
|
||||
template<typename T>
|
||||
Grid<T>::Grid(const Rectangle& bounds)
|
||||
: mBounds(bounds)
|
||||
{
|
||||
mValues = std::vector<T>(mNumX*mNumY, T());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const Rectangle& Grid<T>::getBounds() const
|
||||
{
|
||||
return mBounds;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double Grid<T>::getXSpacing() const
|
||||
{
|
||||
return mBounds.getWidth()/double(mNumX);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double Grid<T>::getYSpacing() const
|
||||
{
|
||||
return mBounds.getHeight()/double(mNumY);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const std::vector<T>& Grid<T>::getValues() const
|
||||
{
|
||||
return mValues;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Grid<T>::resetBounds(const Rectangle& bounds)
|
||||
{
|
||||
mBounds = bounds;
|
||||
mValues = std::vector<T>(mNumX*mNumY, T());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Grid<T>::setValues(const std::vector<std::size_t>& indices, T value)
|
||||
{
|
||||
for (auto index : indices)
|
||||
{
|
||||
mValues[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
template class Grid<unsigned char>;
|
|
@ -3,54 +3,28 @@
|
|||
#include "Rectangle.h"
|
||||
#include <vector>
|
||||
|
||||
template<typename T>
|
||||
class Grid
|
||||
{
|
||||
public:
|
||||
|
||||
Grid(const Rectangle& bounds)
|
||||
: mBounds(bounds)
|
||||
{
|
||||
mValues = std::vector<double>(mNumX*mNumY, 0.0);
|
||||
}
|
||||
Grid(const Rectangle& bounds);
|
||||
|
||||
Rectangle GetBounds() const
|
||||
{
|
||||
return mBounds;
|
||||
}
|
||||
const Rectangle& getBounds() const;
|
||||
|
||||
double GetXSpacing() const
|
||||
{
|
||||
return mBounds.GetWidth()/double(mNumX);
|
||||
}
|
||||
double getXSpacing() const;
|
||||
|
||||
double GetYSpacing() const
|
||||
{
|
||||
return mBounds.GetHeight()/double(mNumY);
|
||||
}
|
||||
double getYSpacing() const;
|
||||
|
||||
std::vector<double> GetValues() const
|
||||
{
|
||||
return mValues;
|
||||
}
|
||||
const std::vector<T>& getValues() const;
|
||||
|
||||
void ResetBounds(const Rectangle& bounds)
|
||||
{
|
||||
mBounds = bounds;
|
||||
mValues = std::vector<double>(mNumX*mNumY, 0.0);
|
||||
}
|
||||
|
||||
void SetValues(const std::vector<std::size_t>& indices, double value)
|
||||
{
|
||||
for (auto index : indices)
|
||||
{
|
||||
mValues[index] = value;
|
||||
}
|
||||
}
|
||||
void resetBounds(const Rectangle& bounds);
|
||||
|
||||
void setValues(const std::vector<std::size_t>& indices, T value);
|
||||
|
||||
private:
|
||||
Rectangle mBounds;
|
||||
std::vector<double> mValues;
|
||||
std::vector<T> mValues;
|
||||
unsigned mNumX{5};
|
||||
unsigned mNumY{5};
|
||||
};
|
||||
|
|
|
@ -1,28 +1,43 @@
|
|||
#include "LineSegment.h"
|
||||
|
||||
LineSegment::LineSegment(PointPtr p0, PointPtr p1)
|
||||
LineSegment::LineSegment(const Point& p0, const Point& p1)
|
||||
: mP0(p0),
|
||||
mP1(p1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<LineSegment> LineSegment::Create(PointPtr p0, PointPtr p1)
|
||||
std::unique_ptr<LineSegment> LineSegment::Create(const Point& p0, const Point& p1)
|
||||
{
|
||||
return std::make_shared<LineSegment>(p0, p1);
|
||||
return std::make_unique<LineSegment>(p0, p1);
|
||||
}
|
||||
|
||||
double LineSegment::getLength() const
|
||||
{
|
||||
return mP0->getDistance(mP1.get());
|
||||
return mP0.getDistance(mP1);
|
||||
}
|
||||
|
||||
Point* LineSegment::getPoint0() const
|
||||
const Point& LineSegment::getPoint0() const
|
||||
{
|
||||
return mP0.get();
|
||||
return mP0;
|
||||
}
|
||||
|
||||
Point* LineSegment::getPoint1() const
|
||||
const Point& LineSegment::getPoint1() const
|
||||
{
|
||||
return mP1.get();
|
||||
return mP1;
|
||||
}
|
||||
|
||||
void LineSegment::sample(Grid<unsigned char>* grid) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LineSegment::Bounds LineSegment::getSize() const
|
||||
{
|
||||
return {mP0.getDeltaX(mP1), mP0.getDeltaY(mP1)};
|
||||
}
|
||||
|
||||
const Point& LineSegment::getLocation() const
|
||||
{
|
||||
return mP0;
|
||||
}
|
||||
|
|
|
@ -3,25 +3,29 @@
|
|||
#include "AbstractGeometricItem.h"
|
||||
#include "Point.h"
|
||||
|
||||
template<class T>
|
||||
class Grid;
|
||||
|
||||
class LineSegment : public AbstractGeometricItem
|
||||
{
|
||||
public:
|
||||
LineSegment(PointPtr p0, PointPtr p1);
|
||||
LineSegment(const Point& p0, const Point& p1);
|
||||
|
||||
static std::shared_ptr<LineSegment> Create(PointPtr p0, PointPtr p1);
|
||||
static std::unique_ptr<LineSegment> Create(const Point& p0, const Point& p1);
|
||||
|
||||
double getLength() const;
|
||||
|
||||
Point* getPoint0() const;
|
||||
const Point& getPoint0() const;
|
||||
|
||||
Point* getPoint1() const;
|
||||
const Point& getPoint1() const;
|
||||
|
||||
void Sample(Grid* grid) const
|
||||
{
|
||||
void sample(Grid<unsigned char>* grid) const override;
|
||||
|
||||
}
|
||||
Bounds getSize() const override;
|
||||
|
||||
const Point& getLocation() const override;
|
||||
|
||||
private:
|
||||
PointPtr mP0;
|
||||
PointPtr mP1;
|
||||
Point mP0;
|
||||
Point mP1;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#include "Rectangle.h"
|
||||
|
||||
Rectangle::Rectangle(const Point& bottomLeft, const Point& topRight)
|
||||
: mBottomLeft(bottomLeft)
|
||||
{
|
||||
mHeight = mBottomLeft.getDeltaY(topRight);
|
||||
mWidth = mBottomLeft.getDeltaX(topRight);
|
||||
}
|
||||
|
||||
Rectangle Rectangle::getBounds() const
|
||||
{
|
||||
return Rectangle(mBottomLeft, Point(mBottomLeft, mWidth, mHeight));
|
||||
}
|
||||
|
||||
void Rectangle::sample(Grid<unsigned char>* grid) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
double Rectangle::getHeight() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
double Rectangle::getWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
const Point& Rectangle::getLocation() const
|
||||
{
|
||||
return mBottomLeft;
|
||||
}
|
||||
|
||||
Rectangle::Bounds Rectangle::getSize() const
|
||||
{
|
||||
return {mWidth, mHeight};
|
||||
}
|
|
@ -3,43 +3,29 @@
|
|||
#include "AbstractGeometricItem.h"
|
||||
#include "Point.h"
|
||||
|
||||
template<class T>
|
||||
class Grid;
|
||||
|
||||
class Rectangle : public AbstractGeometricItem
|
||||
{
|
||||
public:
|
||||
|
||||
Rectangle(const Point& bottomLeft, const Point& topRight)
|
||||
: mBottomLeft(bottomLeft),
|
||||
mTopRight(topRight)
|
||||
{
|
||||
Rectangle(const Point& bottomLeft, const Point& topRight);
|
||||
|
||||
}
|
||||
double getHeight() const;
|
||||
|
||||
Rectangle GetBounds() const
|
||||
{
|
||||
return Rectangle(mBottomLeft, mTopRight);
|
||||
}
|
||||
double getWidth() const;
|
||||
|
||||
void Sample(Grid* grid) const override
|
||||
{
|
||||
const Point& getLocation() const override;
|
||||
|
||||
}
|
||||
Bounds getSize() const override;
|
||||
|
||||
double GetHeight() const
|
||||
{
|
||||
return mBottomLeft.getDeltaY(mTopRight);
|
||||
}
|
||||
Rectangle getBounds() const;
|
||||
|
||||
double GetWidth() const
|
||||
{
|
||||
return mBottomLeft.getDeltaX(mTopRight);
|
||||
}
|
||||
|
||||
Point getBottomLeft() const
|
||||
{
|
||||
return mBottomLeft;
|
||||
}
|
||||
void sample(Grid<unsigned char>* grid) const override;
|
||||
|
||||
private:
|
||||
Point mBottomLeft;
|
||||
Point mTopRight;
|
||||
double mWidth{0};
|
||||
double mHeight{0};
|
||||
};
|
||||
|
|
10
src/graphics/AbstractPainter.h
Normal file
10
src/graphics/AbstractPainter.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
class DrawingContext;
|
||||
|
||||
class AbstractPainter
|
||||
{
|
||||
public:
|
||||
virtual ~AbstractPainter() = default;
|
||||
virtual void paint(DrawingContext* context) = 0;
|
||||
};
|
|
@ -7,23 +7,21 @@ list(APPEND graphics_LIB_INCLUDES
|
|||
DrawingContext.cpp
|
||||
DrawingManager.cpp
|
||||
DrawingSurface.cpp
|
||||
Rasterizer.cpp
|
||||
RasterPainter.cpp
|
||||
${platform_LIB_INCLUDES}
|
||||
)
|
||||
|
||||
list(APPEND graphics_HEADERS
|
||||
${platform_HEADERS}
|
||||
Rasterizer.h
|
||||
INativeDrawingSurface.h
|
||||
INativeDrawingContext.h
|
||||
RasterPainter.h
|
||||
)
|
||||
|
||||
set(OpenGL_GL_PREFERENCE "GLVND")
|
||||
find_package(OpenGL QUIET)
|
||||
if (OpenGL_FOUND)
|
||||
list(APPEND platform_LIBS OpenGL::GL)
|
||||
list(APPEND graphics_LIB_INCLUDES opengl/OpenGlInterface.cpp)
|
||||
list(APPEND graphics_HEADERS opengl/OpenGlInterface.h)
|
||||
list(APPEND graphics_LIB_INCLUDES opengl/OpenGlPainter.cpp)
|
||||
list(APPEND graphics_HEADERS opengl/OpenGlPainter.h)
|
||||
else()
|
||||
message(STATUS "OpenGL headers not found - skipping OpenGL support")
|
||||
endif()
|
||||
|
@ -35,11 +33,7 @@ add_library(graphics SHARED
|
|||
target_include_directories(graphics PUBLIC
|
||||
${platform_INCLUDE_DIRS}
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cairo"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/opengl"
|
||||
"${PROJECT_SOURCE_DIR}/src/geometry/"
|
||||
"${PROJECT_SOURCE_DIR}/src/image/"
|
||||
"${PROJECT_SOURCE_DIR}/src/visual_elements/"
|
||||
)
|
||||
|
||||
target_link_libraries(graphics PUBLIC visual_elements image ${platform_LIBS})
|
||||
|
|
|
@ -1,43 +1,53 @@
|
|||
#include "DrawingContext.h"
|
||||
|
||||
#include "INativeDrawingContext.h"
|
||||
#include "AbstractGeometricItem.h"
|
||||
#include "AbstractPainter.h"
|
||||
#include "OpenGlPainter.h"
|
||||
#include "RasterPainter.h"
|
||||
#include "DrawingSurface.h"
|
||||
#include "Scene.h"
|
||||
#include "Grid.h"
|
||||
|
||||
#include "MeshBuilder.h"
|
||||
|
||||
#include "TriMesh.h"
|
||||
|
||||
std::unique_ptr<DrawingContext> DrawingContext::Create()
|
||||
DrawingContext::DrawingContext(DrawingSurface* surface, DrawingMode requestedDrawingMode)
|
||||
: mSurface(surface),
|
||||
mDrawingMode(requestedDrawingMode),
|
||||
mScene(std::make_unique<Scene>())
|
||||
{
|
||||
return std::make_unique<DrawingContext>();
|
||||
if (mDrawingMode == DrawingMode::GRAPH)
|
||||
{
|
||||
mPainter = std::make_unique<OpenGlPainter>();
|
||||
}
|
||||
else
|
||||
{
|
||||
mPainter = std::make_unique<RasterPainter>();
|
||||
}
|
||||
}
|
||||
|
||||
void DrawingContext::setNativeContext(std::unique_ptr<INativeDrawingContext> context)
|
||||
std::unique_ptr<DrawingContext> DrawingContext::Create(DrawingSurface* surface, DrawingMode requestedDrawingMode)
|
||||
{
|
||||
mNativeDrawingContext = std::move(context);
|
||||
}
|
||||
|
||||
INativeDrawingContext* DrawingContext::getNativeContext()
|
||||
{
|
||||
return mNativeDrawingContext.get();
|
||||
}
|
||||
|
||||
void DrawingContext::addDrawable(AbstractGeometricItemPtr item)
|
||||
{
|
||||
mItems.push_back(std::move(item));
|
||||
}
|
||||
|
||||
unsigned DrawingContext::getNumItems() const
|
||||
{
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
AbstractGeometricItem* DrawingContext::getDrawable(unsigned idx) const
|
||||
{
|
||||
return mItems[idx].get();
|
||||
return std::make_unique<DrawingContext>(surface, requestedDrawingMode);
|
||||
}
|
||||
|
||||
void DrawingContext::updateMesh()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Scene* DrawingContext::getScene() const
|
||||
{
|
||||
return mScene.get();
|
||||
}
|
||||
|
||||
DrawingSurface* DrawingContext::getSurface() const
|
||||
{
|
||||
return mSurface;
|
||||
}
|
||||
|
||||
void DrawingContext::paint()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -3,35 +3,38 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class INativeDrawingContext;
|
||||
class AbstractGeometricItem;
|
||||
using AbstractGeometricItemPtr = std::unique_ptr<AbstractGeometricItem>;
|
||||
|
||||
class Scene;
|
||||
class AbstractPainter;
|
||||
class DrawingSurface;
|
||||
class TriMesh;
|
||||
|
||||
enum class DrawingMode
|
||||
{
|
||||
RASTER,
|
||||
GRAPH
|
||||
};
|
||||
|
||||
class DrawingContext
|
||||
{
|
||||
public:
|
||||
DrawingContext() = default;
|
||||
DrawingContext(DrawingSurface* surface, DrawingMode requestedDrawingMode);
|
||||
|
||||
static std::unique_ptr<DrawingContext> Create();
|
||||
static std::unique_ptr<DrawingContext> Create(DrawingSurface* surface, DrawingMode requestedDrawingMode);
|
||||
|
||||
void setNativeContext(std::unique_ptr<INativeDrawingContext> context);
|
||||
Scene* getScene() const;
|
||||
|
||||
INativeDrawingContext* getNativeContext();
|
||||
DrawingSurface* getSurface() const;
|
||||
|
||||
unsigned getNumItems() const;
|
||||
|
||||
void addDrawable(AbstractGeometricItemPtr item);
|
||||
|
||||
AbstractGeometricItem* getDrawable(unsigned idx) const;
|
||||
void paint();
|
||||
|
||||
private:
|
||||
void updateMesh();
|
||||
|
||||
DrawingMode mDrawingMode;
|
||||
std::unique_ptr<TriMesh> mMesh;
|
||||
std::vector<std::unique_ptr<AbstractGeometricItem> > mItems;
|
||||
std::unique_ptr<INativeDrawingContext> mNativeDrawingContext;
|
||||
std::unique_ptr<Scene> mScene;
|
||||
DrawingSurface* mSurface{nullptr};
|
||||
std::unique_ptr<AbstractPainter> mPainter;
|
||||
};
|
||||
|
||||
using DrawingContextPtr = std::unique_ptr<DrawingContext>;
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
#include "DrawingManager.h"
|
||||
|
||||
#include "INativeDrawingContext.h"
|
||||
#include "DrawingSurface.h"
|
||||
#include "DrawingContext.h"
|
||||
#include "Rasterizer.h"
|
||||
#include "AbstractPainter.h"
|
||||
|
||||
#include "Grid.h"
|
||||
#include "Image.h"
|
||||
#include "TriMesh.h"
|
||||
#include "Scene.h"
|
||||
|
||||
DrawingManager::DrawingManager()
|
||||
: mRasterizer(std::make_unique<Rasterizer>())
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -23,12 +22,12 @@ std::unique_ptr<DrawingManager> DrawingManager::Create()
|
|||
void DrawingManager::InitalizeSurface(unsigned width, unsigned height)
|
||||
{
|
||||
mDrawingSurface = DrawingSurface::Create();
|
||||
mDrawingSurface->SetSize(width, height);
|
||||
mDrawingSurface->setSize(width, height);
|
||||
}
|
||||
|
||||
void DrawingManager::InitializeContext()
|
||||
{
|
||||
mDrawingContext = DrawingContext::Create();
|
||||
//mDrawingContext = DrawingContext::Create();
|
||||
}
|
||||
|
||||
void DrawingManager::AddText(TextNode* text)
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "INativeDrawingContext.h"
|
||||
#include "INativeDrawingSurface.h"
|
||||
|
||||
class TextNode;
|
||||
|
||||
|
@ -12,8 +10,6 @@ using DrawingSurfacePtr = std::unique_ptr<DrawingSurface>;
|
|||
class DrawingContext;
|
||||
using DrawingContextPtr = std::unique_ptr<DrawingContext>;
|
||||
|
||||
class Rasterizer;
|
||||
|
||||
class DrawingManager
|
||||
{
|
||||
public:
|
||||
|
@ -25,7 +21,6 @@ public:
|
|||
void RenderToFile(const std::string& path);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Rasterizer> mRasterizer;
|
||||
DrawingSurfacePtr mDrawingSurface {nullptr};
|
||||
DrawingContextPtr mDrawingContext {nullptr};
|
||||
};
|
||||
|
|
|
@ -7,40 +7,28 @@ std::unique_ptr<DrawingSurface> DrawingSurface::Create()
|
|||
return std::make_unique<DrawingSurface>();
|
||||
}
|
||||
|
||||
INativeDrawingSurface* DrawingSurface::GetNativeSurface()
|
||||
{
|
||||
if (mNativeDrawingSurface)
|
||||
{
|
||||
return mNativeDrawingSurface.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawingSurface::SetNativeSurface(std::unique_ptr<INativeDrawingSurface> surface)
|
||||
{
|
||||
mNativeDrawingSurface = std::move(surface);
|
||||
}
|
||||
|
||||
void DrawingSurface::SetSize(unsigned width, unsigned height)
|
||||
void DrawingSurface::setSize(unsigned width, unsigned height)
|
||||
{
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
||||
unsigned DrawingSurface::GetWidth() const
|
||||
unsigned DrawingSurface::getWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned DrawingSurface::GetHeight() const
|
||||
unsigned DrawingSurface::getHeight() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
void DrawingSurface::Paint(Grid* grid)
|
||||
Image<unsigned char>* DrawingSurface::getImage()
|
||||
{
|
||||
//mImageBuffer = std::make_unique<Image>();
|
||||
if (!mBackingImage)
|
||||
{
|
||||
mBackingImage = std::make_unique<Image<unsigned char> >(mWidth, mHeight);
|
||||
mBackingImage->initialize();
|
||||
}
|
||||
return mBackingImage.get();
|
||||
}
|
||||
|
|
|
@ -2,36 +2,27 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include "INativeDrawingSurface.h"
|
||||
#include "Image.h"
|
||||
|
||||
class Grid;
|
||||
template<typename T>
|
||||
class Image;
|
||||
|
||||
class DrawingSurface
|
||||
{
|
||||
public:
|
||||
DrawingSurface() = default;
|
||||
virtual ~DrawingSurface() = default;
|
||||
|
||||
static std::unique_ptr<DrawingSurface> Create();
|
||||
|
||||
INativeDrawingSurface* GetNativeSurface();
|
||||
void setSize(unsigned width, unsigned height);
|
||||
|
||||
void SetNativeSurface(std::unique_ptr<INativeDrawingSurface> surface);
|
||||
unsigned getWidth() const;
|
||||
|
||||
void SetSize(unsigned width, unsigned height);
|
||||
unsigned getHeight() const;
|
||||
|
||||
unsigned GetWidth() const;
|
||||
|
||||
unsigned GetHeight() const;
|
||||
|
||||
void Paint(Grid* grid);
|
||||
|
||||
Image<unsigned char>* GetAsImage() const;
|
||||
|
||||
private:
|
||||
Image<unsigned char>* getImage();
|
||||
|
||||
protected:
|
||||
unsigned mWidth = 0;
|
||||
unsigned mHeight = 0;
|
||||
std::unique_ptr<Image<unsigned char> > mImageBuffer;
|
||||
std::unique_ptr<INativeDrawingSurface> mNativeDrawingSurface;
|
||||
std::unique_ptr<Image<unsigned char> > mBackingImage;
|
||||
};
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
class INativeDrawingContext
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~INativeDrawingContext() = default;
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
class INativeDrawingSurface
|
||||
{
|
||||
public:
|
||||
virtual ~INativeDrawingSurface() = default;
|
||||
|
||||
virtual void DestroyNativeSurface() = 0;
|
||||
};
|
27
src/graphics/RasterPainter.cpp
Normal file
27
src/graphics/RasterPainter.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "RasterPainter.h"
|
||||
|
||||
#include "DrawingSurface.h"
|
||||
#include "DrawingContext.h"
|
||||
#include "Grid.h"
|
||||
|
||||
RasterPainter::RasterPainter()
|
||||
: mGrid(std::make_unique<Grid<unsigned char> >(Rectangle(Point(0, 0), Point(100, 100))))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RasterPainter::paint(DrawingContext* context)
|
||||
{
|
||||
const auto width = context->getSurface()->getWidth();
|
||||
const auto height = context->getSurface()->getHeight();
|
||||
mGrid->resetBounds(Rectangle(Point(0, 0), Point(width, height)));
|
||||
|
||||
/*
|
||||
for (unsigned idx=0; idx< context->getNumItems(); idx++)
|
||||
{
|
||||
context->getDrawable(idx)->sample(mGrid.get());
|
||||
}
|
||||
|
||||
context->getSurface()->getImage()->setData(mGrid->getValues());
|
||||
*/
|
||||
}
|
20
src/graphics/RasterPainter.h
Normal file
20
src/graphics/RasterPainter.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include "AbstractPainter.h"
|
||||
#include <memory>
|
||||
|
||||
class DrawingContext;
|
||||
|
||||
template<class T>
|
||||
class Grid;
|
||||
|
||||
class RasterPainter : public AbstractPainter
|
||||
{
|
||||
public:
|
||||
RasterPainter();
|
||||
|
||||
void paint(DrawingContext* context) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Grid<unsigned char> > mGrid;
|
||||
};
|
|
@ -1,25 +0,0 @@
|
|||
#include "Rasterizer.h"
|
||||
|
||||
#include "DrawingSurface.h"
|
||||
#include "DrawingContext.h"
|
||||
#include "Grid.h"
|
||||
|
||||
Rasterizer::Rasterizer()
|
||||
: mGrid(std::make_unique<Grid>(Rectangle(Point(0, 0), Point(100, 100))))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Rasterizer::Paint(DrawingSurface* surface, DrawingContext* context)
|
||||
{
|
||||
const auto width = surface->GetWidth();
|
||||
const auto height = surface->GetHeight();
|
||||
mGrid->ResetBounds(Rectangle(Point(0, 0), Point(width, height)));
|
||||
|
||||
for (unsigned idx=0; idx< context->getNumItems(); idx++)
|
||||
{
|
||||
context->getDrawable(idx)->Sample(mGrid.get());
|
||||
}
|
||||
|
||||
surface->Paint(mGrid.get());
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class DrawingSurface;
|
||||
class DrawingContext;
|
||||
class Grid;
|
||||
|
||||
class Rasterizer
|
||||
{
|
||||
public:
|
||||
Rasterizer();
|
||||
|
||||
void Paint(DrawingSurface* surface, DrawingContext* context);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Grid> mGrid;
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
class TriMesh;
|
||||
|
||||
class OpenGlInterface
|
||||
{
|
||||
public:
|
||||
static void draw(TriMesh* mesh);
|
||||
};
|
||||
|
||||
|
|
@ -1,11 +1,14 @@
|
|||
#include "OpenGlInterface.h"
|
||||
#include "OpenGlPainter.h"
|
||||
|
||||
#include "DrawingContext.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
void OpenGlInterface::draw(TriMesh* mesh)
|
||||
void OpenGlPainter::paint(DrawingContext* context)
|
||||
{
|
||||
glClearColor(0.4, 0.4, 0.4, 0.4);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
@ -13,8 +16,6 @@ void OpenGlInterface::draw(TriMesh* mesh)
|
|||
glColor3f(1.0, 1.0, 1.0);
|
||||
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
|
||||
|
||||
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
glVertex3f(-0.7, 0.7, 0);
|
||||
glVertex3f(0.7, 0.7, 0);
|
13
src/graphics/opengl/OpenGlPainter.h
Normal file
13
src/graphics/opengl/OpenGlPainter.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "AbstractPainter.h"
|
||||
|
||||
class DrawingContext;
|
||||
|
||||
class OpenGlPainter : public AbstractPainter
|
||||
{
|
||||
public:
|
||||
void paint(DrawingContext* context) override;
|
||||
};
|
||||
|
||||
|
|
@ -23,7 +23,6 @@ target_include_directories(network PUBLIC
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sockets"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/web"
|
||||
"${PROJECT_SOURCE_DIR}/src/core/http"
|
||||
)
|
||||
set_target_properties( network PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
||||
target_link_libraries( network PUBLIC core)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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};
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -3,17 +3,17 @@ list(APPEND visual_elements_LIB_INCLUDES
|
|||
RectangleNode.cpp
|
||||
TextNode.cpp
|
||||
VisualLayer.cpp
|
||||
Scene.cpp
|
||||
)
|
||||
|
||||
add_library(visual_elements SHARED ${visual_elements_LIB_INCLUDES})
|
||||
|
||||
target_include_directories(visual_elements PUBLIC
|
||||
"${PROJECT_SOURCE_DIR}/src/core/"
|
||||
"${PROJECT_SOURCE_DIR}/src/geometry/"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
)
|
||||
|
||||
target_link_libraries(visual_elements PUBLIC core geometry mesh image)
|
||||
|
||||
set_property(TARGET visual_elements PROPERTY FOLDER src)
|
||||
|
||||
set_target_properties( visual_elements PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
||||
set_target_properties( visual_elements PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
||||
|
|
23
src/visual_elements/Scene.h
Normal file
23
src/visual_elements/Scene.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
class VisualLayer;
|
||||
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene() = default;
|
||||
|
||||
void setLayers(const std::vector<VisualLayer*>& layers)
|
||||
{
|
||||
mLayers = layers;
|
||||
}
|
||||
|
||||
const std::vector<VisualLayer*>& getLayers() const
|
||||
{
|
||||
return mLayers;
|
||||
}
|
||||
private:
|
||||
std::vector<VisualLayer*> mLayers;
|
||||
};
|
|
@ -23,9 +23,6 @@ list(APPEND web_LIB_INCLUDES
|
|||
add_library(web SHARED ${web_LIB_INCLUDES})
|
||||
|
||||
target_include_directories(web PUBLIC
|
||||
"${PROJECT_SOURCE_DIR}/src/core/"
|
||||
"${PROJECT_SOURCE_DIR}/src/core/loggers"
|
||||
"${PROJECT_SOURCE_DIR}/src/core/file_utilities"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/xml"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/xml/xml-elements"
|
||||
|
|
|
@ -88,11 +88,6 @@ target_include_directories(windows PUBLIC
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/x11"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/wayland"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/win32"
|
||||
"${PROJECT_SOURCE_DIR}/src/core"
|
||||
"${PROJECT_SOURCE_DIR}/src/geometry"
|
||||
"${PROJECT_SOURCE_DIR}/src/graphics"
|
||||
"${PROJECT_SOURCE_DIR}/src/ui_elements"
|
||||
"${PROJECT_SOURCE_DIR}/src/ui_elements/widgets"
|
||||
${WAYLAND_INCLUDE_DIRS}
|
||||
${X11_INCLUDE_DIRS}
|
||||
)
|
||||
|
|
|
@ -25,32 +25,32 @@ std::unique_ptr<DesktopManager> DesktopManager::Create(AbstractDesktopApp* appli
|
|||
return std::make_unique<DesktopManager>(application);
|
||||
}
|
||||
|
||||
void DesktopManager::ClearEvents()
|
||||
void DesktopManager::clearEvents()
|
||||
{
|
||||
mEventManager->ClearEvents();
|
||||
}
|
||||
|
||||
void DesktopManager::OnKeyboardEvent(const KeyboardEvent* event)
|
||||
void DesktopManager::onKeyboardEvent(const KeyboardEvent* event)
|
||||
{
|
||||
GetWindowManager()->OnKeyboardEvent(event);
|
||||
mWindowManager->onKeyboardEvent(event);
|
||||
}
|
||||
|
||||
void DesktopManager::OnPaintEvent(const PaintEvent* event)
|
||||
void DesktopManager::onPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
GetWindowManager()->OnPaintEvent(event);
|
||||
mWindowManager->onPaintEvent(event);
|
||||
}
|
||||
|
||||
void DesktopManager::OnMouseEvent(const MouseEvent* event)
|
||||
void DesktopManager::onMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
GetWindowManager()->OnMouseEvent(event);
|
||||
mWindowManager->onMouseEvent(event);
|
||||
}
|
||||
|
||||
bool DesktopManager::IsModified() const
|
||||
bool DesktopManager::isModified() const
|
||||
{
|
||||
return mModified;
|
||||
}
|
||||
|
||||
void DesktopManager::OnUiEvent(UiEventUPtr eventUPtr)
|
||||
void DesktopManager::onUiEvent(UiEventUPtr eventUPtr)
|
||||
{
|
||||
mModified = false;
|
||||
const auto event = mEventManager->AddEvent(std::move(eventUPtr));
|
||||
|
@ -58,19 +58,19 @@ void DesktopManager::OnUiEvent(UiEventUPtr eventUPtr)
|
|||
{
|
||||
case (UiEvent::Type::Paint):
|
||||
{
|
||||
OnPaintEvent(dynamic_cast<const PaintEvent*>(event));
|
||||
onPaintEvent(dynamic_cast<const PaintEvent*>(event));
|
||||
break;
|
||||
}
|
||||
case (UiEvent::Type::Keyboard):
|
||||
{
|
||||
OnKeyboardEvent(dynamic_cast<const KeyboardEvent*>(event));
|
||||
onKeyboardEvent(dynamic_cast<const KeyboardEvent*>(event));
|
||||
mModified = true;
|
||||
break;
|
||||
}
|
||||
case (UiEvent::Type::Mouse):
|
||||
{
|
||||
auto mouseEvent = dynamic_cast<const MouseEvent*>(event);
|
||||
OnMouseEvent(mouseEvent);
|
||||
onMouseEvent(mouseEvent);
|
||||
if (mouseEvent->GetAction() == MouseEvent::Action::Pressed)
|
||||
{
|
||||
mModified = true;
|
||||
|
@ -86,17 +86,17 @@ void DesktopManager::OnUiEvent(UiEventUPtr eventUPtr)
|
|||
}
|
||||
}
|
||||
|
||||
void DesktopManager::SetIsModified(bool modified)
|
||||
void DesktopManager::setIsModified(bool modified)
|
||||
{
|
||||
mModified = modified;
|
||||
}
|
||||
|
||||
Keyboard* DesktopManager::GetKeyboard() const
|
||||
Keyboard* DesktopManager::getKeyboard() const
|
||||
{
|
||||
return mKeyboard.get();
|
||||
}
|
||||
|
||||
void DesktopManager::SetKeyboard(KeyboardUPtr keyboard)
|
||||
void DesktopManager::setKeyboard(KeyboardUPtr keyboard)
|
||||
{
|
||||
mKeyboard = std::move(keyboard);
|
||||
}
|
||||
|
@ -106,12 +106,12 @@ AbstractApp* DesktopManager::getMainApp() const
|
|||
return mUiApplication->getMainApplication();
|
||||
}
|
||||
|
||||
void DesktopManager::AddScreen(ScreenPtr screen)
|
||||
void DesktopManager::addScreen(ScreenPtr screen)
|
||||
{
|
||||
mScreens.push_back(std::move(screen));
|
||||
}
|
||||
|
||||
mt::Screen* DesktopManager::GetDefaultScreen() const
|
||||
mt::Screen* DesktopManager::getDefaultScreen() const
|
||||
{
|
||||
if (mScreens.size() > 0)
|
||||
{
|
||||
|
@ -120,12 +120,12 @@ mt::Screen* DesktopManager::GetDefaultScreen() const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void DesktopManager::SetWindowManager(WindowManagerUPtr windowManager)
|
||||
void DesktopManager::setWindowManager(WindowManagerUPtr windowManager)
|
||||
{
|
||||
mWindowManager = std::move(windowManager);
|
||||
}
|
||||
|
||||
WindowManager* DesktopManager::GetWindowManager() const
|
||||
WindowManager* DesktopManager::getWindowManager() const
|
||||
{
|
||||
return mWindowManager.get();
|
||||
}
|
||||
|
|
|
@ -25,33 +25,33 @@ public:
|
|||
|
||||
static std::unique_ptr<DesktopManager> Create(AbstractDesktopApp* application);
|
||||
|
||||
void SetWindowManager(WindowManagerUPtr windowManager);
|
||||
void setWindowManager(WindowManagerUPtr windowManager);
|
||||
|
||||
AbstractApp* getMainApp() const;
|
||||
|
||||
WindowManager* GetWindowManager() const;
|
||||
WindowManager* getWindowManager() const;
|
||||
|
||||
Keyboard* GetKeyboard() const;
|
||||
Keyboard* getKeyboard() const;
|
||||
|
||||
void AddScreen(ScreenPtr screen);
|
||||
void addScreen(ScreenPtr screen);
|
||||
|
||||
mt::Screen* GetDefaultScreen() const;
|
||||
mt::Screen* getDefaultScreen() const;
|
||||
|
||||
bool IsModified() const;
|
||||
bool isModified() const;
|
||||
|
||||
void SetIsModified(bool modified);
|
||||
void setIsModified(bool modified);
|
||||
|
||||
void SetKeyboard(KeyboardUPtr keyboard);
|
||||
void setKeyboard(KeyboardUPtr keyboard);
|
||||
|
||||
void OnUiEvent(UiEventUPtr event);
|
||||
void onUiEvent(UiEventUPtr event);
|
||||
|
||||
void OnKeyboardEvent(const KeyboardEvent* keyboardEvent);
|
||||
void onKeyboardEvent(const KeyboardEvent* keyboardEvent);
|
||||
|
||||
void OnMouseEvent(const MouseEvent* mouseEvent);
|
||||
void onMouseEvent(const MouseEvent* mouseEvent);
|
||||
|
||||
void OnPaintEvent(const PaintEvent* paintEvent);
|
||||
void onPaintEvent(const PaintEvent* paintEvent);
|
||||
|
||||
void ClearEvents();
|
||||
void clearEvents();
|
||||
|
||||
private:
|
||||
std::vector<ScreenPtr> mScreens;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
WindowManager::WindowManager()
|
||||
: mWindows()
|
||||
{
|
||||
AddWindow(mt::Window::Create());
|
||||
addWindow(mt::Window::Create());
|
||||
}
|
||||
|
||||
WindowManager::~WindowManager()
|
||||
|
@ -16,22 +16,22 @@ std::unique_ptr<WindowManager> WindowManager::Create()
|
|||
return std::make_unique<WindowManager>();
|
||||
}
|
||||
|
||||
void WindowManager::OnPaintEvent(const PaintEvent* event)
|
||||
void WindowManager::onPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
GetMainWindow()->OnPaint(event);
|
||||
getMainWindow()->onPaint(event);
|
||||
}
|
||||
|
||||
void WindowManager::OnMouseEvent(const MouseEvent* event)
|
||||
void WindowManager::onMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
GetMainWindow()->OnMouseEvent(event);
|
||||
getMainWindow()->onMouseEvent(event);
|
||||
}
|
||||
|
||||
void WindowManager::OnKeyboardEvent(const KeyboardEvent* event)
|
||||
void WindowManager::onKeyboardEvent(const KeyboardEvent* event)
|
||||
{
|
||||
GetMainWindow()->OnKeyboardEvent(event);
|
||||
getMainWindow()->onKeyboardEvent(event);
|
||||
}
|
||||
|
||||
void WindowManager::AddWindow(WindowUPtr window)
|
||||
void WindowManager::addWindow(WindowUPtr window)
|
||||
{
|
||||
mWindows.push_back(std::move(window));
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ void WindowManager::clearPlatformWindows()
|
|||
}
|
||||
}
|
||||
|
||||
mt::Window* WindowManager::GetMainWindow() const
|
||||
mt::Window* WindowManager::getMainWindow() const
|
||||
{
|
||||
if(mWindows.size()>0)
|
||||
{
|
||||
|
|
|
@ -17,15 +17,15 @@ public:
|
|||
|
||||
static std::unique_ptr<WindowManager> Create();
|
||||
|
||||
void AddWindow(WindowUPtr window);
|
||||
void addWindow(WindowUPtr window);
|
||||
|
||||
mt::Window* GetMainWindow() const;
|
||||
mt::Window* getMainWindow() const;
|
||||
|
||||
void OnPaintEvent(const PaintEvent* event);
|
||||
void onPaintEvent(const PaintEvent* event);
|
||||
|
||||
void OnMouseEvent(const MouseEvent* event);
|
||||
void onMouseEvent(const MouseEvent* event);
|
||||
|
||||
void OnKeyboardEvent(const KeyboardEvent* event);
|
||||
void onKeyboardEvent(const KeyboardEvent* event);
|
||||
|
||||
void clearPlatformWindows();
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "WaylandEglWindowInterface.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
#include "OpenGlInterface.h"
|
||||
|
||||
#include <wayland-egl.h>
|
||||
|
||||
|
@ -59,7 +58,7 @@ void WaylandEglWindowInterface::initialize(wl_surface* surface, int width, int h
|
|||
}
|
||||
}
|
||||
|
||||
void WaylandEglWindowInterface::draw()
|
||||
void WaylandEglWindowInterface::beforePaint()
|
||||
{
|
||||
if (!mEglSurface)
|
||||
{
|
||||
|
@ -70,8 +69,14 @@ void WaylandEglWindowInterface::draw()
|
|||
{
|
||||
MLOG_ERROR("Made current failed");
|
||||
}
|
||||
}
|
||||
|
||||
OpenGlInterface::draw(nullptr);
|
||||
void WaylandEglWindowInterface::afterPaint()
|
||||
{
|
||||
if (!mEglSurface)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!eglSwapBuffers(mEglInterface->getDisplay(), mEglSurface))
|
||||
{
|
||||
|
|
|
@ -15,7 +15,8 @@ public:
|
|||
|
||||
void initialize(wl_surface* surface, int width, int height);
|
||||
|
||||
void draw();
|
||||
void beforePaint();
|
||||
void afterPaint();
|
||||
|
||||
private:
|
||||
wl_egl_window* mEglWindow{nullptr};
|
||||
|
|
|
@ -81,13 +81,13 @@ void WaylandInterface::initialize()
|
|||
initializeHardwareRendering();
|
||||
}
|
||||
|
||||
const auto num_windows = mDesktopManager->GetWindowManager()->getNumWindows();
|
||||
const auto num_windows = mDesktopManager->getWindowManager()->getNumWindows();
|
||||
for(std::size_t idx=0; idx< num_windows; idx++)
|
||||
{
|
||||
addWindow(mDesktopManager->GetWindowManager()->getWindow(idx));
|
||||
addWindow(mDesktopManager->getWindowManager()->getWindow(idx));
|
||||
}
|
||||
|
||||
mDesktopManager->GetWindowManager()->GetMainWindow()->show();
|
||||
mDesktopManager->getWindowManager()->getMainWindow()->show();
|
||||
}
|
||||
|
||||
void WaylandInterface::initializeHardwareRendering()
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
|
||||
#include "WaylandEglWindowInterface.h"
|
||||
#include "ImagePrimitives.h"
|
||||
#include "DrawingContext.h"
|
||||
|
||||
void WaylandSurface::add(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface)
|
||||
{
|
||||
auto wayland_window = std::make_unique<WaylandSurface>(window, compositor, xdg_wm_base, buffer, eglInterface);
|
||||
window->SetPlatformWindow(std::move(wayland_window));
|
||||
|
||||
const auto drawing_mode = eglInterface ? DrawingMode::GRAPH : DrawingMode::RASTER;
|
||||
window->setPlatformWindow(std::move(wayland_window), drawing_mode);
|
||||
}
|
||||
|
||||
WaylandSurface::WaylandSurface(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface)
|
||||
|
@ -62,7 +65,7 @@ void WaylandSurface::initialize()
|
|||
xdg_toplevel_set_title(mXdgTopLevel, "Example client");
|
||||
|
||||
auto region = wl_compositor_create_region(mCompositor);
|
||||
wl_region_add(region, 0, 0, mWindow->GetWidth(), mWindow->GetHeight());
|
||||
wl_region_add(region, 0, 0, mWindow->getWidth(), mWindow->getHeight());
|
||||
wl_surface_set_opaque_region(mSurface, region);
|
||||
|
||||
wl_surface_commit(mSurface);
|
||||
|
@ -71,56 +74,65 @@ void WaylandSurface::initialize()
|
|||
void WaylandSurface::onConfigure(xdg_surface *xdg_surface, uint32_t serial)
|
||||
{
|
||||
xdg_surface_ack_configure(xdg_surface, serial);
|
||||
paint(nullptr);
|
||||
beforePaint(nullptr);
|
||||
}
|
||||
|
||||
void WaylandSurface::paint(mt::Screen* screen)
|
||||
void WaylandSurface::beforePaint(mt::Screen* screen)
|
||||
{
|
||||
if (mEglWindowInterface)
|
||||
{
|
||||
paintHardware();
|
||||
mEglWindowInterface->initialize(mSurface, mWindow->getWidth(), mWindow->getHeight());
|
||||
mEglWindowInterface->beforePaint();
|
||||
}
|
||||
else
|
||||
{
|
||||
paintSoftware();
|
||||
beforePaintSoftware();
|
||||
}
|
||||
}
|
||||
|
||||
void WaylandSurface::paintHardware()
|
||||
void WaylandSurface::afterPaint(mt::Screen* screen)
|
||||
{
|
||||
mEglWindowInterface->initialize(mSurface, mWindow->GetWidth(), mWindow->GetHeight());
|
||||
mEglWindowInterface->draw();
|
||||
if (mEglWindowInterface)
|
||||
{
|
||||
mEglWindowInterface->afterPaint();
|
||||
}
|
||||
else
|
||||
{
|
||||
afterPaintSoftware();
|
||||
}
|
||||
}
|
||||
|
||||
void WaylandSurface::paintSoftware()
|
||||
unsigned WaylandSurface::getImageBufferSize() const
|
||||
{
|
||||
auto buffer = drawFrame();
|
||||
wl_surface_attach(mSurface, buffer, 0, 0);
|
||||
//wl_surface_damage(mSurface, 0, 0, UINT32_MAX, UINT32_MAX);
|
||||
wl_surface_commit(mSurface);
|
||||
}
|
||||
const auto width = mWindow->getWidth();
|
||||
const auto height = mWindow->getHeight();
|
||||
const int stride = width * mWorkingBitDepth;
|
||||
|
||||
wl_buffer* WaylandSurface::drawFrame()
|
||||
{
|
||||
const auto width = mWindow->GetWidth();
|
||||
const auto height = mWindow->GetHeight();
|
||||
|
||||
const int bitDepth = 4;
|
||||
|
||||
const int stride = width * bitDepth;
|
||||
//const int numBuffers = 2; // i.e. front/back
|
||||
const int numBuffers = 1;
|
||||
const int shm_pool_size = height * stride * numBuffers;
|
||||
return height * stride * mNumFrameBuffers;
|
||||
}
|
||||
|
||||
void WaylandSurface::beforePaintSoftware()
|
||||
{
|
||||
const auto width = mWindow->getWidth();
|
||||
const auto height = mWindow->getHeight();
|
||||
const int stride = width * mWorkingBitDepth;
|
||||
|
||||
const int shm_pool_size = getImageBufferSize();
|
||||
|
||||
mBuffer->initializeSharedBuffer(shm_pool_size);
|
||||
mBuffer->setUpPool(shm_pool_size, width, height, stride);
|
||||
|
||||
int offset = 0;
|
||||
|
||||
ImagePrimitives::drawCheckerboard(mBuffer->getPoolData(), width, height, offset);
|
||||
|
||||
mBuffer->tearDownPool(shm_pool_size);
|
||||
|
||||
return mBuffer->getWorkingBuffer();
|
||||
//ImagePrimitives::drawCheckerboard(mBuffer->getPoolData(), width, height, offset);
|
||||
}
|
||||
|
||||
void WaylandSurface::afterPaintSoftware()
|
||||
{
|
||||
const int shm_pool_size = getImageBufferSize();
|
||||
mBuffer->tearDownPool(shm_pool_size);
|
||||
|
||||
wl_surface_attach(mSurface, mBuffer->getWorkingBuffer(), 0, 0);
|
||||
//wl_surface_damage(mSurface, 0, 0, UINT32_MAX, UINT32_MAX);
|
||||
wl_surface_commit(mSurface);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,13 +37,13 @@ public:
|
|||
private:
|
||||
void initialize();
|
||||
|
||||
void paint(mt::Screen* screen) override;
|
||||
void beforePaint(mt::Screen* screen) override;
|
||||
void afterPaint(mt::Screen* screen) override;
|
||||
|
||||
void paintHardware();
|
||||
void paintSoftware();
|
||||
void beforePaintSoftware();
|
||||
void afterPaintSoftware();
|
||||
|
||||
|
||||
wl_buffer* drawFrame();
|
||||
unsigned getImageBufferSize() const;
|
||||
|
||||
mt::Window* mWindow{nullptr};
|
||||
|
||||
|
@ -57,6 +57,8 @@ private:
|
|||
xdg_surface_listener mXdgSurfaceListener;
|
||||
|
||||
xdg_toplevel* mXdgTopLevel{nullptr};
|
||||
unsigned mWorkingBitDepth{4};
|
||||
unsigned mNumFrameBuffers{1};
|
||||
};
|
||||
|
||||
using WaylandSurfacePtr = std::unique_ptr<WaylandSurface>;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "XcbGlWindowInterface.h"
|
||||
|
||||
#include "OpenGlInterface.h"
|
||||
#include "XcbGlInterface.h"
|
||||
#include "FileLogger.h"
|
||||
|
||||
|
@ -22,9 +21,8 @@ XcbGlWindowInterface::~XcbGlWindowInterface()
|
|||
}
|
||||
}
|
||||
|
||||
void XcbGlWindowInterface::draw()
|
||||
void XcbGlWindowInterface::afterPaint()
|
||||
{
|
||||
OpenGlInterface::draw(nullptr);
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
|
||||
bool initialize(xcb_window_t window);
|
||||
|
||||
void draw();
|
||||
void afterPaint();
|
||||
|
||||
private:
|
||||
void destroyWindow();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "Window.h"
|
||||
#include "XcbWindow.h"
|
||||
#include "Image.h"
|
||||
|
||||
class XcbImage
|
||||
{
|
||||
|
@ -11,9 +12,9 @@ public:
|
|||
XcbImage(xcb_connection_t* connection, mt::Window* window, xcb_screen_t* screen)
|
||||
{
|
||||
mPixmap = xcb_generate_id(connection);
|
||||
auto hwnd = dynamic_cast<XcbWindow*>(window->GetPlatformWindow())->getHandle();
|
||||
const auto w = window->GetWidth();
|
||||
const auto h = window->GetHeight();
|
||||
auto hwnd = dynamic_cast<XcbWindow*>(window->getPlatformWindow())->getHandle();
|
||||
const auto w = window->getWidth();
|
||||
const auto h = window->getHeight();
|
||||
xcb_create_pixmap(connection, screen->root_depth, mPixmap, hwnd, w, h);
|
||||
}
|
||||
|
||||
|
@ -21,10 +22,10 @@ public:
|
|||
{
|
||||
if (!mXImage)
|
||||
{
|
||||
auto backing_image = window->getBackingImage();
|
||||
auto backing_image = window->getImage();
|
||||
|
||||
const auto w = window->GetWidth();
|
||||
const auto h = window->GetHeight();
|
||||
const auto w = window->getWidth();
|
||||
const auto h = window->getHeight();
|
||||
|
||||
//auto data = const_cast<unsigned char*>(backing_image->getDataPtr());
|
||||
auto data = backing_image->getData();
|
||||
|
|
|
@ -40,15 +40,15 @@ void XcbInterface::initialize()
|
|||
{
|
||||
initializeHardwareRendering();
|
||||
}
|
||||
mDesktopManager->SetKeyboard(XcbKeyboard::Create());
|
||||
mDesktopManager->setKeyboard(XcbKeyboard::Create());
|
||||
|
||||
const auto num_windows = mDesktopManager->GetWindowManager()->getNumWindows();
|
||||
const auto num_windows = mDesktopManager->getWindowManager()->getNumWindows();
|
||||
for(std::size_t idx=0; idx< num_windows; idx++)
|
||||
{
|
||||
addWindow(mDesktopManager->GetWindowManager()->getWindow(idx));
|
||||
addWindow(mDesktopManager->getWindowManager()->getWindow(idx));
|
||||
}
|
||||
|
||||
mDesktopManager->GetWindowManager()->GetMainWindow()->show();
|
||||
mDesktopManager->getWindowManager()->getMainWindow()->show();
|
||||
}
|
||||
|
||||
void XcbInterface::connect()
|
||||
|
@ -96,7 +96,7 @@ void XcbInterface::updateScreen()
|
|||
auto xcb_screen = XcbScreen::Create(screen_iter.data);
|
||||
auto screen = mt::Screen::Create();
|
||||
screen->SetPlatformScreen(std::move(xcb_screen));
|
||||
mDesktopManager->AddScreen(std::move(screen));
|
||||
mDesktopManager->addScreen(std::move(screen));
|
||||
}
|
||||
|
||||
void XcbInterface::initializeHardwareRendering()
|
||||
|
@ -107,11 +107,11 @@ void XcbInterface::initializeHardwareRendering()
|
|||
|
||||
void XcbInterface::createGraphicsContext()
|
||||
{
|
||||
if (!mConnection || mDesktopManager->GetDefaultScreen())
|
||||
if (!mConnection || mDesktopManager->getDefaultScreen())
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto xcb_screen = dynamic_cast<XcbScreen*>(mDesktopManager->GetDefaultScreen()->GetPlatformScreen());
|
||||
auto xcb_screen = dynamic_cast<XcbScreen*>(mDesktopManager->getDefaultScreen()->GetPlatformScreen());
|
||||
if (!xcb_screen)
|
||||
{
|
||||
return;
|
||||
|
@ -145,16 +145,16 @@ uint32_t XcbInterface::getEventMask()
|
|||
|
||||
void XcbInterface::addWindow(mt::Window* window)
|
||||
{
|
||||
auto screen = mDesktopManager->GetDefaultScreen();
|
||||
auto screen = mDesktopManager->getDefaultScreen();
|
||||
XcbWindow::add(window, mConnection, screen, getEventMask(), mGlInterface.get());
|
||||
}
|
||||
|
||||
void XcbInterface::onPaint()
|
||||
{
|
||||
mDesktopManager->OnUiEvent(PaintEvent::Create());
|
||||
mDesktopManager->onUiEvent(PaintEvent::Create());
|
||||
|
||||
auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow();
|
||||
auto defaultScreen = mDesktopManager->GetDefaultScreen();
|
||||
auto mainWindow = mDesktopManager->getWindowManager()->getMainWindow();
|
||||
auto defaultScreen = mDesktopManager->getDefaultScreen();
|
||||
|
||||
mainWindow->doPaint(defaultScreen);
|
||||
}
|
||||
|
@ -183,26 +183,26 @@ void XcbInterface::loop()
|
|||
}
|
||||
case XCB_KEY_PRESS: {
|
||||
auto kp = reinterpret_cast<xcb_key_press_event_t*>(event);
|
||||
auto ui_event = mEventInterface->ConvertKeyPress(kp, mDesktopManager->GetKeyboard());
|
||||
mDesktopManager->OnUiEvent(std::move(ui_event));
|
||||
auto ui_event = mEventInterface->ConvertKeyPress(kp, mDesktopManager->getKeyboard());
|
||||
mDesktopManager->onUiEvent(std::move(ui_event));
|
||||
break;
|
||||
}
|
||||
case XCB_KEY_RELEASE: {
|
||||
auto kr = reinterpret_cast<xcb_key_release_event_t*>(event);
|
||||
auto ui_event = mEventInterface->ConvertKeyRelease(kr, mDesktopManager->GetKeyboard());
|
||||
mDesktopManager->OnUiEvent(std::move(ui_event));
|
||||
auto ui_event = mEventInterface->ConvertKeyRelease(kr, mDesktopManager->getKeyboard());
|
||||
mDesktopManager->onUiEvent(std::move(ui_event));
|
||||
break;
|
||||
}
|
||||
case XCB_BUTTON_PRESS: {
|
||||
auto press = reinterpret_cast<xcb_button_press_event_t*>(event);
|
||||
auto ui_event = mEventInterface->ConvertButtonPress(press);
|
||||
mDesktopManager->OnUiEvent(std::move(ui_event));
|
||||
mDesktopManager->onUiEvent(std::move(ui_event));
|
||||
break;
|
||||
}
|
||||
case XCB_BUTTON_RELEASE: {
|
||||
auto release = reinterpret_cast<xcb_button_release_event_t*>(event);
|
||||
auto ui_event = mEventInterface->ConvertButtonRelease(release);
|
||||
mDesktopManager->OnUiEvent(std::move(ui_event));
|
||||
mDesktopManager->onUiEvent(std::move(ui_event));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -216,17 +216,17 @@ void XcbInterface::loop()
|
|||
|
||||
void XcbInterface::onEventsDispatched()
|
||||
{
|
||||
if (mDesktopManager->IsModified())
|
||||
if (mDesktopManager->isModified())
|
||||
{
|
||||
mDesktopManager->SetIsModified(false);
|
||||
auto mainWindow = mDesktopManager->GetWindowManager()->GetMainWindow();
|
||||
mDesktopManager->setIsModified(false);
|
||||
auto mainWindow = mDesktopManager->getWindowManager()->getMainWindow();
|
||||
mainWindow->clear();
|
||||
}
|
||||
}
|
||||
|
||||
void XcbInterface::shutDown()
|
||||
{
|
||||
mDesktopManager->GetWindowManager()->clearPlatformWindows();
|
||||
mDesktopManager->getWindowManager()->clearPlatformWindows();
|
||||
|
||||
if (!mConnection)
|
||||
{
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "Screen.h"
|
||||
#include "ImagePrimitives.h"
|
||||
#include "XcbGlWindowInterface.h"
|
||||
#include "DrawingContext.h"
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
|
@ -42,14 +43,16 @@ void XcbWindow::add(mt::Window* window, xcb_connection_t* connection, mt::Screen
|
|||
hwnd, /* window Id */
|
||||
xcb_screen->GetNativeScreen()->root, /* parent window */
|
||||
0, 0, /* x, y */
|
||||
window->GetWidth(), window->GetHeight(), /* width, height */
|
||||
window->getWidth(), window->getHeight(), /* width, height */
|
||||
10, /* border_width */
|
||||
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
|
||||
xcb_screen->GetNativeScreen()->root_visual, /* visual */
|
||||
mask, values ); /* masks */
|
||||
|
||||
auto xcb_window = std::make_unique<XcbWindow>(window, hwnd, connection, xcbGlInterface);
|
||||
window->SetPlatformWindow(std::move(xcb_window));
|
||||
|
||||
const auto drawing_mode = xcbGlInterface ? DrawingMode::GRAPH : DrawingMode::RASTER;
|
||||
window->setPlatformWindow(std::move(xcb_window), drawing_mode);
|
||||
}
|
||||
|
||||
int XcbWindow::getHandle() const
|
||||
|
@ -67,54 +70,40 @@ void XcbWindow::show()
|
|||
map();
|
||||
}
|
||||
|
||||
void XcbWindow::paint(mt::Screen* screen)
|
||||
{
|
||||
auto xcb_screen = dynamic_cast<XcbScreen*>(screen->GetPlatformScreen());
|
||||
|
||||
if (mGlInterface)
|
||||
{
|
||||
paintHardware(xcb_screen);
|
||||
}
|
||||
else
|
||||
{
|
||||
paintSoftware(xcb_screen);
|
||||
}
|
||||
}
|
||||
|
||||
void XcbWindow::paintHardware(XcbScreen* screen)
|
||||
void XcbWindow::beforePaint(mt::Screen* screen)
|
||||
{
|
||||
if (mGlInterface)
|
||||
{
|
||||
mGlInterface->initialize(mHandle);
|
||||
mGlInterface->draw();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto xcb_screen = dynamic_cast<XcbScreen*>(screen->GetPlatformScreen());
|
||||
if (!mBackingImage)
|
||||
{
|
||||
mBackingImage = std::make_unique<XcbImage>(mConnection, mWindow, xcb_screen->GetNativeScreen());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XcbWindow::paintSoftware(XcbScreen* screen)
|
||||
void XcbWindow::afterPaint(mt::Screen* screen)
|
||||
{
|
||||
if (!mBackingImage)
|
||||
if (mGlInterface)
|
||||
{
|
||||
mBackingImage = std::make_unique<XcbImage>(mConnection, mWindow, screen->GetNativeScreen());
|
||||
mGlInterface->afterPaint();
|
||||
}
|
||||
|
||||
auto backing_image = mWindow->getBackingImage();
|
||||
backing_image->initialize();
|
||||
//ImagePrimitives::drawCheckerboard(const_cast<unsigned char*>(backing_image->getDataPtr()), backing_image->getWidth(), backing_image->getHeight(), 0);
|
||||
|
||||
mBackingImage->update(mWindow, screen->GetNativeScreen(), mConnection, screen->GetGraphicsContext());
|
||||
|
||||
xcb_copy_area(mConnection, mBackingImage->getPixMap(), mHandle, screen->GetGraphicsContext(), 0, 0 ,0 , 0, backing_image->getWidth(), backing_image->getHeight());
|
||||
/*
|
||||
for(const auto& layer : mWindow->GetLayers())
|
||||
else
|
||||
{
|
||||
XcbLayerInterface::AddLayer(mConnection, xcb_screen->GetNativeScreen(), mHandle, xcb_screen->GetGraphicsContext(), layer);
|
||||
auto xcb_screen = dynamic_cast<XcbScreen*>(screen->GetPlatformScreen());
|
||||
mBackingImage->update(mWindow, xcb_screen->GetNativeScreen(), mConnection, xcb_screen->GetGraphicsContext());
|
||||
|
||||
xcb_copy_area(mConnection, mBackingImage->getPixMap(), mHandle, xcb_screen->GetGraphicsContext(), 0, 0 ,0 , 0, mWindow->getWidth(), mWindow->getHeight());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void XcbWindow::clear()
|
||||
{
|
||||
xcb_clear_area(mConnection, 1, mHandle, 0, 0, mWindow->GetWidth(), mWindow->GetHeight());
|
||||
xcb_clear_area(mConnection, 1, mHandle, 0, 0, mWindow->getWidth(), mWindow->getHeight());
|
||||
xcb_flush(mConnection);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,16 +26,15 @@ public:
|
|||
|
||||
void show() override;
|
||||
|
||||
void paint(mt::Screen* screen) override;
|
||||
void beforePaint(mt::Screen* screen) override;
|
||||
|
||||
void afterPaint(mt::Screen* screen) override;
|
||||
|
||||
void clear() override;
|
||||
|
||||
void map() override;
|
||||
|
||||
private:
|
||||
void paintHardware(XcbScreen* screen);
|
||||
void paintSoftware(XcbScreen* screen);
|
||||
|
||||
int mHandle{-1};
|
||||
unsigned mGraphicsContext {0};
|
||||
xcb_connection_t* mConnection{nullptr};
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
#include "DrawingSurface.h"
|
||||
#include "DrawingContext.h"
|
||||
#include "Grid.h"
|
||||
#include "Rasterizer.h"
|
||||
#include "Scene.h"
|
||||
#include "RasterPainter.h"
|
||||
#include "LineSegment.h"
|
||||
#include "Point.h"
|
||||
#include "TriMesh.h"
|
||||
|
@ -15,7 +16,7 @@ int main()
|
|||
manager.InitalizeSurface(200, 200);
|
||||
manager.InitializeContext();
|
||||
|
||||
auto line = LineSegment::Create(Point::Create(10.0, 10.0), Point::Create(190.0, 190.0));
|
||||
auto line = LineSegment::Create(Point(10.0, 10.0), Point(190.0, 190.0));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue