Basic Font integration.
This commit is contained in:
parent
ce11c52ae5
commit
72123bc333
36 changed files with 325 additions and 198 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "WindowManager.h"
|
#include "WindowManager.h"
|
||||||
#include "DesktopManager.h"
|
#include "DesktopManager.h"
|
||||||
|
#include "FontsManager.h"
|
||||||
#include "MainApplication.h"
|
#include "MainApplication.h"
|
||||||
#include "AbstractUiInterface.h"
|
#include "AbstractUiInterface.h"
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include "MidiReader.h"
|
#include "MidiReader.h"
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "DocumentConverter.h"
|
#include "DocumentConverter.h"
|
||||||
#include "DrawingManager.h"
|
|
||||||
#include "DrawingSurface.h"
|
#include "DrawingSurface.h"
|
||||||
#include "DrawingContext.h"
|
#include "DrawingContext.h"
|
||||||
#include "Grid.h"
|
#include "Grid.h"
|
||||||
|
@ -97,12 +96,14 @@ void MainApplication::run()
|
||||||
}
|
}
|
||||||
else if(program_type == "-draw")
|
else if(program_type == "-draw")
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
auto drawing_manager = DrawingManager::Create();
|
auto drawing_manager = DrawingManager::Create();
|
||||||
drawing_manager->InitalizeSurface(400, 400);
|
drawing_manager->InitalizeSurface(400, 400);
|
||||||
|
|
||||||
auto text = TextNode::Create("Hello World", DiscretePoint(20, 20));
|
auto text = TextNode::Create("Hello World", DiscretePoint(20, 20));
|
||||||
drawing_manager->AddText(text.get());
|
drawing_manager->AddText(text.get());
|
||||||
drawing_manager->RenderToFile("test.png");
|
drawing_manager->RenderToFile("test.png");
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "IFontEngine.h"
|
||||||
|
|
||||||
|
#include "Image.h"
|
||||||
|
|
||||||
|
class BasicFontEngine : public IFontEngine
|
||||||
|
{
|
||||||
|
virtual void initialize(){};
|
||||||
|
|
||||||
|
virtual void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16){};
|
||||||
|
|
||||||
|
virtual std::unique_ptr<Image<unsigned char> > loadGlyph(unsigned charCode){return nullptr;};
|
||||||
|
};
|
|
@ -4,12 +4,13 @@ set(fonts_LIB_DEPENDS "")
|
||||||
list(APPEND fonts_LIB_INCLUDES
|
list(APPEND fonts_LIB_INCLUDES
|
||||||
FontReader.cpp
|
FontReader.cpp
|
||||||
TrueTypeFont.cpp
|
TrueTypeFont.cpp
|
||||||
|
FontsManager.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
find_package(Freetype QUIET)
|
find_package(Freetype QUIET)
|
||||||
if(Freetype_FOUND)
|
if(Freetype_FOUND)
|
||||||
list(APPEND font_LIB_INCLUDES
|
list(APPEND fonts_LIB_INCLUDES
|
||||||
FreeTypeFontEngine.cpp
|
FreeTypeFontEngine.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,6 +28,6 @@ target_include_directories(fonts PUBLIC
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(fonts PUBLIC core ${fonts_LIB_DEPENDS})
|
target_link_libraries(fonts PUBLIC core image ${fonts_LIB_DEPENDS})
|
||||||
set_property(TARGET fonts PROPERTY FOLDER src)
|
set_property(TARGET fonts PROPERTY FOLDER src)
|
||||||
set_target_properties( fonts PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
set_target_properties( fonts PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
23
src/fonts/FontsManager.cpp
Normal file
23
src/fonts/FontsManager.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include "FontsManager.h"
|
||||||
|
|
||||||
|
#include "FreeTypeFontEngine.h"
|
||||||
|
#include "BasicFontEngine.h"
|
||||||
|
|
||||||
|
|
||||||
|
FontsManager::FontsManager()
|
||||||
|
: mFontEngine(std::make_unique<FreeTypeFontEngine>())
|
||||||
|
{
|
||||||
|
mFontEngine->initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<FontsManager> FontsManager::Create()
|
||||||
|
{
|
||||||
|
return std::make_unique<FontsManager>();
|
||||||
|
}
|
||||||
|
|
||||||
|
IFontEngine* FontsManager::getFontEngine() const
|
||||||
|
{
|
||||||
|
return mFontEngine.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
20
src/fonts/FontsManager.h
Normal file
20
src/fonts/FontsManager.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class IFontEngine;
|
||||||
|
|
||||||
|
class FontsManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FontsManager();
|
||||||
|
static std::unique_ptr<FontsManager> Create();
|
||||||
|
|
||||||
|
IFontEngine* getFontEngine() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<IFontEngine> mFontEngine;
|
||||||
|
};
|
||||||
|
|
||||||
|
using FontsManagerPtr = std::unique_ptr<FontsManager>;
|
|
@ -0,0 +1,87 @@
|
||||||
|
#include "FreeTypeFontEngine.h"
|
||||||
|
|
||||||
|
#include "Image.h"
|
||||||
|
#include "FileLogger.h"
|
||||||
|
|
||||||
|
void FreeTypeFontEngine::initialize()
|
||||||
|
{
|
||||||
|
if (mLibrary)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto error = FT_Init_FreeType(&mLibrary);
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
MLOG_ERROR("Error initializing FreeType. Code " << static_cast<int>(error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FreeTypeFontEngine::loadFontFace(const std::filesystem::path& fontFile, int penSize)
|
||||||
|
{
|
||||||
|
if (!mLibrary)
|
||||||
|
{
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto full_path = mSystemFontLocation / fontFile;
|
||||||
|
const auto error = FT_New_Face(mLibrary, full_path.c_str(), 0, &mWorkingFontFace );
|
||||||
|
if ( error == FT_Err_Unknown_File_Format )
|
||||||
|
{
|
||||||
|
MLOG_ERROR("Found file but format not supported. Code " << static_cast<int>(error));
|
||||||
|
}
|
||||||
|
else if ( error )
|
||||||
|
{
|
||||||
|
MLOG_ERROR("Failed to find or open file. Code " << static_cast<int>(error));
|
||||||
|
}
|
||||||
|
FT_Set_Pixel_Sizes(mWorkingFontFace, penSize, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Image<unsigned char> > FreeTypeFontEngine::loadGlyph(unsigned charCode)
|
||||||
|
{
|
||||||
|
auto glyph_index = FT_Get_Char_Index( mWorkingFontFace, 65 );
|
||||||
|
if (glyph_index == 0)
|
||||||
|
{
|
||||||
|
MLOG_ERROR("Got the null glyph");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto error = FT_Load_Glyph(mWorkingFontFace, glyph_index, FT_LOAD_DEFAULT );
|
||||||
|
if (error == FT_Err_Invalid_Argument)
|
||||||
|
{
|
||||||
|
MLOG_ERROR("Error loading glyph - bad arg. Code " << static_cast<int>(error));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
else if(error)
|
||||||
|
{
|
||||||
|
MLOG_ERROR("Error loading glyph. Code " << static_cast<int>(error));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mWorkingFontFace->glyph->format != FT_GLYPH_FORMAT_BITMAP)
|
||||||
|
{
|
||||||
|
error = FT_Render_Glyph( mWorkingFontFace->glyph, FT_RENDER_MODE_NORMAL );
|
||||||
|
}
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
MLOG_ERROR("Error rendering glyph. Code " << static_cast<int>(error));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto rows = mWorkingFontFace->glyph->bitmap.rows;
|
||||||
|
auto columns = mWorkingFontFace->glyph->bitmap.width;
|
||||||
|
auto image = std::make_unique<Image<unsigned char>> (columns, rows);
|
||||||
|
|
||||||
|
unsigned counter = 0;
|
||||||
|
std::vector<unsigned char> data(rows*columns, 0);
|
||||||
|
for (unsigned idx=0; idx<rows; idx++)
|
||||||
|
{
|
||||||
|
for (unsigned jdx=0; jdx<columns; jdx++)
|
||||||
|
{
|
||||||
|
data[counter] = mWorkingFontFace->glyph->bitmap.buffer[counter];
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
image->setData(data);
|
||||||
|
return image;
|
||||||
|
}
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
|
||||||
#include <iostream>
|
template<typename T>
|
||||||
#include <filesystem>
|
class Image;
|
||||||
|
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
|
@ -15,86 +15,11 @@ class FreeTypeFontEngine : public IFontEngine
|
||||||
public:
|
public:
|
||||||
FreeTypeFontEngine() = default;
|
FreeTypeFontEngine() = default;
|
||||||
|
|
||||||
void initialize()
|
void initialize() override;
|
||||||
{
|
|
||||||
if (mLibrary)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto error = FT_Init_FreeType(&mLibrary);
|
void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16) override;
|
||||||
if (error)
|
|
||||||
{
|
|
||||||
std::cout << "Error initializing FreeType" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadFontFace(const std::filesystem::path& fontFile)
|
std::unique_ptr<Image<unsigned char> > loadGlyph(unsigned charCode) override;
|
||||||
{
|
|
||||||
const auto full_path = mSystemFontLocation / fontFile;
|
|
||||||
const auto error = FT_New_Face(mLibrary, full_path.c_str(), 0, &mWorkingFontFace );
|
|
||||||
if ( error == FT_Err_Unknown_File_Format )
|
|
||||||
{
|
|
||||||
std::cout << "Found file but format not supported" << std::endl;
|
|
||||||
}
|
|
||||||
else if ( error )
|
|
||||||
{
|
|
||||||
std::cout << "Failed to find or open file" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pensize = 16;
|
|
||||||
FT_Set_Pixel_Sizes(mWorkingFontFace, pensize, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<Image<unsigned char> > loadGlyph(unsigned charCode)
|
|
||||||
{
|
|
||||||
auto glyph_index = FT_Get_Char_Index( mWorkingFontFace, charCode );
|
|
||||||
if (glyph_index == 0)
|
|
||||||
{
|
|
||||||
std::cout << "Got the null glyph" << std::endl;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto error = FT_Load_Glyph(mWorkingFontFace, glyph_index, FT_LOAD_DEFAULT );
|
|
||||||
if (error == FT_Err_Invalid_Argument)
|
|
||||||
{
|
|
||||||
std::cout << "Error loading glyph - bad arg" << std::endl;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
else if(error)
|
|
||||||
{
|
|
||||||
auto code = static_cast<int>(error);
|
|
||||||
std::cout << "Error loading glyph - somethign else " << code << std::endl;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mWorkingFontFace->glyph->format == FT_GLYPH_FORMAT_BITMAP)
|
|
||||||
{
|
|
||||||
std::cout << "It is bitmap format" << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error = FT_Render_Glyph( mWorkingFontFace->glyph, FT_RENDER_MODE_NORMAL );
|
|
||||||
}
|
|
||||||
|
|
||||||
auto rows = mWorkingFontFace->glyph->bitmap.rows;
|
|
||||||
auto columns = mWorkingFontFace->glyph->bitmap.width;
|
|
||||||
std::cout << "We have a bitmap with rows " << rows << " and columns " << columns << std::endl;
|
|
||||||
|
|
||||||
auto image = std::make_unique<Image<unsigned char>> (columns, rows);
|
|
||||||
|
|
||||||
unsigned counter = 0;
|
|
||||||
std::vector<unsigned char> data(rows*columns);
|
|
||||||
for (unsigned idx=0; idx<rows; idx++)
|
|
||||||
{
|
|
||||||
for (unsigned jdx=0; jdx<columns; jdx++)
|
|
||||||
{
|
|
||||||
data[counter] = mWorkingFontFace->glyph->bitmap.buffer[counter];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
image->setData(data);
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::filesystem::path mSystemFontLocation{"/usr/share/fonts/"};
|
std::filesystem::path mSystemFontLocation{"/usr/share/fonts/"};
|
||||||
|
|
|
@ -1,8 +1,20 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Image;
|
||||||
|
|
||||||
class IFontEngine
|
class IFontEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IFontEngine() = default;
|
IFontEngine() = default;
|
||||||
virtual ~IFontEngine() = default;
|
virtual ~IFontEngine() = default;
|
||||||
|
|
||||||
|
virtual void initialize(){};
|
||||||
|
|
||||||
|
virtual void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16) = 0;
|
||||||
|
|
||||||
|
virtual std::unique_ptr<Image<unsigned char> > loadGlyph(unsigned charCode) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,6 @@ set(platform_LIBS "")
|
||||||
|
|
||||||
list(APPEND graphics_LIB_INCLUDES
|
list(APPEND graphics_LIB_INCLUDES
|
||||||
DrawingContext.cpp
|
DrawingContext.cpp
|
||||||
DrawingManager.cpp
|
|
||||||
DrawingSurface.cpp
|
DrawingSurface.cpp
|
||||||
RasterPainter.cpp
|
RasterPainter.cpp
|
||||||
${platform_LIB_INCLUDES}
|
${platform_LIB_INCLUDES}
|
||||||
|
@ -36,7 +35,7 @@ target_include_directories(graphics PUBLIC
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/opengl"
|
"${CMAKE_CURRENT_SOURCE_DIR}/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(graphics PUBLIC visual_elements image ${platform_LIBS})
|
target_link_libraries(graphics PUBLIC geometry mesh fonts image visual_elements ${platform_LIBS})
|
||||||
|
|
||||||
set_property(TARGET graphics PROPERTY FOLDER src)
|
set_property(TARGET graphics PROPERTY FOLDER src)
|
||||||
set_target_properties( graphics PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
set_target_properties( graphics PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
|
|
@ -9,10 +9,11 @@
|
||||||
#include "DrawingSurface.h"
|
#include "DrawingSurface.h"
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
|
|
||||||
DrawingContext::DrawingContext(DrawingSurface* surface, DrawingMode requestedDrawingMode)
|
DrawingContext::DrawingContext(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode)
|
||||||
: mSurface(surface),
|
: mSurface(surface),
|
||||||
mDrawingMode(requestedDrawingMode),
|
mDrawingMode(requestedDrawingMode),
|
||||||
mScene(std::make_unique<Scene>())
|
mScene(std::make_unique<Scene>()),
|
||||||
|
mFontsManager(fontsManager)
|
||||||
{
|
{
|
||||||
if (mDrawingMode == DrawingMode::GRAPH)
|
if (mDrawingMode == DrawingMode::GRAPH)
|
||||||
{
|
{
|
||||||
|
@ -24,9 +25,9 @@ DrawingContext::DrawingContext(DrawingSurface* surface, DrawingMode requestedDra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<DrawingContext> DrawingContext::Create(DrawingSurface* surface, DrawingMode requestedDrawingMode)
|
std::unique_ptr<DrawingContext> DrawingContext::Create(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode)
|
||||||
{
|
{
|
||||||
return std::make_unique<DrawingContext>(surface, requestedDrawingMode);
|
return std::make_unique<DrawingContext>(surface, fontsManager, requestedDrawingMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
Scene* DrawingContext::getScene() const
|
Scene* DrawingContext::getScene() const
|
||||||
|
@ -41,6 +42,6 @@ DrawingSurface* DrawingContext::getSurface() const
|
||||||
|
|
||||||
void DrawingContext::paint()
|
void DrawingContext::paint()
|
||||||
{
|
{
|
||||||
mScene->update(mDrawingMode == DrawingMode::RASTER ? mSurface->getImage() : nullptr);
|
mScene->update(mFontsManager, mDrawingMode == DrawingMode::RASTER ? mSurface->getImage() : nullptr);
|
||||||
mPainter->paint(this);
|
mPainter->paint(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
class Scene;
|
class Scene;
|
||||||
class AbstractPainter;
|
class AbstractPainter;
|
||||||
class DrawingSurface;
|
class DrawingSurface;
|
||||||
|
class FontsManager;
|
||||||
|
|
||||||
enum class DrawingMode
|
enum class DrawingMode
|
||||||
{
|
{
|
||||||
|
@ -16,9 +17,9 @@ enum class DrawingMode
|
||||||
class DrawingContext
|
class DrawingContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DrawingContext(DrawingSurface* surface, DrawingMode requestedDrawingMode);
|
DrawingContext(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode);
|
||||||
|
|
||||||
static std::unique_ptr<DrawingContext> Create(DrawingSurface* surface, DrawingMode requestedDrawingMode);
|
static std::unique_ptr<DrawingContext> Create(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode);
|
||||||
|
|
||||||
Scene* getScene() const;
|
Scene* getScene() const;
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DrawingMode mDrawingMode;
|
DrawingMode mDrawingMode;
|
||||||
|
FontsManager* mFontsManager{nullptr};
|
||||||
DrawingSurface* mSurface{nullptr};
|
DrawingSurface* mSurface{nullptr};
|
||||||
std::unique_ptr<Scene> mScene;
|
std::unique_ptr<Scene> mScene;
|
||||||
std::unique_ptr<AbstractPainter> mPainter;
|
std::unique_ptr<AbstractPainter> mPainter;
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
#include "DrawingManager.h"
|
|
||||||
|
|
||||||
#include "DrawingSurface.h"
|
|
||||||
#include "DrawingContext.h"
|
|
||||||
#include "AbstractPainter.h"
|
|
||||||
|
|
||||||
#include "Grid.h"
|
|
||||||
#include "Image.h"
|
|
||||||
#include "TriMesh.h"
|
|
||||||
#include "Scene.h"
|
|
||||||
|
|
||||||
DrawingManager::DrawingManager()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<DrawingManager> DrawingManager::Create()
|
|
||||||
{
|
|
||||||
return std::make_unique<DrawingManager>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawingManager::InitalizeSurface(unsigned width, unsigned height)
|
|
||||||
{
|
|
||||||
mDrawingSurface = DrawingSurface::Create();
|
|
||||||
mDrawingSurface->setSize(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawingManager::InitializeContext()
|
|
||||||
{
|
|
||||||
//mDrawingContext = DrawingContext::Create();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawingManager::AddText(TextNode* text)
|
|
||||||
{
|
|
||||||
if (!mDrawingContext)
|
|
||||||
{
|
|
||||||
InitializeContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mDrawingContext)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawingManager::RenderToFile(const std::string& path)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class TextNode;
|
|
||||||
|
|
||||||
class DrawingSurface;
|
|
||||||
using DrawingSurfacePtr = std::unique_ptr<DrawingSurface>;
|
|
||||||
class DrawingContext;
|
|
||||||
using DrawingContextPtr = std::unique_ptr<DrawingContext>;
|
|
||||||
|
|
||||||
class DrawingManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DrawingManager();
|
|
||||||
static std::unique_ptr<DrawingManager> Create();
|
|
||||||
void InitalizeSurface(unsigned width, unsigned height);
|
|
||||||
void InitializeContext();
|
|
||||||
void AddText(TextNode* text);
|
|
||||||
void RenderToFile(const std::string& path);
|
|
||||||
|
|
||||||
private:
|
|
||||||
DrawingSurfacePtr mDrawingSurface {nullptr};
|
|
||||||
DrawingContextPtr mDrawingContext {nullptr};
|
|
||||||
};
|
|
||||||
|
|
||||||
using DrawingManagerPtr = std::unique_ptr<DrawingManager>;
|
|
|
@ -9,7 +9,9 @@
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
#include "TriMesh.h"
|
#include "TriMesh.h"
|
||||||
#include "AbstractPainter.h"
|
#include "AbstractPainter.h"
|
||||||
|
|
||||||
#include "DrawingContext.h"
|
#include "DrawingContext.h"
|
||||||
|
#include "FontsManager.h"
|
||||||
|
|
||||||
#include "IPlatformWindow.h"
|
#include "IPlatformWindow.h"
|
||||||
#include "Screen.h"
|
#include "Screen.h"
|
||||||
|
@ -89,10 +91,10 @@ IPlatformWindow* Window::getPlatformWindow() const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setPlatformWindow(IPlatformWindowPtr window, DrawingMode drawingMode)
|
void Window::setPlatformWindow(IPlatformWindowPtr window, FontsManager* fontsManager, DrawingMode drawingMode)
|
||||||
{
|
{
|
||||||
mPlatformWindow = std::move(window);
|
mPlatformWindow = std::move(window);
|
||||||
mDrawingContext = std::make_unique<DrawingContext>(this, drawingMode);
|
mDrawingContext = std::make_unique<DrawingContext>(this, fontsManager, drawingMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::map()
|
void Window::map()
|
||||||
|
|
|
@ -11,7 +11,9 @@ class MouseEvent;
|
||||||
class KeyboardEvent;
|
class KeyboardEvent;
|
||||||
|
|
||||||
class DrawingContext;
|
class DrawingContext;
|
||||||
|
class FontsManager;
|
||||||
enum class DrawingMode;
|
enum class DrawingMode;
|
||||||
|
|
||||||
class Widget;
|
class Widget;
|
||||||
using WidgetPtr = std::unique_ptr<Widget>;
|
using WidgetPtr = std::unique_ptr<Widget>;
|
||||||
class IPlatformWindow;
|
class IPlatformWindow;
|
||||||
|
@ -43,7 +45,7 @@ public:
|
||||||
|
|
||||||
IPlatformWindow* getPlatformWindow() const;
|
IPlatformWindow* getPlatformWindow() const;
|
||||||
|
|
||||||
void setPlatformWindow(IPlatformWindowPtr window, DrawingMode drawingMode);
|
void setPlatformWindow(IPlatformWindowPtr window, FontsManager* fontsManager, DrawingMode drawingMode);
|
||||||
|
|
||||||
void map();
|
void map();
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
#include "AbstractMesh.h"
|
#include "AbstractMesh.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "DiscretePoint.h"
|
#include "DiscretePoint.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
class FontsManager;
|
||||||
|
|
||||||
class AbstractVisualNode
|
class AbstractVisualNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -21,11 +24,21 @@ public:
|
||||||
return mMesh.get();
|
return mMesh.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void update(FontsManager* fontsManager)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
virtual void updateMesh()
|
virtual void updateMesh()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void updateTexture(FontsManager* fontsManager)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Image<unsigned char>* getImage() const
|
Image<unsigned char>* getImage() const
|
||||||
{
|
{
|
||||||
return mImage.get();
|
return mImage.get();
|
||||||
|
@ -36,8 +49,14 @@ public:
|
||||||
return mLocation;
|
return mLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Image<unsigned char>* getTexture() const
|
||||||
|
{
|
||||||
|
return mTexture.get();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DiscretePoint mLocation;
|
DiscretePoint mLocation;
|
||||||
std::unique_ptr<AbstractMesh> mMesh;
|
std::unique_ptr<AbstractMesh> mMesh;
|
||||||
std::unique_ptr<Image<unsigned char> > mImage;
|
std::unique_ptr<Image<unsigned char> > mImage;
|
||||||
|
std::unique_ptr<Image<unsigned char> > mTexture;
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,7 +12,7 @@ target_include_directories(visual_elements PUBLIC
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(visual_elements PUBLIC core geometry mesh image)
|
target_link_libraries(visual_elements PUBLIC core geometry fonts mesh image)
|
||||||
|
|
||||||
set_property(TARGET visual_elements PROPERTY FOLDER src)
|
set_property(TARGET visual_elements PROPERTY FOLDER src)
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,11 @@ unsigned RectangleNode::getHeight() const
|
||||||
return mHeight;
|
return mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RectangleNode::update(FontsManager* fontsManager)
|
||||||
|
{
|
||||||
|
updateMesh();
|
||||||
|
}
|
||||||
|
|
||||||
void RectangleNode::updateMesh()
|
void RectangleNode::updateMesh()
|
||||||
{
|
{
|
||||||
const auto rect = Rectangle(mLocation, mWidth, mHeight);
|
const auto rect = Rectangle(mLocation, mWidth, mHeight);
|
||||||
|
|
|
@ -15,9 +15,10 @@ public:
|
||||||
unsigned getWidth() const;
|
unsigned getWidth() const;
|
||||||
unsigned getHeight() const;
|
unsigned getHeight() const;
|
||||||
|
|
||||||
void updateMesh() override;
|
void update(FontsManager* fontsManager) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateMesh() override;
|
||||||
unsigned mWidth{1};
|
unsigned mWidth{1};
|
||||||
unsigned mHeight{1};
|
unsigned mHeight{1};
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,16 +3,19 @@
|
||||||
#include "VisualLayer.h"
|
#include "VisualLayer.h"
|
||||||
#include "GeometryNode.h"
|
#include "GeometryNode.h"
|
||||||
#include "RectangleNode.h"
|
#include "RectangleNode.h"
|
||||||
|
#include "TextNode.h"
|
||||||
|
|
||||||
#include "MeshBuilder.h"
|
#include "MeshBuilder.h"
|
||||||
#include "TriMesh.h"
|
#include "TriMesh.h"
|
||||||
|
|
||||||
|
#include "Image.h"
|
||||||
|
|
||||||
void Scene::syncLayers(const std::vector<VisualLayer*>& layers)
|
void Scene::syncLayers(const std::vector<VisualLayer*>& layers)
|
||||||
{
|
{
|
||||||
mLayers = layers;
|
mLayers = layers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::update(Image<unsigned char>* image)
|
void Scene::update(FontsManager* fontsManager, Image<unsigned char>* image)
|
||||||
{
|
{
|
||||||
if (image)
|
if (image)
|
||||||
{
|
{
|
||||||
|
@ -28,11 +31,23 @@ void Scene::update(Image<unsigned char>* image)
|
||||||
auto node = layer->getShapeNode();
|
auto node = layer->getShapeNode();
|
||||||
if (layer->getIsDirty())
|
if (layer->getIsDirty())
|
||||||
{
|
{
|
||||||
node->updateMesh();
|
node->update(fontsManager);
|
||||||
layer->setIsDirty(false);
|
layer->setIsDirty(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
mWorkingMeshs.push_back(dynamic_cast<TriMesh*>(node->getMesh()));
|
mWorkingMeshs.push_back(dynamic_cast<TriMesh*>(node->getMesh()));
|
||||||
|
mTextures.push_back(nullptr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto node = layer->getTextNode();
|
||||||
|
if (layer->getIsDirty())
|
||||||
|
{
|
||||||
|
node->update(fontsManager);
|
||||||
|
layer->setIsDirty(false);
|
||||||
|
}
|
||||||
|
mWorkingMeshs.push_back(dynamic_cast<TriMesh*>(node->getMesh()));
|
||||||
|
mTextures.push_back(node->getTexture());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
class VisualLayer;
|
class VisualLayer;
|
||||||
class TriMesh;
|
class TriMesh;
|
||||||
|
class FontsManager;
|
||||||
|
|
||||||
class RectangleNode;
|
class RectangleNode;
|
||||||
|
|
||||||
|
@ -18,16 +19,19 @@ public:
|
||||||
|
|
||||||
void syncLayers(const std::vector<VisualLayer*>& layers);
|
void syncLayers(const std::vector<VisualLayer*>& layers);
|
||||||
|
|
||||||
void update(Image<unsigned char>* image = nullptr);
|
void update(FontsManager* fontsManager, Image<unsigned char>* image = nullptr);
|
||||||
|
|
||||||
unsigned getNumMeshes() const;
|
unsigned getNumMeshes() const;
|
||||||
|
|
||||||
TriMesh* getMesh(std::size_t idx) const;
|
TriMesh* getMesh(std::size_t idx) const;
|
||||||
|
|
||||||
|
Image<unsigned char>* getTexture(std::size_t idx) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void processRectangleNode(RectangleNode* node);
|
void processRectangleNode(RectangleNode* node);
|
||||||
|
|
||||||
std::vector<TriMesh*> mWorkingMeshs;
|
std::vector<TriMesh*> mWorkingMeshs;
|
||||||
std::vector<VisualLayer*> mLayers;
|
std::vector<VisualLayer*> mLayers;
|
||||||
|
std::vector<Image<unsigned char>* > mTextures;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
#include "TextNode.h"
|
#include "TextNode.h"
|
||||||
|
|
||||||
|
#include "Rectangle.h"
|
||||||
|
#include "FontsManager.h"
|
||||||
|
#include "IFontEngine.h"
|
||||||
|
#include "MeshPrimitives.h"
|
||||||
|
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
|
|
||||||
TextNode::TextNode(const std::string& content, const DiscretePoint& loc)
|
TextNode::TextNode(const std::string& content, const DiscretePoint& loc)
|
||||||
|
@ -55,3 +60,39 @@ void TextNode::setStrokeColor(const Color& color)
|
||||||
{
|
{
|
||||||
mStrokeColor = color;
|
mStrokeColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextNode::update(FontsManager* drawingManager)
|
||||||
|
{
|
||||||
|
updateMesh();
|
||||||
|
updateTexture(drawingManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextNode::updateMesh()
|
||||||
|
{
|
||||||
|
double font_height = 16;
|
||||||
|
double font_width = 16;
|
||||||
|
|
||||||
|
double text_width = mContent.size() * font_width;
|
||||||
|
|
||||||
|
const auto rect = Rectangle(mLocation, text_width, font_height);
|
||||||
|
|
||||||
|
auto mesh = MeshPrimitives::build(rect);
|
||||||
|
auto color = Color(0, 0, 0, 1.0);
|
||||||
|
|
||||||
|
mesh->addConstantFaceVectorAttribute("Color", color.getAsVectorDouble());
|
||||||
|
mMesh = std::move(mesh);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextNode::updateTexture(FontsManager* fontsManager)
|
||||||
|
{
|
||||||
|
fontsManager->getFontEngine()->loadFontFace("truetype/msttcorefonts/arial.ttf");
|
||||||
|
auto glyph = fontsManager->getFontEngine()->loadGlyph('A');
|
||||||
|
|
||||||
|
if (!glyph)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mTexture = std::make_unique<Image<unsigned char> >(glyph->getWidth(), glyph->getHeight());
|
||||||
|
mTexture->setData(glyph->getData());
|
||||||
|
}
|
||||||
|
|
|
@ -28,7 +28,12 @@ public:
|
||||||
void setFillColor(const Color& color);
|
void setFillColor(const Color& color);
|
||||||
void setStrokeColor(const Color& color);
|
void setStrokeColor(const Color& color);
|
||||||
|
|
||||||
|
void update(FontsManager* fontsManager) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateMesh() override;
|
||||||
|
void updateTexture(FontsManager* fontsManager) override;
|
||||||
|
|
||||||
std::string mContent;
|
std::string mContent;
|
||||||
std::string mFontLabel;
|
std::string mFontLabel;
|
||||||
Color mFillColor;
|
Color mFillColor;
|
||||||
|
|
|
@ -1,19 +1,25 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include "IFontEngine.h"
|
||||||
|
#include "FontsManager.h"
|
||||||
|
|
||||||
namespace mt
|
namespace mt
|
||||||
{
|
{
|
||||||
class Window;
|
class Window;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DesktopManager;
|
class DesktopManager;
|
||||||
|
class FontsManager;
|
||||||
|
|
||||||
class AbstractUIInterface
|
class AbstractUIInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AbstractUIInterface(DesktopManager* desktopManager, bool useHardware = false)
|
AbstractUIInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = false)
|
||||||
: mDesktopManager(desktopManager),
|
: mDesktopManager(desktopManager),
|
||||||
mUseHardwareRendering(useHardware)
|
mUseHardwareRendering(useHardware),
|
||||||
|
mFontsManager(std::move(fontsManager))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,5 +38,7 @@ protected:
|
||||||
virtual void initializeHardwareRendering() {};
|
virtual void initializeHardwareRendering() {};
|
||||||
|
|
||||||
DesktopManager* mDesktopManager{nullptr};
|
DesktopManager* mDesktopManager{nullptr};
|
||||||
|
std::unique_ptr<FontsManager> mFontsManager;
|
||||||
|
|
||||||
bool mUseHardwareRendering{false};
|
bool mUseHardwareRendering{false};
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,18 +7,22 @@
|
||||||
#include "Win32UiInterface.h"
|
#include "Win32UiInterface.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "FontsManager.h"
|
||||||
|
|
||||||
std::unique_ptr<AbstractUIInterface> UiInterfaceFactory::create(DesktopManager* desktopManager, Backend backend)
|
std::unique_ptr<AbstractUIInterface> UiInterfaceFactory::create(DesktopManager* desktopManager, Backend backend)
|
||||||
{
|
{
|
||||||
|
auto fonts_manager = std::make_unique<FontsManager>();
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (backend == Backend::UNSET || backend == Backend::X11 || backend == Backend::X11_RASTER)
|
if (backend == Backend::UNSET || backend == Backend::X11 || backend == Backend::X11_RASTER)
|
||||||
{
|
{
|
||||||
const bool use_hardware = (backend != Backend::X11_RASTER);
|
const bool use_hardware = (backend != Backend::X11_RASTER);
|
||||||
return std::make_unique<XcbInterface>(desktopManager, use_hardware);
|
return std::make_unique<XcbInterface>(desktopManager, std::move(fonts_manager), use_hardware);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const bool use_hardware = (backend != Backend::WAYLAND_RASTER);
|
const bool use_hardware = (backend != Backend::WAYLAND_RASTER);
|
||||||
return std::make_unique<WaylandInterface>(desktopManager, use_hardware);
|
return std::make_unique<WaylandInterface>(desktopManager, std::move(fonts_manager), use_hardware);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return std::make_unique<Win32UiInterface>();
|
return std::make_unique<Win32UiInterface>();
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "FileLogger.h"
|
#include "FileLogger.h"
|
||||||
#include "DesktopManager.h"
|
#include "DesktopManager.h"
|
||||||
#include "WindowManager.h"
|
#include "WindowManager.h"
|
||||||
|
#include "FontsManager.h"
|
||||||
|
|
||||||
#include "WaylandSurface.h"
|
#include "WaylandSurface.h"
|
||||||
#include "WaylandBuffer.h"
|
#include "WaylandBuffer.h"
|
||||||
|
@ -43,8 +44,8 @@ void WaylandInterface::registryHandleGlobalRemoveEvent(void *data, struct wl_reg
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WaylandInterface::WaylandInterface(DesktopManager* desktopManager, bool useHardware)
|
WaylandInterface::WaylandInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware)
|
||||||
: AbstractUIInterface(desktopManager, useHardware),
|
: AbstractUIInterface(desktopManager, std::move(fontsManager), useHardware),
|
||||||
mBuffer(std::make_shared<WaylandBuffer>())
|
mBuffer(std::make_shared<WaylandBuffer>())
|
||||||
{
|
{
|
||||||
mRegistryListener.global = registryHandleGlobalEvent;
|
mRegistryListener.global = registryHandleGlobalEvent;
|
||||||
|
@ -129,7 +130,7 @@ void WaylandInterface::doXdgPong(uint32_t serial)
|
||||||
|
|
||||||
void WaylandInterface::addWindow(mt::Window* window)
|
void WaylandInterface::addWindow(mt::Window* window)
|
||||||
{
|
{
|
||||||
WaylandSurface::add(window, mCompositor, mXdgBase, mBuffer, mEglInterface.get());
|
WaylandSurface::add(window, mCompositor, mXdgBase, mBuffer, mFontsManager.get(), mEglInterface.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandInterface::showWindow(mt::Window* window)
|
void WaylandInterface::showWindow(mt::Window* window)
|
||||||
|
|
|
@ -18,7 +18,7 @@ class WaylandInterface : public AbstractUIInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WaylandInterface(DesktopManager* desktopManager, bool useHardware = true);
|
WaylandInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = true);
|
||||||
|
|
||||||
~WaylandInterface();
|
~WaylandInterface();
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,16 @@
|
||||||
|
|
||||||
#include "WaylandEglWindowInterface.h"
|
#include "WaylandEglWindowInterface.h"
|
||||||
#include "ImagePrimitives.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)
|
#include "DrawingContext.h"
|
||||||
|
#include "FontsManager.h"
|
||||||
|
|
||||||
|
void WaylandSurface::add(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, FontsManager* fontsManager, WaylandEglInterface* eglInterface)
|
||||||
{
|
{
|
||||||
auto wayland_window = std::make_unique<WaylandSurface>(window, compositor, xdg_wm_base, buffer, eglInterface);
|
auto wayland_window = std::make_unique<WaylandSurface>(window, compositor, xdg_wm_base, buffer, eglInterface);
|
||||||
|
|
||||||
const auto drawing_mode = eglInterface ? DrawingMode::GRAPH : DrawingMode::RASTER;
|
const auto drawing_mode = eglInterface ? DrawingMode::GRAPH : DrawingMode::RASTER;
|
||||||
window->setPlatformWindow(std::move(wayland_window), drawing_mode);
|
window->setPlatformWindow(std::move(wayland_window), fontsManager, drawing_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
WaylandSurface::WaylandSurface(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface)
|
WaylandSurface::WaylandSurface(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface)
|
||||||
|
|
|
@ -16,11 +16,13 @@ struct xdg_toplevel;
|
||||||
class WaylandEglInterface;
|
class WaylandEglInterface;
|
||||||
class WaylandEglWindowInterface;
|
class WaylandEglWindowInterface;
|
||||||
|
|
||||||
|
class FontsManager;
|
||||||
|
|
||||||
class WaylandSurface : public IPlatformWindow
|
class WaylandSurface : public IPlatformWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static void add(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface);
|
static void add(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, FontsManager* fontsManager, WaylandEglInterface* eglInterface);
|
||||||
|
|
||||||
WaylandSurface(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface);
|
WaylandSurface(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface);
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,13 @@
|
||||||
#include "XcbEventInterface.h"
|
#include "XcbEventInterface.h"
|
||||||
#include "XcbGlInterface.h"
|
#include "XcbGlInterface.h"
|
||||||
#include "FileLogger.h"
|
#include "FileLogger.h"
|
||||||
|
#include "FontsManager.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
XcbInterface::XcbInterface(DesktopManager* desktopManager, bool useHardware)
|
XcbInterface::XcbInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware)
|
||||||
: AbstractUIInterface(desktopManager, useHardware),
|
: AbstractUIInterface(desktopManager, std::move(fontsManager), useHardware),
|
||||||
mEventInterface(XcbEventInterface::Create())
|
mEventInterface(XcbEventInterface::Create())
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -151,7 +152,7 @@ uint32_t XcbInterface::getEventMask()
|
||||||
void XcbInterface::addWindow(mt::Window* window)
|
void XcbInterface::addWindow(mt::Window* window)
|
||||||
{
|
{
|
||||||
auto screen = mDesktopManager->getDefaultScreen();
|
auto screen = mDesktopManager->getDefaultScreen();
|
||||||
XcbWindow::add(window, mConnection, screen, getEventMask(), mGlInterface.get());
|
XcbWindow::add(window, mConnection, screen, getEventMask(), mFontsManager.get(), mGlInterface.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbInterface::onPaint()
|
void XcbInterface::onPaint()
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace mt
|
||||||
class XcbInterface : public AbstractUIInterface
|
class XcbInterface : public AbstractUIInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
XcbInterface(DesktopManager* desktopManager, bool useHardware = true);
|
XcbInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = true);
|
||||||
|
|
||||||
~XcbInterface();
|
~XcbInterface();
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
#include "Screen.h"
|
#include "Screen.h"
|
||||||
#include "ImagePrimitives.h"
|
#include "ImagePrimitives.h"
|
||||||
#include "XcbGlWindowInterface.h"
|
#include "XcbGlWindowInterface.h"
|
||||||
|
|
||||||
#include "DrawingContext.h"
|
#include "DrawingContext.h"
|
||||||
|
#include "FontsManager.h"
|
||||||
|
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
|
@ -27,7 +29,7 @@ XcbWindow::~XcbWindow()
|
||||||
xcb_destroy_window(mConnection, mHandle);
|
xcb_destroy_window(mConnection, mHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XcbWindow::add(mt::Window* window, xcb_connection_t* connection, mt::Screen* screen, uint32_t eventMask, XcbGlInterface* xcbGlInterface)
|
void XcbWindow::add(mt::Window* window, xcb_connection_t* connection, mt::Screen* screen, uint32_t eventMask, FontsManager* fontsManager, XcbGlInterface* xcbGlInterface)
|
||||||
{
|
{
|
||||||
if (!screen)
|
if (!screen)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +54,7 @@ void XcbWindow::add(mt::Window* window, xcb_connection_t* connection, mt::Screen
|
||||||
auto xcb_window = std::make_unique<XcbWindow>(window, hwnd, connection, xcbGlInterface);
|
auto xcb_window = std::make_unique<XcbWindow>(window, hwnd, connection, xcbGlInterface);
|
||||||
|
|
||||||
const auto drawing_mode = xcbGlInterface ? DrawingMode::GRAPH : DrawingMode::RASTER;
|
const auto drawing_mode = xcbGlInterface ? DrawingMode::GRAPH : DrawingMode::RASTER;
|
||||||
window->setPlatformWindow(std::move(xcb_window), drawing_mode);
|
window->setPlatformWindow(std::move(xcb_window), fontsManager, drawing_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int XcbWindow::getHandle() const
|
int XcbWindow::getHandle() const
|
||||||
|
|
|
@ -6,6 +6,9 @@ class XcbImage;
|
||||||
class XcbScreen;
|
class XcbScreen;
|
||||||
class XcbGlWindowInterface;
|
class XcbGlWindowInterface;
|
||||||
class XcbGlInterface;
|
class XcbGlInterface;
|
||||||
|
|
||||||
|
class FontsManager;
|
||||||
|
|
||||||
struct xcb_connection_t;
|
struct xcb_connection_t;
|
||||||
|
|
||||||
namespace mt
|
namespace mt
|
||||||
|
@ -19,7 +22,7 @@ public:
|
||||||
XcbWindow(mt::Window* window, int hwnd, xcb_connection_t* connection, XcbGlInterface* xcbGlInterface);
|
XcbWindow(mt::Window* window, int hwnd, xcb_connection_t* connection, XcbGlInterface* xcbGlInterface);
|
||||||
virtual ~XcbWindow();
|
virtual ~XcbWindow();
|
||||||
|
|
||||||
static void add(mt::Window* window, xcb_connection_t* connection, mt::Screen* screen, uint32_t eventMask, XcbGlInterface* xcbGlInterface);
|
static void add(mt::Window* window, xcb_connection_t* connection, mt::Screen* screen, uint32_t eventMask, FontsManager* fontsManager, XcbGlInterface* xcbGlInterface);
|
||||||
|
|
||||||
int getHandle() const;
|
int getHandle() const;
|
||||||
unsigned getGraphicsContext() const;
|
unsigned getGraphicsContext() const;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include "FreeTypeFontEngine.h"
|
#include "FreeTypeFontEngine.h"
|
||||||
|
#include "Image.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "PngWriter.h"
|
#include "PngWriter.h"
|
||||||
#include "DrawingManager.h"
|
|
||||||
#include "DrawingSurface.h"
|
#include "DrawingSurface.h"
|
||||||
#include "DrawingContext.h"
|
#include "DrawingContext.h"
|
||||||
#include "Grid.h"
|
#include "Grid.h"
|
||||||
|
@ -12,11 +11,13 @@
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
DrawingManager manager;
|
DrawingManager manager;
|
||||||
manager.InitalizeSurface(200, 200);
|
manager.InitalizeSurface(200, 200);
|
||||||
manager.InitializeContext();
|
manager.InitializeContext();
|
||||||
|
|
||||||
auto line = LineSegment::Create(Point(10.0, 10.0), Point(190.0, 190.0));
|
auto line = LineSegment::Create(Point(10.0, 10.0), Point(190.0, 190.0));
|
||||||
|
*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue