Clean up fontsmanager

This commit is contained in:
jmsgrogan 2023-01-12 11:54:08 +00:00
parent 076e32b1d6
commit 64f0b3e77a
26 changed files with 111 additions and 89 deletions

View file

@ -67,23 +67,23 @@ void MainApplication::initialize(CommandLineArgsUPtr commandLineArgs, std::uniqu
void MainApplication::run()
{
std::string program_type;
if(mCommandLineArgs->getNumberOfArgs() > 1)
if(mCommandLineArgs->getArgs().size() > 1)
{
program_type = mCommandLineArgs->getArg(1);
program_type = mCommandLineArgs->getArgs()[1];
}
std::string input_path;
std::string output_path;
for(unsigned idx=1; idx<mCommandLineArgs->getNumberOfArgs(); idx++)
for(unsigned idx=1; idx< mCommandLineArgs->getArgs().size(); idx++)
{
auto arg = mCommandLineArgs->getArg(idx);
if(arg == "-input" && mCommandLineArgs->getNumberOfArgs() > idx+1)
auto arg = mCommandLineArgs->getArgs()[idx];
if(arg == "-input" && mCommandLineArgs->getArgs().size() > idx+1)
{
input_path = mCommandLineArgs->getArg(idx + 1);
input_path = mCommandLineArgs->getArgs()[idx + 1];
}
else if(arg == "-output" && mCommandLineArgs->getNumberOfArgs() > idx+1)
else if(arg == "-output" && mCommandLineArgs->getArgs().size() > idx+1)
{
output_path = mCommandLineArgs->getArg(idx + 1);
output_path = mCommandLineArgs->getArgs()[idx + 1];
}
}

View file

@ -61,20 +61,6 @@ void CommandLineArgs::process(const std::vector<std::string>& args)
mArugments = args;
}
std::size_t CommandLineArgs::getNumberOfArgs() const
{
return mArugments.size();
}
std::string CommandLineArgs::getArg(std::size_t index) const
{
if(index<mArugments.size())
{
return mArugments[index];
}
return "";
}
std::vector<std::string> CommandLineArgs::getUserArgs() const
{
std::vector<std::string> user_args;
@ -84,3 +70,8 @@ std::vector<std::string> CommandLineArgs::getUserArgs() const
}
return user_args;
}
const std::vector<std::string> CommandLineArgs::getArgs() const
{
return mArugments;
}

View file

