summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/GipfelWidget.H1
-rw-r--r--src/GipfelWidget.cxx22
-rw-r--r--src/ImageMetaData.cxx20
3 files changed, 28 insertions, 15 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index 3158a11..f8e242e 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -25,6 +25,7 @@ class GipfelWidget : public Fl_Group {
int have_gipfel_info;
ImageMetaData *md;
int show_hidden;
+ char focused_mountain_label[128];
int handle(int event);
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 0f94f9f..b895ecb 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -33,6 +33,7 @@
static double pi_d, deg2rad;
GipfelWidget::GipfelWidget(int X,int Y,int W, int H): Fl_Group(X, Y, W, H) {
+ end();
pi_d = asin(1.0) * 2.0;
deg2rad = pi_d / 180.0;
img = NULL;
@@ -286,19 +287,16 @@ GipfelWidget::draw() {
}
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_rectf(m_x, m_y - height,
+ (int) fl_width(focused_mountain_label) + 2, height + 2);
fl_color(FL_BLACK);
- fl_draw(buf, m_x, m_y);
+ fl_draw(focused_mountain_label, m_x, m_y);
}
@@ -613,6 +611,10 @@ GipfelWidget::handle(int event) {
cur_mountain = m;
} else if (Fl::event_button() == 2) {
toggle_known_mountain(mark_x, mark_y);
+ if (focused_mountain) {
+ focused_mountain = NULL;
+ redraw();
+ }
}
Fl::focus(this);
@@ -629,7 +631,13 @@ GipfelWidget::handle(int event) {
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) {
+ if (m != focused_mountain && (!m || !known_hills->contains(m))) {
+ if (m)
+ snprintf(focused_mountain_label,
+ sizeof(focused_mountain_label) - 1,
+ "%s (%dm), distance %.2fkm",
+ m->name, (int) m->height, pan->get_real_distance(m) / 1000.0);
+
focused_mountain = m;
redraw();
}
diff --git a/src/ImageMetaData.cxx b/src/ImageMetaData.cxx
index a678360..f22a641 100644
--- a/src/ImageMetaData.cxx
+++ b/src/ImageMetaData.cxx
@@ -93,7 +93,7 @@ degminsecstr2double(char *val) {
int
ImageMetaData::load_image_exif(char *name) {
- char * args[32];
+ const char * args[32];
FILE *p;
pid_t pid;
int status;
@@ -107,7 +107,7 @@ ImageMetaData::load_image_exif(char *name) {
args[3] = name;
args[4] = NULL;
- p = pexecvp(args[0], args, &pid, "r");
+ p = pexecvp(args[0], const_cast<char * const *>(args), &pid, "r");
if (p) {
while (fgets(buf, sizeof(buf), p) != NULL) {
@@ -155,7 +155,7 @@ ImageMetaData::load_image_exif(char *name) {
int
ImageMetaData::load_image_jpgcom(char *name) {
- char * args[32];
+ const char * args[32];
FILE *p;
pid_t pid;
int status;
@@ -168,7 +168,7 @@ ImageMetaData::load_image_jpgcom(char *name) {
args[1] = name;
args[2] = NULL;
- p = pexecvp(args[0], args, &pid, "r");
+ p = pexecvp(args[0], const_cast<char * const *>(args), &pid, "r");
if (p) {
while (fgets(buf, sizeof(buf), p) != NULL) {
@@ -208,15 +208,18 @@ ImageMetaData::load_image_jpgcom(char *name) {
int
ImageMetaData::save_image_jpgcom(char *in_img, char *out_img) {
- char * args[32];
+ const char * args[32];
FILE *p;
pid_t pid;
char buf[1024], tmpname[MAXPATHLEN];
int status, err = 0;
ssize_t n;
int tmp_fd;
+ char *dirbuf;
- snprintf(tmpname, sizeof(tmpname), "%s/.gipfelXXXXXX", dirname(out_img));
+ dirbuf = strdup(out_img);
+ snprintf(tmpname, sizeof(tmpname), "%s/.gipfelXXXXXX", dirname(dirbuf));
+ free(dirbuf);
tmp_fd = mkstemp(tmpname);
if (tmp_fd < 0) {
perror("mkstemp");
@@ -242,7 +245,7 @@ ImageMetaData::save_image_jpgcom(char *in_img, char *out_img) {
args[4] = in_img;
args[5] = NULL;
- p = pexecvp(args[0], args, &pid, "r");
+ p = pexecvp(args[0], const_cast<char * const *>(args), &pid, "r");
if (p) {
while ((n = fread(buf, 1, sizeof(buf), p)) != 0) {
@@ -263,7 +266,8 @@ ImageMetaData::save_image_jpgcom(char *in_img, char *out_img) {
err++;
}
- close(tmp_fd);
+ fsync(tmp_fd); /* make sure data is on disk before replacing orig file */
+ close(tmp_fd);
if (!err) {
if (rename(tmpname, out_img) != 0) {