summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-02-26 16:57:36 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-02-26 16:57:36 +0100
commit5f0f1bd03de95f48e11b371c87e47f956792fbad (patch)
treefc143f01c170b19c01fcf1b2ce6119ce2b2cb08a
parent3b1bd99e40c1d7bbb8115ab62ec3e50b16f3cb7d (diff)
show details of peak under the mouse
-rw-r--r--src/GipfelWidget.H9
-rw-r--r--src/GipfelWidget.cxx63
2 files changed, 48 insertions, 24 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index d8434a5..3158a11 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -7,15 +7,15 @@
#ifndef GipfelWidget_H
#define GipfelWidget_H
-#include <FL/Fl_Widget.H>
+#include <FL/Fl_Group.H>
#include <FL/Fl_Menu_Button.H>
#include "Panorama.H"
#include "ImageMetaData.H"
-class GipfelWidget : public Fl_Widget {
+class GipfelWidget : public Fl_Group {
private:
Fl_Image *img;
- Hill *cur_mountain;
+ Hill *cur_mountain, *focused_mountain;
Hills *track_points;
Hills *known_hills;
Panorama *pan;
@@ -24,12 +24,11 @@ class GipfelWidget : public Fl_Widget {
double track_width;
int have_gipfel_info;
ImageMetaData *md;
-
int show_hidden;
int handle(int event);
- int set_cur_mountain(int m_x, int m_y);
+ Hill * find_mountain(Hills *mnts, int m_x, int m_y);
int toggle_known_mountain(int m_x, int m_y);
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index aa0f34c..0f94f9f 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -32,12 +32,13 @@
static double pi_d, deg2rad;
-GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) {
+GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Group(X, Y, W, H) {
pi_d = asin(1.0) * 2.0;
deg2rad = pi_d / 180.0;
img = NULL;
pan = new Panorama();
cur_mountain = NULL;
+ focused_mountain = NULL;
mb = NULL;
known_hills = new Hills();
img_file = NULL;
@@ -249,7 +250,8 @@ GipfelWidget::draw() {
int m_y = h() / 2 + y() + (int) rint(m->y);
if ((m->flags & (Hill::DUPLICATE|Hill::TRACK_POINT)) ||
- (!show_hidden && (m->flags & Hill::HIDDEN)) || known_hills->contains(m))
+ (!show_hidden && (m->flags & Hill::HIDDEN)) ||
+ known_hills->contains(m) || m == focused_mountain)
continue;
fl_xyline(m_x - CROSS_SIZE, m_y, m_x + CROSS_SIZE);
@@ -263,7 +265,7 @@ GipfelWidget::draw() {
int m_y = h() / 2 + y() + (int) rint(m->y);
if ((m->flags & (Hill::DUPLICATE|Hill::TRACK_POINT)) ||
- (!show_hidden && (m->flags & Hill::HIDDEN)))
+ (!show_hidden && (m->flags & Hill::HIDDEN)) || m == focused_mountain)
continue;
if (known_hills->contains(m)) {
@@ -283,6 +285,23 @@ GipfelWidget::draw() {
fl_draw(m->name, m_x + 2, m_y + m->label_y);
}
+ if (focused_mountain) {
+ static char buf[128];
+ m = focused_mountain;
+ int m_x = w() / 2 + x() + (int) rint(m->x);
+ int m_y = h() / 2 + y() + (int) rint(m->y);
+
+ snprintf(buf, sizeof(buf), "%s (%dm), distance %.2fkm",
+ m->name, (int) m->height, pan->get_real_distance(m) / 1000.0);
+
+ fl_color(FL_YELLOW);
+
+ fl_rectf(m_x, m_y - height, (int) fl_width(buf) + 2, height + 2);
+ fl_color(FL_BLACK);
+ fl_draw(buf, m_x, m_y);
+ }
+
+
/* track */
if (track_points && track_points->get_num() > 0) {
int last_x = 0, last_y = 0, last_initialized = 0;
@@ -368,25 +387,22 @@ GipfelWidget::set_labels(Hills *v) {
}
}
-int
-GipfelWidget::set_cur_mountain(int m_x, int m_y) {
+Hill *
+GipfelWidget::find_mountain(Hills *mnts, int m_x, int m_y) {
Hill *m;
int center_x = w() / 2;
int center_y = h() / 2;
int i;
- for (i=0; i<known_hills->get_num(); i++) {
- m = known_hills->get(i);
+ for (i=0; i<mnts->get_num(); i++) {
+ m = mnts->get(i);
if (m_x - center_x >= m->x - 2 && m_x - center_x < m->x + 2 &&
- m_y - center_y >= m->y - 2 && m_y - center_y < m->y + 2) {
-
- cur_mountain = m;
- return 0;
- }
+ m_y - center_y >= m->y - 2 && m_y - center_y < m->y + 2)
+ return m;
}
- return 1;
+ return NULL;
}
int
@@ -585,34 +601,43 @@ GipfelWidget::set_track_width(double w) {
int
GipfelWidget::handle(int event) {
int mark_x, mark_y;
+ Hill *m;
switch(event) {
case FL_PUSH:
mark_x = Fl::event_x()-x();
mark_y = Fl::event_y()-y();
if (Fl::event_button() == 1) {
- set_cur_mountain(mark_x, mark_y);
+ m = find_mountain(known_hills, mark_x, mark_y);
+ if (m)
+ cur_mountain = m;
} else if (Fl::event_button() == 2) {
toggle_known_mountain(mark_x, mark_y);
}
Fl::focus(this);
return 1;
- break;
case FL_DRAG:
set_mountain(Fl::event_x()-x(), Fl::event_y()-y());
return 1;
- break;
case FL_RELEASE:
cur_mountain = NULL;
return 1;
- break;
+ case FL_ENTER:
+ return 1;
+ case FL_LEAVE:
+ return 1;
+ case FL_MOVE:
+ m = find_mountain(pan->get_visible_mountains(), Fl::event_x()-x(), Fl::event_y()-y());
+ if (m && m != focused_mountain) {
+ focused_mountain = m;
+ redraw();
+ }
+ return 1;
case FL_FOCUS:
return 1;
- break;
case FL_UNFOCUS:
return 0;
- break;
}
return 0;
}