Graphics refactor finished
This commit is contained in:
parent
37b4993b70
commit
476da8bb92
12 changed files with 114 additions and 110 deletions
|
|
@ -138,8 +138,11 @@ void Canvas::deleteImageHandle(ImageHandle image) {
|
|||
void Canvas::drawBegin() {
|
||||
const auto size = mContext->window->getSize();
|
||||
nvgBeginFrame(mContext->vg, size.x, size.y, 1.0);
|
||||
glViewport(0, 0, size.x, size.y);
|
||||
}
|
||||
|
||||
void Canvas::drawEnd() {
|
||||
const auto size = mContext->window->getSize();
|
||||
glViewport(0, 0, size.x, size.y);
|
||||
nvgEndFrame(mContext->vg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "EventHandler.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace tp;
|
||||
|
||||
EventHandler::EventHandler() = default;
|
||||
|
|
@ -23,13 +25,13 @@ InputState::State transitions[4][4] = {
|
|||
{ InputState::State::NONE, InputState::State::PRESSED, InputState::State::PRESSED, InputState::State::NONE },
|
||||
{ InputState::State::PRESSED, InputState::State::PRESSED, InputState::State::HOLD, InputState::State::PRESSED },
|
||||
{ InputState::State::HOLD, InputState::State::RELEASED, InputState::State::RELEASED, InputState::State::HOLD },
|
||||
{ InputState::State::RELEASED, InputState::State::NONE, InputState::State::RELEASED, InputState::State::RELEASED },
|
||||
{ InputState::State::RELEASED, InputState::State::NONE, InputState::State::NONE, InputState::State::RELEASED },
|
||||
};
|
||||
|
||||
bool transitionsReduce[4][4] = {
|
||||
{ true, true, false, true },
|
||||
{ true, true, false, true },
|
||||
{ true, false, true, true },
|
||||
{ true, false, false, true },
|
||||
{ true, false, true, true },
|
||||
};
|
||||
|
||||
|
|
@ -69,6 +71,8 @@ void EventHandler::processEvent() {
|
|||
}
|
||||
}
|
||||
|
||||
mPointerPressure = mInputStates[(int) InputID::MOUSE1].mCurrentState != InputState::State::NONE;
|
||||
|
||||
mMutex.unlock();
|
||||
}
|
||||
|
||||
|
|
@ -82,6 +86,10 @@ bool EventHandler::isReleased(InputID id) const {
|
|||
return mInputStates[(int) id].mCurrentState == InputState::State::RELEASED;
|
||||
}
|
||||
|
||||
halnf EventHandler::getPointerPressure() const {
|
||||
return mPointerPressure;
|
||||
}
|
||||
|
||||
bool EventHandler::isDown(InputID id) const {
|
||||
return mInputStates[(int) id].mCurrentState == InputState::State::PRESSED ||
|
||||
mInputStates[(int) id].mCurrentState == InputState::State::HOLD;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using namespace tp;
|
|||
|
||||
Application::Application() {
|
||||
mWindow = Window::createWindow();
|
||||
mGraphics = new Graphics(mWindow);
|
||||
|
||||
mDrawTimer.setDuration(1000.f / mDrawPerSecond);
|
||||
mProcTimer.setDuration(1000.f / mProcPerSecond);
|
||||
|
|
@ -12,7 +13,6 @@ Application::Application() {
|
|||
}
|
||||
|
||||
void Application::run() {
|
||||
Graphics graphics(mWindow);
|
||||
auto eventHandler = new EventHandler();
|
||||
|
||||
mWindow->setEventHandler(eventHandler);
|
||||
|
|
@ -44,11 +44,11 @@ void Application::run() {
|
|||
mDrawTimer.reset();
|
||||
|
||||
if (redrawNeeded) {
|
||||
graphics.drawBegin();
|
||||
mGraphics->drawBegin();
|
||||
|
||||
drawFrame(graphics.getCanvas());
|
||||
drawFrame(mGraphics->getCanvas());
|
||||
|
||||
graphics.drawEnd();
|
||||
mGraphics->drawEnd();
|
||||
|
||||
mWindow->draw();
|
||||
|
||||
|
|
@ -79,5 +79,6 @@ void Application::drawFrame(Canvas* canvas) {
|
|||
}
|
||||
|
||||
Application::~Application() {
|
||||
delete mGraphics;
|
||||
Window::destroyWindow(mWindow);
|
||||
}
|
||||
|
|
@ -96,8 +96,6 @@ bool Window::shouldClose() const { return glfwWindowShouldClose(mContext->window
|
|||
void Window::processEvents() {
|
||||
glfwWaitEvents();
|
||||
checkAxisUpdates();
|
||||
|
||||
glViewport(0, 0, mSize.x, mSize.y);
|
||||
}
|
||||
|
||||
void Window::draw() {
|
||||
|
|
|
|||
|
|
@ -69,11 +69,13 @@ namespace tp {
|
|||
bool isEvents();
|
||||
void processEvent();
|
||||
|
||||
const Vec2F& getPointer() const;
|
||||
bool isPressed(InputID id) const;
|
||||
bool isReleased(InputID id) const;
|
||||
bool isDown(InputID id) const;
|
||||
halnf getScrollY() const;
|
||||
[[nodiscard]] const Vec2F& getPointer() const;
|
||||
[[nodiscard]] bool isPressed(InputID id) const;
|
||||
[[nodiscard]] bool isReleased(InputID id) const;
|
||||
[[nodiscard]] bool isDown(InputID id) const;
|
||||
[[nodiscard]] halnf getScrollY() const;
|
||||
|
||||
[[nodiscard]] halnf getPointerPressure() const;
|
||||
|
||||
private:
|
||||
std::mutex mMutex = {};
|
||||
|
|
@ -83,7 +85,7 @@ namespace tp {
|
|||
|
||||
// input states
|
||||
Vec2F mPointer;
|
||||
halnf pressure = 0;
|
||||
halnf mPointerPressure = 0;
|
||||
|
||||
InputState mInputStates[(int) InputID::LAST_KEY_CODE]{};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ namespace tp {
|
|||
virtual ~Application();
|
||||
|
||||
protected:
|
||||
Window* mWindow = nullptr;
|
||||
|
||||
bool mInitialized = false;
|
||||
|
||||
ualni mDrawPerSecond = 60;
|
||||
|
|
@ -34,5 +32,8 @@ namespace tp {
|
|||
|
||||
halnf mFramesProcessed = 0;
|
||||
halnf mFramesDrawn = 0;
|
||||
|
||||
Graphics* mGraphics = nullptr;
|
||||
Window* mWindow = nullptr;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue