summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jones <admin@danieljon.es>2020-06-27 12:08:49 +0930
committerDaniel Jones <admin@danieljon.es>2020-06-27 12:08:49 +0930
commit353954259bbd23b30c4c5025d682751192a3f745 (patch)
tree6258a425d074bcbaee24080e41f2b402371de9f6
parent2dcc781681c73732fda1f9b4fb1bfefa833af58e (diff)
downloadfoxlogicgates-353954259bbd23b30c4c5025d682751192a3f745.tar.gz
foxlogicgates-353954259bbd23b30c4c5025d682751192a3f745.zip
Functionality: added ability to rubberband select gates
this however only works in topleft->bottomright direction for now
-rw-r--r--MainWindow.cpp72
-rw-r--r--MainWindow.h5
2 files changed, 76 insertions, 1 deletions
diff --git a/MainWindow.cpp b/MainWindow.cpp
index 01d14ef..e59ea65 100644
--- a/MainWindow.cpp
+++ b/MainWindow.cpp
@@ -257,6 +257,16 @@ MainWindow::draw()
{
dc_image.drawHashBox(selected_gate->get_x(), selected_gate->get_y(), selected_gate->get_width(), selected_gate->get_height());
}
+ else if (!selected_gates.empty())
+ {
+ /* draw border box if multuple gates selected */
+ Gate *selgate;
+ for (auto g = selected_gates.begin(); g != selected_gates.end(); ++g)
+ {
+ selgate = (*g);
+ dc_image.drawHashBox(selgate->get_x(), selgate->get_y(), selgate->get_width(), selgate->get_height());
+ }
+ }
/* draw dragging link */
if (dragging_link && selected_gate)
@@ -323,6 +333,15 @@ MainWindow::draw()
}
+ /*draw rubber band */
+ if (rubberbanding)
+ {
+ FXint mousex, mousey;
+ FXuint mbuttons;
+ canvas->getCursorPosition(mousex, mousey, mbuttons);
+ dc_image.drawRectangle(rubberband_startx, rubberband_starty, mousex-rubberband_startx, mousey-rubberband_starty);
+ }
+
/* update options panel */
if (selected_gate)
{
@@ -337,6 +356,7 @@ MainWindow::draw()
output_details->setText("(None)");
}
+
FXDCWindow dc_canvas(canvas);
dc_canvas.drawImage(canvas_image, 0, 0);
}
@@ -660,6 +680,38 @@ MainWindow::remove_all_gates()
draw();
}
+void
+MainWindow::find_gates_in_area(int x, int y, int width, int height)
+{
+ /*
+ * find all gates in a given rectangle
+ */
+ Gate *gate;
+ int gx, gy, gw, gh;
+ for (auto g = gates.begin(); g != gates.end(); ++g)
+ {
+ gate = (*g).get();
+ gx = gate->get_x();
+ gy = gate->get_y();
+ gw = gate->get_width();
+ gh = gate->get_height();
+
+ /* check if rectangles intersect */
+ if(gx < x+width && gx+gw > x
+ && gy < y+height && gy+gh > y)
+ {
+ printf("adding gate %d to selected gates list\n", gate->get_id());
+ selected_gates.push_back(gate);
+ }
+ if (!selected_gates.empty())
+ {
+ selected_gate = nullptr;
+ selected_input.gate = nullptr;
+ selected_input.input = -1;
+ }
+ }
+}
+
long
MainWindow::on_paint(FXObject*, FXSelector, void *ptr)
{
@@ -715,6 +767,17 @@ MainWindow::on_left_mouse_down(FXObject*, FXSelector, void *ptr)
/* an input is selected */
}
}
+ else
+ {
+ rubberbanding = true;
+ rubberband_startx = ev->last_x;
+ rubberband_starty = ev->last_y;
+ }
+
+ if (!selected_gates.empty())
+ {
+ selected_gates.clear();
+ }
}
draw();
return 1;
@@ -765,6 +828,13 @@ MainWindow::on_left_mouse_up(FXObject*, FXSelector, void *ptr)
}
dragging_link = false;
}
+ if (rubberbanding)
+ {
+ rubberbanding = false;
+ find_gates_in_area(rubberband_startx, rubberband_starty, ev->last_x-rubberband_startx, ev->last_y-rubberband_starty);
+ draw();
+ }
+
return 1;
}
@@ -889,9 +959,9 @@ MainWindow::on_key_release(FXObject *sender, FXSelector sel, void *ptr)
long
MainWindow::on_mouse_move(FXObject *sender, FXSelector sel, void *ptr)
{
+ FXEvent* event = (FXEvent*)ptr;
if (lmouse_down && !dragging_link && selected_gate)
{
- FXEvent* event = (FXEvent*)ptr;
selected_gate->set_x(event->last_x-selected_gate->get_width()/2);
selected_gate->set_y(event->last_y-selected_gate->get_height()/2);
}
diff --git a/MainWindow.h b/MainWindow.h
index 484ebaa..04162ed 100644
--- a/MainWindow.h
+++ b/MainWindow.h
@@ -101,6 +101,7 @@ class MainWindow : public FXMainWindow
Gate *find_gate_at(int x, int y);
Gate *find_gate_by_id(int id);
void remove_all_gates();
+ void find_gates_in_area(int x, int y, int width, int height);
bool save_file();
bool load_file();
@@ -148,11 +149,15 @@ class MainWindow : public FXMainWindow
Gate::GATE_TYPE selected_gate_type = Gate::NONE; // the type of gate we will place
struct selected_input selected_input;
+ std::vector<Gate *> selected_gates;
/* mouse */
bool lmouse_down = false;
bool rmouse_down = false;
bool dragging_link = false;
+ bool rubberbanding = false;
+ int rubberband_startx;
+ int rubberband_starty;
/* keyboard */
bool lshift_down = false;