summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/GipfelWidget.cxx13
-rw-r--r--src/Hill.H6
-rw-r--r--src/Hill.cxx33
3 files changed, 45 insertions, 7 deletions
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index b71abbf..8782fb1 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: GipfelWidget.cxx,v 1.34 2005/06/22 19:47:19 hofmann Exp $"
+// "$Id: GipfelWidget.cxx,v 1.35 2005/06/22 20:40:35 hofmann Exp $"
//
// GipfelWidget routines.
//
@@ -348,7 +348,9 @@ GipfelWidget::get_view_height() {
void
GipfelWidget::update_menuitems(Hills *h) {
int i,j;
-
+ Hills *h_sort = new Hills(h);
+ h_sort->sort_name();
+
if (menuitems) {
free(menuitems);
menuitems = NULL;
@@ -356,14 +358,15 @@ GipfelWidget::update_menuitems(Hills *h) {
menuitems = (Fl_Menu_Item*) calloc(h->get_num(), sizeof(Fl_Menu_Item) + 1);
j = 0;
- for (i=0; i<h->get_num(); i++) {
- if (h->get(i)->duplicate) {
+ for (i=0; i<h_sort->get_num(); i++) {
+ if (h_sort->get(i)->duplicate) {
continue;
}
- menuitems[j++].text = h->get(i)->name;
+ menuitems[j++].text = h_sort->get(i)->name;
}
mb->menu(menuitems);
+ delete h_sort;
}
void
diff --git a/src/Hill.H b/src/Hill.H
index bba2b4d..68f6df5 100644
--- a/src/Hill.H
+++ b/src/Hill.H
@@ -1,5 +1,5 @@
//
-// "$Id: Hill.H,v 1.15 2005/06/19 16:54:02 hofmann Exp $"
+// "$Id: Hill.H,v 1.16 2005/06/22 20:40:35 hofmann Exp $"
//
// Copyright 2005 by Johannes Hofmann
//
@@ -55,6 +55,8 @@ class Hills {
public:
Hills();
+ Hills(const Hills *h);
+
~Hills();
int load(const char *file);
@@ -65,6 +67,8 @@ class Hills {
void sort_phi();
+ void sort_name();
+
void sort();
void clear();
diff --git a/src/Hill.cxx b/src/Hill.cxx
index 08d834f..4057524 100644
--- a/src/Hill.cxx
+++ b/src/Hill.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Hill.cxx,v 1.16 2005/06/22 19:47:20 hofmann Exp $"
+// "$Id: Hill.cxx,v 1.17 2005/06/22 20:40:35 hofmann Exp $"
//
// Hill routines.
//
@@ -67,6 +67,16 @@ Hills::Hills() {
deg2rad = pi_d / 180.0;
}
+Hills::Hills(const Hills *h) {
+ num = h->num;
+ cap = h->cap;
+ m = (Hill **) malloc(cap * sizeof(Hill *));
+ memcpy(m, h->m, cap * sizeof(Hill *));
+
+ pi_d = asin(1.0) * 2.0;
+ deg2rad = pi_d / 180.0;
+}
+
int
Hills::load(const char *file) {
FILE *fp;
@@ -184,6 +194,18 @@ comp_mountains_phi(const void *n1, const void *n2) {
}
}
+static int
+comp_mountains_name(const void *n1, const void *n2) {
+ Hill *m1 = *(Hill **)n1;
+ Hill *m2 = *(Hill **)n2;
+
+ if (m1 && m2) {
+ return strcmp(m1->name, m2->name);
+ } else {
+ return 0;
+ }
+}
+
void
Hills::sort() {
if (!m) {
@@ -203,6 +225,15 @@ Hills::sort_phi() {
}
void
+Hills::sort_name() {
+ if (!m) {
+ return;
+ }
+
+ qsort(m, num, sizeof(Hill *), comp_mountains_name);
+}
+
+void
Hills::clear() {
if (m) {
free(m);