summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jones <admin@danieljon.es>2020-06-29 23:14:23 +0930
committerDaniel Jones <admin@danieljon.es>2020-06-29 23:14:23 +0930
commit193fda2d270f63c127edc5b1082ef14ad12b1175 (patch)
tree8423cc822fd704f4c7b659f0ff6c9580147c4b2a
parent1e76ef7d2df9d49a905f416774f33fdedfcf6f34 (diff)
downloadfoxlogicgates-193fda2d270f63c127edc5b1082ef14ad12b1175.tar.gz
foxlogicgates-193fda2d270f63c127edc5b1082ef14ad12b1175.zip
further work deriving gates from Object
-rw-r--r--Gate.cpp1
-rw-r--r--Gate.h5
-rw-r--r--MainWindow.cpp41
3 files changed, 37 insertions, 10 deletions
diff --git a/Gate.cpp b/Gate.cpp
index a1ed3a7..00e3d00 100644
--- a/Gate.cpp
+++ b/Gate.cpp
@@ -19,6 +19,7 @@ int Object::object_id_counter = 0; // initialise static object counter FIXME: do
Gate::Gate(GATE_TYPE type, int x, int y, int width, int height, int loaded_id)
{
+ set_object_type(Object::GATE);
this->gate_type = type;
this->input_gate1 = nullptr;
this->input_gate2 = nullptr;
diff --git a/Gate.h b/Gate.h
index a0d8cf6..e5a6115 100644
--- a/Gate.h
+++ b/Gate.h
@@ -45,7 +45,6 @@ class Gate : public Object
GATE_TYPE get_gate_type() { return this->gate_type; };
Gate *get_input_gate1() { return this->input_gate1; };
Gate *get_input_gate2() { return this->input_gate2; };
- std::string get_output_type_text();
void set_state(bool state) { this->output_state = state; };
void set_input_gate1(Gate *gate) { this->input_gate1 = gate; };
void set_input_gate2(Gate *gate) { this->input_gate2 = gate; };
@@ -54,6 +53,8 @@ class Gate : public Object
void remove_input_gate(int id);
void update_state();
+ std::string get_object_name() override { return get_output_type_text(); };
+
private:
GATE_TYPE gate_type;
@@ -62,6 +63,8 @@ class Gate : public Object
Gate *input_gate1;
Gate *input_gate2;
+ std::string get_output_type_text();
+
/* states */
bool output_state = false;
};
diff --git a/MainWindow.cpp b/MainWindow.cpp
index 49bee5a..51a66c2 100644
--- a/MainWindow.cpp
+++ b/MainWindow.cpp
@@ -261,10 +261,18 @@ MainWindow::draw()
{
/* draw border box if multuple gates selected */
Gate *selgate;
+ // FIXME: selgate needs to be an object and such
for (auto g = selected_gates.begin(); g != selected_gates.end(); ++g)
{
- selgate = (Gate*)(*g);
- dc_image.drawHashBox(selgate->get_x(), selgate->get_y(), selgate->get_width(), selgate->get_height());
+ switch ((*g)->get_object_type())
+ {
+ case Object::GATE:
+ selgate = (Gate*)(*g);
+ dc_image.drawHashBox(selgate->get_x(), selgate->get_y(), selgate->get_width(), selgate->get_height());
+ case Object::NONE:
+ default:
+ printf("drawing objects hashbox not implemented for type\n");
+ }
}
}
@@ -345,8 +353,8 @@ MainWindow::draw()
/* update options panel */
if (selected_gate)
{
- input_1_details->setText((selected_gate->get_input_gate1() ? selected_gate->get_input_gate1()->get_output_type_text().c_str() : "(None)"));
- input_2_details->setText((selected_gate->get_input_gate2() ? selected_gate->get_input_gate2()->get_output_type_text().c_str() : "(None)"));
+ input_1_details->setText((selected_gate->get_input_gate1() ? selected_gate->get_input_gate1()->get_object_name().c_str() : "(None)"));
+ input_2_details->setText((selected_gate->get_input_gate2() ? selected_gate->get_input_gate2()->get_object_name().c_str() : "(None)"));
output_details->setText(selected_gate->get_output_state() ? "ON" : "OFF");
}
else
@@ -825,10 +833,18 @@ MainWindow::on_left_mouse_down(FXObject*, FXSelector, void *ptr)
/* clear selection if we're not clicking on a selected gate */
for (auto g = selected_gates.begin(); g != selected_gates.end(); ++g)
{
- selgate = (Gate*)(*g);
- if (gate->get_id() == selgate->get_id())
+ switch ((*g)->get_object_type())
{
- found_gate = true;
+ case Object::GATE:
+ selgate = (Gate*)(*g);
+ if (gate->get_id() == selgate->get_id())
+ {
+ found_gate = true;
+ }
+ break;
+
+ case Object::NONE:
+ break;
}
}
@@ -981,8 +997,15 @@ MainWindow::on_key_release(FXObject *sender, FXSelector sel, void *ptr)
Gate *gate;
for (auto g = selected_gates.begin(); g != selected_gates.end(); ++g)
{
- gate = (Gate*)(*g);
- remove_gate(*gate);
+ switch ((*g)->get_object_type())
+ {
+ case Object::GATE:
+ gate = (Gate*)(*g);
+ remove_gate(*gate);
+ break;
+ case Object::NONE:
+ break;
+ }
}
}