Selection working partially. Needs global z-index hovering to work reliably.
This commit is contained in:
+22
-2
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "draggable.h"
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
#include "state.h"
|
||||
namespace VISEQ::APP::CANVAS {
|
||||
@@ -10,9 +11,10 @@ namespace VISEQ::APP::CANVAS {
|
||||
|
||||
Camera2D camera;
|
||||
Vec2Df camera_delta;
|
||||
Vec2Df select_start;
|
||||
|
||||
virtual bool hovering() override {
|
||||
return true;
|
||||
virtual bool hovering() override {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void drag() override {
|
||||
@@ -23,15 +25,33 @@ namespace VISEQ::APP::CANVAS {
|
||||
|
||||
virtual void drawStart(){
|
||||
BeginMode2D(camera);
|
||||
state->hovering = false;
|
||||
if(hovering()) state->istate = InteractionState::HOVER_CANVAS;
|
||||
}
|
||||
|
||||
virtual void drawEnd(){
|
||||
EndMode2D();
|
||||
}
|
||||
|
||||
void select(){
|
||||
|
||||
if(state->mouse_left.clicked){
|
||||
select_start = state->screen_mouse;
|
||||
state->istate = InteractionState::DRAW_SELECTION;
|
||||
}
|
||||
|
||||
if(state->mouse_left.down){
|
||||
Vec2Df select1 = {state->screen_mouse.x > select_start.x ? select_start.x : state->screen_mouse.x, state->screen_mouse.y > select_start.y ? select_start.y : state->screen_mouse.y};
|
||||
Vec2Df select2 = {state->screen_mouse.x > select_start.x ? state->screen_mouse.x - select_start.x : select_start.x - state->screen_mouse.x, state->screen_mouse.y > select_start.y ? state->screen_mouse.y - select_start.y : select_start.y - state->screen_mouse.y};
|
||||
DrawRectangleLines(select1.x, select1.y, select2.x, select2.y, (Color){150,150,150,150});
|
||||
state->selection = (Rectangle){select1.x, select1.y, select2.x, select2.y};
|
||||
}
|
||||
}
|
||||
|
||||
virtual void draw(){
|
||||
camera_delta = state->mouse_delta * (-1.0f/camera.zoom);
|
||||
if(hovering()) drag();
|
||||
if(state->istate == InteractionState::HOVER_CANVAS || state->istate == InteractionState::DRAW_SELECTION) select();
|
||||
|
||||
float wheel = GetMouseWheelMove();
|
||||
if(wheel != 0){
|
||||
|
||||
Reference in New Issue
Block a user