Graphics refactor finished
This commit is contained in:
parent
37b4993b70
commit
476da8bb92
12 changed files with 114 additions and 110 deletions
|
|
@ -1,37 +1,35 @@
|
|||
|
||||
#include "GraphicApplication.hpp"
|
||||
|
||||
#include "Sketch3D.hpp"
|
||||
|
||||
#include "Graphics.hpp"
|
||||
#include "Window.hpp"
|
||||
#include "Sketch3DWidget.hpp"
|
||||
|
||||
void runApp() {
|
||||
using namespace tp;
|
||||
|
||||
class Sketch3DApplication : public Application {
|
||||
public:
|
||||
Sketch3DApplication() : mGui(*mGraphics->getCanvas(), {1920, 1080}) {}
|
||||
|
||||
void processFrame(EventHandler* eventHandler) override {
|
||||
auto rec = RectF( { 0, 0 }, mWindow->getSize() );
|
||||
mGui.proc(*eventHandler, rec, rec);
|
||||
}
|
||||
|
||||
void drawFrame(Canvas* canvas) override {
|
||||
mGui.draw(*canvas);
|
||||
}
|
||||
|
||||
private:
|
||||
Sketch3DGUI<EventHandler, Canvas> mGui;
|
||||
};
|
||||
|
||||
|
||||
void runApp() {
|
||||
tp::GlobalGUIConfig config;
|
||||
tp::gGlobalGUIConfig = &config;
|
||||
|
||||
auto window = tp::Window::createWindow(800, 600, "Window 1");
|
||||
|
||||
{
|
||||
tp::Sketch3DGUI<tp::Window::Events, tp::Graphics::Canvas> gui(window->getCanvas(), {1920, 1080});
|
||||
|
||||
if (window) {
|
||||
while (!window->shouldClose()) {
|
||||
window->processEvents();
|
||||
|
||||
auto area = window->getCanvas().getAvaliableArea();
|
||||
|
||||
gui.proc(window->getEvents(), { area.x, area.y, area.z, area.w }, { area.x, area.y, area.z, area.w });
|
||||
gui.draw(window->getCanvas());
|
||||
|
||||
tp::sleep(10);
|
||||
|
||||
window->draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tp::Window::destroyWindow(window);
|
||||
Sketch3DApplication app;
|
||||
app.run();
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
@ -43,11 +41,7 @@ int main() {
|
|||
return 1;
|
||||
}
|
||||
|
||||
tp::HeapAllocGlobal::disableCallstack();
|
||||
|
||||
runApp();
|
||||
|
||||
// FIXME : leaks in stacktrace itself
|
||||
|
||||
binModule.deinitialize();
|
||||
}
|
||||
|
|
@ -26,21 +26,21 @@ namespace tp {
|
|||
this->mVisible = area.isOverlap(areaParent);
|
||||
if (!this->mVisible) return;
|
||||
|
||||
if (!this->mArea.isInside(events.getPos())) {
|
||||
if (!this->mArea.isInside(events.getPointer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto crs = (events.getPos() - this->mArea.pos);
|
||||
auto crs = (events.getPointer() - this->mArea.pos);
|
||||
crs.x /= this->mArea.z;
|
||||
crs.y /= this->mArea.w;
|
||||
crs = (crs - 0.5) * 2;
|
||||
|
||||
// TODO : make better api for events
|
||||
Vec2F absolutePos = events.getPos() - this->mArea.pos;
|
||||
Vec2F absolutePos = events.getPointer() - this->mArea.pos;
|
||||
|
||||
if (events.isPressed()) {
|
||||
if (events.isPressed(InputID::MOUSE1)) {
|
||||
mAction = true;
|
||||
} else if (events.isReleased()) {
|
||||
} else if (events.isReleased(InputID::MOUSE1)) {
|
||||
mAction = false;
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +48,8 @@ namespace tp {
|
|||
Vec2F relativePosPrev = ((mActionPosAbsolutePrev / this->mArea.size) - 0.5f) * 2.f;
|
||||
Vec2F relativeDelta = relativePos - relativePosPrev;
|
||||
|
||||
mProject.mCamera.setRatio(this->mArea.w / this->mArea.z);
|
||||
|
||||
switch (mMode) {
|
||||
case Mode::MOVE: {
|
||||
if (mAction) mProject.mCamera.move(relativePos, relativePosPrev);
|
||||
|
|
@ -63,7 +65,7 @@ namespace tp {
|
|||
break;
|
||||
}
|
||||
case Mode::DRAW: {
|
||||
mProject.sample(events.pressure, this->mArea.w / this->mArea.z, crs);
|
||||
mProject.sample(events.getPointerPressure(), this->mArea.w / this->mArea.z, crs);
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue