aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/EdgeView.cpp57
-rw-r--r--src/gui/EdgeView.hpp2
-rw-r--r--src/gui/NodeView.cpp7
-rw-r--r--src/gui/NodeView.hpp1
4 files changed, 58 insertions, 9 deletions
diff --git a/src/gui/EdgeView.cpp b/src/gui/EdgeView.cpp
index 166f5fa..2c32425 100644
--- a/src/gui/EdgeView.cpp
+++ b/src/gui/EdgeView.cpp
@@ -22,6 +22,41 @@
#include "EdgeView.hpp"
#include "NodeView.hpp"
+
+/* probability colour stuff */
+
+#define RGB_TO_UINT(r,g,b) ((((guint)(r))<<16)|(((guint)(g))<<8)|((guint)(b)))
+#define RGB_TO_RGBA(x,a) (((x) << 8) | ((((guint)a) & 0xff)))
+#define RGBA_TO_UINT(r,g,b,a) RGB_TO_RGBA(RGB_TO_UINT(r,g,b), a)
+
+#define UINT_RGBA_R(x) (((uint32_t)(x))>>24)
+#define UINT_RGBA_G(x) ((((uint32_t)(x))>>16)&0xff)
+#define UINT_RGBA_B(x) ((((uint32_t)(x))>>8)&0xff)
+#define UINT_RGBA_A(x) (((uint32_t)(x))&0xff)
+
+#define MONO_INTERPOLATE(v1, v2, t) ((int)rint((v2)*(t)+(v1)*(1-(t))))
+
+#define UINT_INTERPOLATE(c1, c2, t) \
+ RGBA_TO_UINT( MONO_INTERPOLATE(UINT_RGBA_R(c1), UINT_RGBA_R(c2), t), \
+ MONO_INTERPOLATE(UINT_RGBA_G(c1), UINT_RGBA_G(c2), t), \
+ MONO_INTERPOLATE(UINT_RGBA_B(c1), UINT_RGBA_B(c2), t), \
+ MONO_INTERPOLATE(UINT_RGBA_A(c1), UINT_RGBA_A(c2), t) )
+
+inline static uint32_t edge_color(float prob)
+{
+ static uint32_t min = 0xFF4444C0;
+ static uint32_t mid = 0xFFFF44C0;
+ static uint32_t max = 0x44FF44C0;
+
+ if (prob <= 0.5)
+ return UINT_INTERPOLATE(min, mid, prob*2.0);
+ else
+ return UINT_INTERPOLATE(mid, max, (prob-0.5)*2.0);
+}
+
+/* end probability colour stuff */
+
+
using namespace FlowCanvas;
EdgeView::EdgeView(SharedPtr<Canvas> canvas,
@@ -31,6 +66,9 @@ EdgeView::EdgeView(SharedPtr<Canvas> canvas,
: FlowCanvas::Connection(canvas, src, dst, 0x9FA0A0F4, true)
, _edge(edge)
{
+ set_color(edge_color(_edge->probability()));
+ set_handle_style(HANDLE_CIRCLE);
+ show_handle(true);
}
@@ -44,24 +82,29 @@ EdgeView::length_hint() const
void
EdgeView::show_label(bool show)
{
+ /* too slow
if (show) {
char label[4];
snprintf(label, 4, "%3f", _edge->probability());
set_label(label);
} else {
set_label("");
- }
+ }*/
+ show_handle(show);
+ set_color(edge_color(_edge->probability()));
}
void
-EdgeView::update_label()
+EdgeView::update()
{
- if (_label) {
- char label[4];
+ if (_handle/* && _handle->text*/) {
+ /*char label[4];
snprintf(label, 4, "%3f", _edge->probability());
- set_label(label);
+ set_label(label);*/
+ show_handle(true);
}
+ set_color(edge_color(_edge->probability()));
}
@@ -72,11 +115,11 @@ EdgeView::on_event(GdkEvent* ev)
if (ev->button.state & GDK_CONTROL_MASK) {
if (ev->button.button == 1) {
_edge->set_probability(_edge->probability() - 0.1);
- update_label();
+ update();
return true;
} else if (ev->button.button == 3) {
_edge->set_probability(_edge->probability() + 0.1);
- update_label();
+ update();
return true;
}
}
diff --git a/src/gui/EdgeView.hpp b/src/gui/EdgeView.hpp
index 29eacde..2555e4a 100644
--- a/src/gui/EdgeView.hpp
+++ b/src/gui/EdgeView.hpp
@@ -38,7 +38,7 @@ public:
virtual double length_hint() const;
private:
- void update_label();
+ void update();
bool on_event(GdkEvent* ev);
SharedPtr<Machina::Edge> _edge;
diff --git a/src/gui/NodeView.cpp b/src/gui/NodeView.cpp
index c0378a7..fc9b0bb 100644
--- a/src/gui/NodeView.cpp
+++ b/src/gui/NodeView.cpp
@@ -32,6 +32,8 @@ NodeView::NodeView(Gtk::Window* window,
: FlowCanvas::Ellipse(canvas, name, x, y, 20, 20, false)
, _window(window)
, _node(node)
+ , _default_border_color(_border_color)
+ , _old_color(_color)
{
signal_clicked.connect(sigc::mem_fun(this, &NodeView::handle_click));
update_state(false);
@@ -86,15 +88,18 @@ NodeView::show_label(bool show)
void
NodeView::update_state(bool show_labels)
{
- static const uint32_t active_color = 0xA0A0AAFF;
+ static const uint32_t active_color = 0x408040FF;
+ static const uint32_t active_border_color = 0x00FF00FF;
if (_node->is_active()) {
if (_color != active_color) {
_old_color = _color;
set_base_color(active_color);
+ set_border_color(active_border_color);
}
} else if (_color == active_color) {
set_base_color(_old_color);
+ set_border_color(_default_border_color);
}
if (_node->is_selector())
diff --git a/src/gui/NodeView.hpp b/src/gui/NodeView.hpp
index a0dd5b8..bc94efa 100644
--- a/src/gui/NodeView.hpp
+++ b/src/gui/NodeView.hpp
@@ -43,6 +43,7 @@ private:
Gtk::Window* _window;
SharedPtr<Machina::Node> _node;
+ uint32_t _default_border_color;
uint32_t _old_color;
};