Update widgets module. Raster example initial.

This commit is contained in:
IlyaShurupov 2024-04-12 15:27:40 +03:00
parent 9e339defd6
commit 9cfae3fe3e
48 changed files with 1169 additions and 530 deletions

View file

@ -1,8 +1,6 @@
#include "EventHandler.hpp"
#include <stdio.h>
using namespace tp;
EventHandler::EventHandler() = default;
@ -35,7 +33,6 @@ bool transitionsReduce[4][4] = {
{ true, false, true, true },
};
void EventHandler::processEvent() {
mMutex.lock();
auto lastEvent = mEventQueue.last();
@ -45,30 +42,30 @@ void EventHandler::processEvent() {
switch (eventData.type) {
case InputEvent::Type::MOUSE_POS:
{
mPointer = eventData.mouseEvent;
mEventQueue.popFront();
break;
}
case InputEvent::Type::BUTTON_ACTION:
{
auto currentState = (int) mInputStates[(int) inputId].mCurrentState;
auto reportedEvent = (int) eventData.buttonAction;
mInputStates[(int) inputId].mCurrentState = transitions[currentState][reportedEvent];
if (transitionsReduce[currentState][reportedEvent]) {
{
mPointer = eventData.mouseEvent;
mEventQueue.popFront();
break;
}
break;
}
case InputEvent::Type::BUTTON_ACTION:
{
auto currentState = (int) mInputStates[(int) inputId].mCurrentState;
auto reportedEvent = (int) eventData.buttonAction;
mInputStates[(int) inputId].mCurrentState = transitions[currentState][reportedEvent];
if (transitionsReduce[currentState][reportedEvent]) {
mEventQueue.popFront();
}
break;
}
default:
{
mEventQueue.popFront();
}
{
mEventQueue.popFront();
}
}
mPointerPressure = mInputStates[(int) InputID::MOUSE1].mCurrentState != InputState::State::NONE;
@ -78,7 +75,7 @@ void EventHandler::processEvent() {
const Vec2F& EventHandler::getPointer() const { return mPointer; }
bool EventHandler::isPressed(InputID id) const {
bool EventHandler::isPressed(InputID id) const {
return mInputStates[(int) id].mCurrentState == InputState::State::PRESSED;
}
@ -86,13 +83,11 @@ bool EventHandler::isReleased(InputID id) const {
return mInputStates[(int) id].mCurrentState == InputState::State::RELEASED;
}
halnf EventHandler::getPointerPressure() const {
return mPointerPressure;
}
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;
return mInputStates[(int) id].mCurrentState == InputState::State::PRESSED ||
mInputStates[(int) id].mCurrentState == InputState::State::HOLD;
}
halnf EventHandler::getScrollY() const { return 0; }

View file

@ -62,7 +62,7 @@ namespace tp {
ImageHandle createImageFromTextId(ualni id, Vec2F size);
void deleteImageHandle(ImageHandle image);
void drawImage(const RectF& rec, ImageHandle* image, halnf angle, halnf alpha, halnf rounding);
void drawImage(const RectF& rec, ImageHandle* image, halnf angle = 0, halnf alpha = 1.f, halnf rounding = 0.f);
private:
Buffer<RectF> mScissors;
@ -71,7 +71,9 @@ namespace tp {
class Graphics {
public:
explicit Graphics(Window* window) : mGui(window), mCanvas(window) {}
explicit Graphics(Window* window) :
mGui(window),
mCanvas(window) {}
void procBegin() {
mCanvas.procBegin();
@ -88,14 +90,12 @@ namespace tp {
mGui.drawBegin();
}
void drawEnd() {
void drawEnd() {
mCanvas.drawEnd();
mGui.drawEnd();
}
Canvas* getCanvas() {
return &mCanvas;
}
Canvas* getCanvas() { return &mCanvas; }
private:
Canvas mCanvas;