summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2005-08-14 23:00:39 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2005-08-14 23:00:39 +0100
commite7a2566a7a4d6b52d64536737bb4bca5fd08c605 (patch)
tree96180a2fe4fa77c0307c74d777d874a92f1ab7bd
parentc68dc4526cf9a1920b79b14c1cfd030b3aa7dcb5 (diff)
switch popup menu to use new choose_hill function
-rw-r--r--src/GipfelWidget.H4
-rw-r--r--src/GipfelWidget.cxx55
-rw-r--r--src/Makefile.am4
-rw-r--r--src/Panorama.cxx1
-rw-r--r--src/choose_hill.H34
-rw-r--r--src/choose_hill.cxx56
-rw-r--r--src/gipfel.cxx26
7 files changed, 113 insertions, 67 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index 3fdab77..085908c 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -46,12 +46,10 @@ class GipfelWidget : public Fl_Widget {
void set_labels(Hills *v);
- void update_menuitems(Hills *h);
-
public:
GipfelWidget(int X,int Y,int W, int H);
- void menu_cb(Hill *hill);
+ void center();
int load_image(char *file);
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index b1b677b..5570399 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -39,12 +39,14 @@
#include <FL/fl_draw.H>
#include "Fl_Search_Chooser.H"
+#include "choose_hill.H"
#include "util.h"
#include "GipfelWidget.H"
-static Fl_Menu_Item *menuitems;
static double pi_d, deg2rad;
+static void center_cb(Fl_Widget *o, void *f);
+
GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Widget(X, Y, W, H) {
int i;
@@ -102,7 +104,7 @@ GipfelWidget::load_image(char *file) {
mb = new Fl_Menu_Button(x(),y(),w()+x(),h()+y(),"&popup");
mb->type(Fl_Menu_Button::POPUP3);
mb->box(FL_NO_BOX);
- mb->menu(menuitems);
+ mb->add("Center Peak", NULL, (Fl_Callback*) center_cb, this);
// try to retrieve gipfel data from JPEG comment section
args[0] = "rdjpgcom";
@@ -201,7 +203,6 @@ GipfelWidget::load_data(const char *file) {
r = pan->load_data(file);
set_labels(pan->get_visible_mountains());
- update_menuitems(pan->get_close_mountains());
return r;
}
@@ -238,7 +239,6 @@ GipfelWidget::set_viewpoint(const char *pos) {
r = pan->set_viewpoint(pos);
set_labels(pan->get_visible_mountains());
- update_menuitems(pan->get_close_mountains());
return r;
}
@@ -247,7 +247,6 @@ void
GipfelWidget::set_viewpoint(const Hill *m) {
pan->set_viewpoint(m);
set_labels(pan->get_visible_mountains());
- update_menuitems(pan->get_close_mountains());
}
static void
@@ -539,48 +538,21 @@ GipfelWidget::get_view_height() {
}
void
-GipfelWidget::menu_cb(Hill* hill) {
- if (hill) {
- set_center_angle(hill->alph / deg2rad);
+GipfelWidget::center() {
+ Hill *m = choose_hill(pan->get_close_mountains(), "Center Peak");
+ if (m) {
+ set_center_angle(m->alph / deg2rad);
if (!m1 || (m1 && m2)) {
- m1 = hill;
+ m1 = m;
} else {
- m2 = hill;
+ m2 = m;
}
}
}
-void
-static_menu_cb(Fl_Widget *o, void *f) {
- Hill *hill = (Hill*) ((Fl_Menu_*)o)->mvalue()->user_data();
- ((GipfelWidget *)f)->menu_cb(hill);
-}
-
-void
-GipfelWidget::update_menuitems(Hills *h) {
- int i,j;
- Hills *h_sort = new Hills(h);
- h_sort->sort_name();
-
- if (menuitems) {
- free(menuitems);
- }
-
- menuitems = (Fl_Menu_Item*) calloc(h->get_num(), sizeof(Fl_Menu_Item) + 1);
- j = 0;
- for (i=0; i<h_sort->get_num(); i++) {
- if (h_sort->get(i)->flags & (HILL_DUPLICATE | HILL_TRACK_POINT)) {
- continue;
- }
- menuitems[j].text = h_sort->get(i)->name;
- menuitems[j].user_data(h_sort->get(i));
- j++;
- }
-
- mb->menu(menuitems);
- mb->callback((Fl_Callback*) static_menu_cb, this);
-
- delete h_sort;
+static void
+center_cb(Fl_Widget *o, void *f) {
+ ((GipfelWidget*)f)->center();
}
void
@@ -588,7 +560,6 @@ GipfelWidget::set_height_dist_ratio(double r) {
pan->set_height_dist_ratio(r);
set_labels(pan->get_visible_mountains());
- update_menuitems(pan->get_close_mountains());
redraw();
}
diff --git a/src/Makefile.am b/src/Makefile.am
index 8687c95..3e264c4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,7 +10,8 @@ gipfel_SOURCES = \
ProjectionSphaeric.cxx \
Hill.cxx \
Fl_Value_Dial.cxx \
- Fl_Search_Chooser.cxx
+ Fl_Search_Chooser.cxx \
+ choose_hill.cxx
noinst_HEADERS = \
GipfelWidget.H \
@@ -21,4 +22,5 @@ noinst_HEADERS = \
Hill.H \
Fl_Value_Dial.H \
Fl_Search_Chooser.H \
+ choose_hill.H \
util.h
diff --git a/src/Panorama.cxx b/src/Panorama.cxx
index 1643080..dea97e9 100644
--- a/src/Panorama.cxx
+++ b/src/Panorama.cxx
@@ -112,7 +112,6 @@ Panorama::set_viewpoint(const Hill *m) {
view_phi = m->phi;
view_lam = m->lam;
view_height = m->height;
-
if (view_name) {
free(view_name);
diff --git a/src/choose_hill.H b/src/choose_hill.H
new file mode 100644
index 0000000..1387868
--- /dev/null
+++ b/src/choose_hill.H
@@ -0,0 +1,34 @@
+//
+// "$Id: Fl_Value_Dial.H,v 1.2 2005/05/18 11:34:30 hofmann Exp $"
+//
+// Value dial header file for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2004 by Bill Spitzak and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems to "fltk-bugs@fltk.org".
+//
+
+#ifndef CHOOSE_HILL_H
+#define CHOOSE_HILL_H
+
+#include "Fl_Search_Chooser.H"
+#include "Hill.H"
+
+Hill *choose_hill(const Hills *hills, const char *l);
+
+#endif
diff --git a/src/choose_hill.cxx b/src/choose_hill.cxx
new file mode 100644
index 0000000..1cab2ac
--- /dev/null
+++ b/src/choose_hill.cxx
@@ -0,0 +1,56 @@
+//
+// Search Chooser widget for the Fast Light Tool Kit (FLTK).
+//
+// Copyright by Johannes Hofmann
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+//
+
+#include <stdio.h>
+#include <string.h>
+#include <FL/Fl.H>
+#include "choose_hill.H"
+
+Hill*
+choose_hill(const Hills *hills, const char *l) {
+ Fl_Search_Chooser *sc = new Fl_Search_Chooser(l?l:"Choose Hill");
+ Hills *h_sort = new Hills(hills);
+ Hill *ret;
+
+ h_sort->sort_name();
+
+ for (int i=0; i<h_sort->get_num(); i++) {
+ Hill *m = h_sort->get(i);
+ if (m->flags & (HILL_DUPLICATE | HILL_TRACK_POINT)) {
+ continue;
+ }
+ sc->add(m->name, m);
+ }
+
+ delete h_sort;
+
+ sc->show();
+ while (sc->shown()) {
+ Fl::wait();
+ }
+
+ ret = (Hill*) sc->data();
+
+ delete(sc);
+
+ return ret;
+}
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index 3c8c450..9db82fa 100644
--- a/src/gipfel.cxx
+++ b/src/gipfel.cxx
@@ -45,10 +45,11 @@
#include <FL/Fl_Valuator.H>
#include <FL/Fl_Value_Slider.H>
#include <FL/Fl_Value_Input.H>
+
#include "Fl_Value_Dial.H"
#include "Fl_Search_Chooser.H"
-
#include "GipfelWidget.H"
+#include "choose_hill.H"
char *img_file;
char *data_file;
@@ -126,26 +127,11 @@ void view_height_cb(Fl_Value_Input* o, void*) {
}
void viewpoint_cb(Fl_Value_Input* o, void*) {
- Fl_Search_Chooser *sc = new Fl_Search_Chooser("Choose Viewpoint");
- Hills *h_sort = new Hills(gipf->get_mountains());
- h_sort->sort_name();
-
- for (int i=0; i<h_sort->get_num(); i++) {
- Hill *m = h_sort->get(i);
- if (m->flags & (HILL_DUPLICATE | HILL_TRACK_POINT)) {
- continue;
- }
- sc->add(m->name, m);
+ Hill *m = choose_hill(gipf->get_mountains(), "Choose Viewpoint");
+ if (m) {
+ gipf->set_viewpoint(m);
+ set_values();
}
-
- sc->show();
- while (sc->shown()) {
- Fl::wait();
- }
-
- gipf->set_viewpoint((Hill*) sc->data());
- delete sc;
- set_values();
}
void proj_cb(Fl_Value_Input* o, void*d) {