refactored from main to canvas.h - basic functionality working
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "draggable.h"
|
||||
#include "raymath.h"
|
||||
#include "state.h"
|
||||
namespace VISEQ::APP::CANVAS {
|
||||
class Canvas : public BASE::Draggable {
|
||||
public:
|
||||
Canvas() {}
|
||||
|
||||
Camera2D camera;
|
||||
Vec2Df camera_delta;
|
||||
|
||||
virtual bool hovering() override {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void drag() override {
|
||||
if(state->mouse_right.down) {
|
||||
camera.target = Vector2Add(camera.target, camera_delta);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void drawStart(){
|
||||
BeginMode2D(camera);
|
||||
}
|
||||
|
||||
virtual void drawEnd(){
|
||||
EndMode2D();
|
||||
}
|
||||
|
||||
virtual void draw(){
|
||||
camera_delta = state->mouse_delta * (-1.0f/camera.zoom);
|
||||
if(hovering()) drag();
|
||||
|
||||
float wheel = GetMouseWheelMove();
|
||||
if(wheel != 0){
|
||||
if(!IsKeyDown(KEY_LEFT_SHIFT) && !IsKeyDown(KEY_LEFT_CONTROL) && !IsKeyDown(KEY_LEFT_ALT)){
|
||||
camera.offset = state->raw_mouse;
|
||||
camera.target = state->screen_mouse;
|
||||
float scaleFactor = 1.0f + (0.25f*fabsf(wheel));
|
||||
if (wheel < 0) scaleFactor = 1.0f/scaleFactor;
|
||||
camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f);
|
||||
}
|
||||
}
|
||||
|
||||
for(int x = -state->settings.grid*100; x < state->settings.grid*100; x+=state->settings.grid){
|
||||
for(int y = -state->settings.grid*100; y < state->settings.grid*100; y+=state->settings.grid){
|
||||
DrawPixel(x, y, (Color){130,130,130,200});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user