@ -7,16 +7,13 @@
class CommandLineArgs
{
public:
CommandLineArgs();
static std::unique_ptr<CommandLineArgs> Create();
std::filesystem::path getLaunchPath();
std::size_t getNumberOfArgs() const;
std::string getArg(std::size_t index) const;
const std::vector<std::string> getArgs() const;
void process(int argc, char *argv[]);

View file

@ -8,11 +8,11 @@
#include "FontGlyph.h"
FontsManager::FontsManager()
{
#ifdef HAS_FREETYPE
mFontEngine = std::make_unique<FreeTypeFontEngine>();
mUsesGlyphs = true;
#else
mFontEngine = std::make_unique<BasicFontEngine>();
#endif
@ -24,6 +24,11 @@ std::unique_ptr<FontsManager> FontsManager::Create()
return std::make_unique<FontsManager>();
}
bool FontsManager::usesGlyphs() const
{
return mUsesGlyphs;
}
IFontEngine* FontsManager::getFontEngine() const
{
return mFontEngine.get();

View file

@ -1,12 +1,12 @@
#pragma once
#include "IFontEngine.h"
#include "FontGlyph.h"
#include <memory>
#include <string>
#include <unordered_map>
class IFontEngine;
class FontGlyph;
class FontsManager
{
public:
@ -15,11 +15,13 @@ public:
IFontEngine* getFontEngine() const;
bool usesGlyphs() const;
FontGlyph* getGlyph(const std::string& fontFace, int size, uint32_t c);
private:
bool mUsesGlyphs{ false };
std::unique_ptr<IFontEngine> mFontEngine;
std::unordered_map<uint32_t, std::unique_ptr<FontGlyph> > mGlyphs;
};

View file

@ -108,9 +108,19 @@ void DirectXMeshPainter::updateBuffers(DrawingContext* context)
auto scene = context->getSurface()->getScene();
for (const auto item : scene->getItems())
{
if (item->getType() == SceneItem::Type::MODEL && item->isVisible())
if (!item->isVisible())
{
continue;
}
if (item->getType() == SceneItem::Type::MODEL)
{
auto model = dynamic_cast<SceneModel*>(item);
if (model->getGeometry())
{
continue;
}
auto dx_mesh = std::make_unique<DirectXMesh>(model);
dx_mesh->update(context, mDxInterface->getD3dDevice());
mDxMeshes.push_back(std::move(dx_mesh));

View file

@ -84,14 +84,14 @@ void DirectXPainter::initializeDxInterface()
void DirectXPainter::resetPainters()
{
m2dPainter->setD2dInterface(mDxInterface->getD2dInterface());
mTextPainter->setD2dInterface(mDxInterface->getD2dInterface());
m2dPainter->setD2dInterface(getDxInterface()->getD2dInterface());
mTextPainter->setD2dInterface(getDxInterface()->getD2dInterface());
mMeshPainter->setDxInterface(getDxInterface());
}
void DirectXPainter::paint()
{
if (!mDxInterface)
if (!getDxInterface())
{
initializeDxInterface();
}

View file

@ -6,8 +6,6 @@
#include "FontsManager.h"
#include "FontGlyph.h"
#include "DirectXShaderProgram.h"
#include "TextData.h"
#include "SceneText.h"
#include "DirectX2dInterface.h"

View file

@ -23,7 +23,7 @@
namespace mt
{
Window::Window()
Window::Window(DrawingMode drawingMode, FontsManager* fontsManager)
: DrawingSurface(),
mWidget(Widget::Create())
{
@ -31,6 +31,8 @@ Window::Window()
mHeight = 600;
mWidget->setBounds(mWidth, mHeight);
mWidget->setWindow(this);
mDrawingContext = std::make_unique<DrawingContext>(this, fontsManager, drawingMode);
}
Window::~Window()
@ -38,9 +40,9 @@ Window::~Window()
}
std::unique_ptr<Window> Window::Create()
std::unique_ptr<Window> Window::Create(DrawingMode drawingMode, FontsManager* fontsManager)
{
return std::make_unique<Window>();
return std::make_unique<Window>(drawingMode, fontsManager);
}
void Window::setIsSizingOnGoing(bool sizingOngoing)
@ -117,10 +119,9 @@ IPlatformWindow* Window::getPlatformWindow() const
return nullptr;
}
void Window::setPlatformWindow(IPlatformWindowPtr window, FontsManager* fontsManager, DrawingMode drawingMode)
void Window::setPlatformWindow(IPlatformWindowPtr window)
{
mPlatformWindow = std::move(window);
mDrawingContext = std::make_unique<DrawingContext>(this, fontsManager, drawingMode);
}
void Window::map()

View file

@ -2,6 +2,8 @@
#include "DrawingSurface.h"
#include "DisplayState.h"
#include "DrawingContext.h"
#include "Widget.h"
#include <memory>
#include <vector>
@ -17,7 +19,6 @@ class DrawingContext;
class FontsManager;
enum class DrawingMode;
class Widget;
using WidgetPtr = std::unique_ptr<Widget>;
class IPlatformWindow;
using IPlatformWindowPtr = std::unique_ptr<IPlatformWindow>;
@ -33,11 +34,11 @@ class Window : public DrawingSurface
public:
using onPopupFunc = std::function<void(mt::Window* parent, std::unique_ptr<Widget> popup)>;
Window();
Window(DrawingMode drawingMode = DrawingMode::GRAPH, FontsManager* fontsManager = nullptr);
~Window();
static std::unique_ptr<Window> Create();
static std::unique_ptr<Window> Create(DrawingMode drawingMode = DrawingMode::GRAPH, FontsManager* fontsManager = nullptr);
void addPopup(std::unique_ptr<Widget> popupWidget);
@ -71,7 +72,7 @@ public:
void onKeyboardEvent(const KeyboardEvent* event);
void setPlatformWindow(IPlatformWindowPtr window, FontsManager* fontsManager, DrawingMode drawingMode);
void setPlatformWindow(IPlatformWindowPtr window);
void setPopupHandler(onPopupFunc func);

View file

@ -107,7 +107,7 @@ std::size_t TextNode::getNumSceneItems() const
void TextNode::updateLines(FontsManager* fontsManager)
{
if (!fontsManager)
if (!fontsManager || !fontsManager->usesGlyphs())
{
return;
}

View file

@ -79,9 +79,13 @@ endif()
list(APPEND windows_LIB_INCLUDES
ui_interfaces/AbstractUiInterface.h
ui_interfaces/UiInterfaceFactory.cpp
managers/WindowManager.h
managers/DesktopManager.h
managers/EventManager.h
managers/WindowManager.cpp
managers/DesktopManager.cpp
managers/EventManager.cpp)
managers/EventManager.cpp
)
# add the library
add_library(windows SHARED ${windows_LIB_INCLUDES} ${platform_INCLUDES})

View file

@ -12,7 +12,8 @@ DesktopManager::DesktopManager(AbstractDesktopApp* application)
: mScreens(),
mKeyboard(Keyboard::Create()),
mUiApplication(application),
mEventManager(EventManager::Create())
mEventManager(EventManager::Create()),
mFontsManager(FontsManager::Create())
{
mWindowManager = WindowManager::Create(this);
}
@ -32,6 +33,11 @@ void DesktopManager::clearEvents()
mEventManager->ClearEvents();
}
FontsManager* DesktopManager::getFontsManager() const
{
return mFontsManager.get();
}
void DesktopManager::onKeyboardEvent(const KeyboardEvent* event)
{
mWindowManager->onKeyboardEvent(event);

View file

@ -12,13 +12,13 @@
#include "UiEvent.h"
#include "AbstractApp.h"
#include "EventManager.h"
#include "FontsManager.h"
class AbstractDesktopApp;
class DesktopManager
{
public:
DesktopManager(AbstractDesktopApp* application);
~DesktopManager();
@ -33,6 +33,8 @@ public:
Keyboard* getKeyboard() const;
FontsManager* getFontsManager() const;
void addScreen(ScreenPtr screen);
mt::Screen* getDefaultScreen() const;
@ -55,6 +57,8 @@ public:
private:
std::vector<ScreenPtr> mScreens;
FontsManagerPtr mFontsManager;
WindowManagerUPtr mWindowManager;
KeyboardUPtr mKeyboard;
EventManagerUPtr mEventManager;

View file

@ -1,15 +1,12 @@
#include "WindowManager.h"
#include "DesktopManager.h"
#include "Widget.h"
#include <iostream>
WindowManager::WindowManager(DesktopManager* desktopManager)
: mWindows(),
mDesktopManager(desktopManager)
{
addWindow(mt::Window::Create());
addWindow(mt::Window::Create(mDrawMode, desktopManager->getFontsManager()));
}
WindowManager::~WindowManager()
@ -53,7 +50,7 @@ void WindowManager::addWindow(WindowUPtr window)
void WindowManager::onAddPopupWindow(mt::Window* parent, std::unique_ptr<Widget> widget)
{
auto popup = mt::Window::Create();
auto popup = mt::Window::Create(mDrawMode, mDesktopManager->getFontsManager());
popup->setWidget(std::move(widget));
popup->setParent(parent);

View file

@ -4,6 +4,8 @@
#include <memory>
#include "Window.h"
#include "DrawingContext.h"
#include "PaintEvent.h"
#include "MouseEvent.h"
#include "ResizeEvent.h"
@ -51,6 +53,7 @@ public:
private:
std::vector<WindowUPtr> mWindows;
DrawingMode mDrawMode{ DrawingMode::GRAPH };
DesktopManager* mDesktopManager{nullptr};
};

View file

@ -1,9 +1,6 @@
#pragma once
#include <memory>
#include "IFontEngine.h"
#include "FontsManager.h"
#include "FontGlyph.h"
namespace mt
{
@ -11,16 +8,14 @@ namespace mt
}
class DesktopManager;
class FontsManager;
class AbstractUIInterface
{
public:
AbstractUIInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = false)
AbstractUIInterface(DesktopManager* desktopManager, bool useHardware = false)
: mDesktopManager(desktopManager),
mUseHardwareRendering(useHardware),
mFontsManager(std::move(fontsManager))
mUseHardwareRendering(useHardware)
{
}
@ -39,7 +34,5 @@ protected:
virtual void initializeHardwareRendering() {};
DesktopManager* mDesktopManager{nullptr};
std::unique_ptr<FontsManager> mFontsManager;
bool mUseHardwareRendering{false};
};

View file

@ -8,8 +8,8 @@ class NullUIInterface : public AbstractUIInterface
{
public:
NullUIInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = false)
: AbstractUIInterface(desktopManager, std::move(fontsManager), useHardware)
NullUIInterface(DesktopManager* desktopManager, bool useHardware = false)
: AbstractUIInterface(desktopManager, useHardware)
{
};

View file

@ -13,38 +13,36 @@
#include "NullUiInterface.h"
#include "FontsManager.h"
#include "Widget.h"
std::unique_ptr<AbstractUIInterface> UiInterfaceFactory::create(DesktopManager* desktopManager, Backend backend)
{
auto fonts_manager = std::make_unique<FontsManager>();
#ifdef __linux__
if (backend == Backend::UNSET || backend == Backend::X11 || backend == Backend::X11_RASTER)
{
#ifdef HAS_X11
const bool use_hardware = (backend != Backend::X11_RASTER);
return std::make_unique<XcbInterface>(desktopManager, std::move(fonts_manager), use_hardware);
return std::make_unique<XcbInterface>(desktopManager, use_hardware);
#else
return std::make_unique<NullUIInterface>(desktopManager, std::move(fonts_manager));
return std::make_unique<NullUIInterface>(desktopManager);
#endif
}
else
{
#ifdef HAS_WAYLAND
const bool use_hardware = (backend != Backend::WAYLAND_RASTER);
return std::make_unique<WaylandInterface>(desktopManager, std::move(fonts_manager), use_hardware);
return std::make_unique<WaylandInterface>(desktopManager, use_hardware);
#else
#ifdef HAS_X11
const bool use_hardware = (backend != Backend::X11_RASTER);
return std::make_unique<XcbInterface>(desktopManager, std::move(fonts_manager), use_hardware);
return std::make_unique<XcbInterface>(desktopManager, use_hardware);
#else
return std::make_unique<NullUIInterface>(desktopManager, std::move(fonts_manager));
return std::make_unique<NullUIInterface>(desktopManager);
#endif
#endif
}
#else
return std::make_unique<Win32UIInterface>(desktopManager, std::move(fonts_manager), true);
return std::make_unique<Win32UIInterface>(desktopManager, true);
#endif
}

View file

@ -1,6 +1,5 @@
#include "Win32UIInterface.h"
#include "Widget.h"
#include "DesktopManager.h"
#include "DirectXInterface.h"
#include "DirectX2dInterface.h"
@ -10,8 +9,8 @@
#include <dxgi1_6.h>
#include <Windows.h>
Win32UIInterface::Win32UIInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware)
: AbstractUIInterface(desktopManager, std::move(fontsManager), useHardware),
Win32UIInterface::Win32UIInterface(DesktopManager* desktopManager, bool useHardware)
: AbstractUIInterface(desktopManager, useHardware),
mWindowInterface(std::make_unique<Win32WindowInterface>())
{

View file

@ -13,7 +13,7 @@ using DirectXInterfacePtr = std::unique_ptr<DirectXInterface>;
class Win32UIInterface : public AbstractUIInterface
{
public:
Win32UIInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = false);
Win32UIInterface(DesktopManager* desktopManager, bool useHardware = false);
~Win32UIInterface() = default;

View file

@ -29,7 +29,7 @@ void Win32WindowInterface::add(mt::Window* window, DesktopManager* desktopManage
auto win32_window = Win32Window::Create(window, dxInterface);
win32_window->createNative(context, desktopManager);
win32_window->setCmdShow(context->nCmdShow);
window->setPlatformWindow(std::move(win32_window), nullptr, DrawingMode::GRAPH);
window->setPlatformWindow(std::move(win32_window));
window->getPlatformWindow()->beforePaint(nullptr);
}

View file

@ -1,16 +1,8 @@
#include "TestCase.h"
#include "TestCaseRunner.h"
#include "TestUiApplication.h"
#include "TestFramework.h"
#include "DesktopManager.h"
#include "MeshPrimitives.h"
#include "MeshNode.h"
#include "RectangleNode.h"
#include "TextNode.h"
#include "Scene.h"
#include "Widget.h"
#include <memory>
#include <string>
@ -18,5 +10,15 @@
TEST_CASE(TestD2dRendering, "graphics")
{
auto gui_app = TestCaseRunner::getInstance().getTestApplication();
auto scene = gui_app->getMainWindowScene();
auto rect = std::make_unique<RectangleNode>(Point(10, 10), 200.0, 200.0);
scene->addNode(rect.get());
auto text_node = std::make_unique<TextNode>("Test2", Point(100, 100));
scene->addNode(text_node.get());
scene->update();
gui_app->run();
};

View file

@ -1,6 +1,7 @@
#include "TestUiApplication.h"
#include "MainApplication.h"
#include "DesktopManager.h"
TestUiApplication::TestUiApplication(std::unique_ptr<CommandLineArgs> args, std::unique_ptr<MainApplication> mainApp)
: GuiApplication(std::move(args), std::move(mainApp))
@ -11,4 +12,9 @@ TestUiApplication::TestUiApplication(std::unique_ptr<CommandLineArgs> args, std:
DesktopManager* TestUiApplication::getDesktopManager() const
{
return mDesktopManager.get();
}
Scene* TestUiApplication::getMainWindowScene() const
{
return mDesktopManager->getWindowManager()->getMainWindow()->getScene();
}

View file

@ -1,6 +1,7 @@
#pragma once
#include "GuiApplication.h"
#include "Scene.h"
#include <memory>
@ -10,4 +11,6 @@ public:
TestUiApplication(std::unique_ptr<CommandLineArgs> args = nullptr, std::unique_ptr<MainApplication> mainApp = nullptr);
DesktopManager* getDesktopManager() const;
Scene* getMainWindowScene() const;
};

View file

@ -23,6 +23,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
auto args = CommandLineArgs::Create();
CommandLineArgs::initialize(args.get());
const auto user_args = args->getUserArgs();
auto main_app = MainApplication::Create();
auto applicationContext = std::make_unique<Win32ApplicationContext>();
@ -41,7 +43,7 @@ int main(int argc, char *argv[])
#endif
TestCaseRunner::getInstance().setTestApplication(gui_app.get());
auto result = TestCaseRunner::getInstance().run({});
auto result = TestCaseRunner::getInstance().run(user_args);
#ifdef _WIN32
CoUninitialize();