diff options
author | Johannes Hofmann <johannes.hofmann@gmx.de> | 2005-05-03 19:36:39 +0000 |
---|---|---|
committer | Johannes Hofmann <johannes.hofmann@gmx.de> | 2005-05-03 19:36:39 +0000 |
commit | 002969de7a3aa5343008d5cf0fe72997d9d7a014 (patch) | |
tree | ae0c660b8eff239401f136a47e1ed4b670e8e311 | |
parent | b886930071c8b9df3c5be7a3a0e50661a549c2ed (diff) |
initial label positioning
initial label positioning
-rw-r--r-- | src/GipfelWidget.H | 4 | ||||
-rw-r--r-- | src/GipfelWidget.cxx | 38 | ||||
-rw-r--r-- | src/Hill.H | 3 | ||||
-rw-r--r-- | src/Hill.cxx | 16 |
4 files changed, 52 insertions, 9 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index ab86a5d..4d1296c 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.H,v 1.14 2005/05/03 20:04:14 hofmann Exp $" +// "$Id: GipfelWidget.H,v 1.15 2005/05/03 21:36:39 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -41,6 +41,8 @@ class GipfelWidget : public Fl_Widget { int set_cur_mountain(int m_x, int m_y); int set_mountain(int m_x, int m_y); + + void set_labels(Mountains *v); public: GipfelWidget(int X,int Y,int W, int H); diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index eeba2fa..49562cf 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -1,5 +1,5 @@ // -// "$Id: GipfelWidget.cxx,v 1.17 2005/05/03 20:04:14 hofmann Exp $" +// "$Id: GipfelWidget.cxx,v 1.18 2005/05/03 21:36:39 hofmann Exp $" // // PSEditWidget routines. // @@ -117,11 +117,11 @@ GipfelWidget::draw() { } fl_xyline(center_x + m->x + x() - 2, center_y + m->y + y(), center_x + m->x + x() + 2); - fl_yxline(center_x + m->x + x(), center_y + m->y + y() - 2, center_y + m->y + y() + 2); + fl_yxline(center_x + m->x + x(), center_y + m->label_y + y() - 2, center_y + m->y + y() + 2); fl_draw(m->name, center_x + m->x + x(), - center_y + m->y + y()); + center_y + m->label_y + y()); } for (i=0; i<marker->get_num(); i++) { @@ -135,6 +135,31 @@ GipfelWidget::draw() { fl_pop_clip(); } +void +GipfelWidget::set_labels(Mountains *v) { + int i, j, width, height; + Mountain *m, *n; + + fl_font(FL_HELVETICA, 8); + + for (i=0; i<v->get_num(); i++) { + m = v->get(i); + + fl_measure(m->name, width, height); + + m->label_x = m->x + width; + m->label_y = m->y; + + for (j=0; j<v->get_num() && j < i; j++) { + n = v->get(j); + + if (n->label_x >= m->x && n->label_y >= m->label_y - 1 && n->label_y <= m->label_y + height + 1) { + m->label_y = n->label_y - height - 1; + } + } + } +} + int GipfelWidget::set_cur_mountain(int m_x, int m_y) { Mountains *mnts = pan->get_visible_mountains(); @@ -186,42 +211,49 @@ GipfelWidget::set_mountain(int m_x, int m_y) { void GipfelWidget::set_center_angle(double a) { pan->set_center_angle(a); + set_labels(pan->get_visible_mountains()); redraw(); } void GipfelWidget::set_nick_angle(double a) { pan->set_nick_angle(a); + set_labels(pan->get_visible_mountains()); redraw(); } void GipfelWidget::set_tilt_angle(double a) { pan->set_tilt_angle(a); + set_labels(pan->get_visible_mountains()); redraw(); } void GipfelWidget::set_scale(double s) { pan->set_scale(s); + set_labels(pan->get_visible_mountains()); redraw(); } void GipfelWidget::set_height_dist_ratio(double r) { pan->set_height_dist_ratio(r); + set_labels(pan->get_visible_mountains()); redraw(); } int GipfelWidget::comp_params() { pan->comp_params(); + set_labels(pan->get_visible_mountains()); redraw(); } int GipfelWidget::guess() { pan->guess(marker); + set_labels(pan->get_visible_mountains()); redraw(); } @@ -1,5 +1,5 @@ // -// "$Id: Hill.H,v 1.9 2005/05/03 20:32:20 hofmann Exp $" +// "$Id: Hill.H,v 1.10 2005/05/03 21:36:39 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -37,6 +37,7 @@ class Mountain { double a_nick; double dist; int x, y; + int label_x, label_y; char *name; Mountain(const char *n, double p, double l, double h); diff --git a/src/Hill.cxx b/src/Hill.cxx index 5bef0fd..443e639 100644 --- a/src/Hill.cxx +++ b/src/Hill.cxx @@ -1,5 +1,5 @@ // -// "$Id: Hill.cxx,v 1.7 2005/05/03 20:32:20 hofmann Exp $" +// "$Id: Hill.cxx,v 1.8 2005/05/03 21:36:39 hofmann Exp $" // // PSEditWidget routines. // @@ -55,7 +55,6 @@ Mountain::~Mountain() { Mountains::Mountains() { - fprintf(stderr, "===>huhu\n"); num = 0; cap = 100; m = (Mountain **) malloc(cap * sizeof(class Mountain *)); @@ -80,9 +79,18 @@ Mountains::add(Mountain *m1) { static int -comp_mountains(const void *m1, const void *m2) { +comp_mountains(const void *n1, const void *n2) { + Mountain *m1 = (Mountain *)n1; + Mountain *m2 = (Mountain *)n2; + if (m1 && m2) { - return ((Mountain *)m1)->alph > ((Mountain *)m2)->alph; + if (m1->alph < m2->alph) { + return 1; + } else if (m1->alph > m2->alph) { + return -1; + } else { + return 0; + } } else { return 0; } |