Fixes and improvements to the graphics module

This commit is contained in:
IlyaShurupov 2024-07-17 09:40:49 +03:00 committed by Ilya Shurupov
parent 860474654a
commit 5e3f5594b8
19 changed files with 161 additions and 55 deletions

View file

@ -71,9 +71,13 @@ namespace tp {
public: // User interface
bool isEvents();
void processEvent();
void processAllEvent();
[[nodiscard]] const Vec2F& getPointer() const;
[[nodiscard]] const Vec2F& getPointerPrev() const;
void setCursorOrigin(const Vec2F& origin);
[[nodiscard]] Vec2F getPointer() const;
[[nodiscard]] Vec2F getPointerPrev() const;
[[nodiscard]] Vec2F getPointerDelta() const;
[[nodiscard]] bool isPressed(InputID id) const;
@ -83,6 +87,9 @@ namespace tp {
[[nodiscard]] halnf getPointerPressure() const;
private:
void processEventUnguarded();
private:
std::mutex mMutex = {};
@ -90,6 +97,8 @@ namespace tp {
List<std::pair<InputID, InputEvent>> mEventQueue;
// input states
Vec2F mPointerOrigin = { 0, 0 };
Vec2F mPointer;
Vec2F mPointerPrev;
Vec2F mScrollDelta;

View file

@ -12,16 +12,24 @@ namespace tp {
void run();
virtual void processFrame(EventHandler* eventHandler);
virtual bool forceNewFrame() { return false; }
virtual void processFrame(EventHandler* eventHandler, halnf deltaTime);
virtual void drawFrame(Canvas* canvas);
virtual ~Application();
void drawDebug();
private:
void runDefaultLoop();
void runDebugLoop();
protected:
bool mInitialized = false;
ualni mDrawPerSecond = 60;
ualni mProcPerSecond = 160;
ualni mProcPerSecond = 100;
Timer mDrawTimer;
Timer mProcTimer;

View file

@ -55,21 +55,25 @@ namespace tp {
ualni id = 0;
};
void setOrigin(const Vec2F& origin);
void pushClamp(const RectF& rec);
void popClamp();
void rect(const RectF& rec, const RGBA& col, halnf round = 0);
void circle(const Vec2F& pos, halnf size, const RGBA& col);
void rect(RectF rec, const RGBA& col, halnf round = 0);
void circle(Vec2F pos, halnf size, const RGBA& col);
void text(const char*, const RectF&, halnf size, Align, halnf padding, const RGBA&);
ImageHandle createImageFromTextId(ualni id, Vec2F size);
void updateTextureID(ImageHandle handle, ualni id);
void deleteImageHandle(ImageHandle image);
void drawImage(const RectF& rec, ImageHandle* image, halnf angle = 0, halnf alpha = 1.f, halnf rounding = 0.f);
void drawImage(RectF rec, ImageHandle* image, halnf angle = 0, halnf alpha = 1.f, halnf rounding = 0.f);
private:
Buffer<RectF> mScissors;
bool mIsClamping = false;
Vec2F mOrigin = { 0, 0 };
};
class Graphics {

View file

@ -17,7 +17,7 @@ namespace tp {
public:
void draw();
void processEvents();
void processEvents(bool wait = true);
void setEventHandler(EventHandler* eventHandler);
[[nodiscard]] EventHandler* getEventHandler();