You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spOSMroute/main/guiw_gpsfile.c

151 lines
4.3 KiB

/***************************************************************************
* guiw_gpsfile.c
*
* 2012-02-21
* Copyright (C) 2012 Steffen Pohle
* steffen@gulpe.de
****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* main.c 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
#include "gps.h"
enum {
GPSWIN_UNDEF = 0,
GPSWIN_PAUSEPLAY,
GPSWIN_JUMP,
GPSWIN_CLOSE
};
static GUIWindow gpswin = {0};
void gpswin_closecallback ();
void gpswin_btndraw (GUIButton *btn);
void gpswin_btnjump(int x, int y);
void gpswin_btnpauseplay(int x, int y);
void gpswin_btnclose(int x, int y);
void gpswin_show () {
d_printf ("GUI: gps file screen");
if (gpswin.screen == NULL) guiwindow_new (&gpswin, 250, 32);
gpswin.screen_changed = 1;
gpswin.callback_close = (void*)gpswin_closecallback;
gpswin.style = WGUI_S_VCENTER | WGUI_S_HBOTTOM;
/* add buttons */
strncpy (gpswin.buttons[0].caption, _("P"), GUI_TEXTLEN);
gpswin.buttons[0].callback_clicked = (void*)gpswin_btnpauseplay;
gpswin.buttons[0].id = GPSWIN_PAUSEPLAY;
gpswin.buttons[0].callback_draw = (void*)gpswin_btndraw;
gpswin.buttons[0].w = 31;
gpswin.buttons[0].h = 31;
gpswin.buttons[0].x = 0;
gpswin.buttons[0].y = 0;
strncpy (gpswin.buttons[1].caption, _("-"), GUI_TEXTLEN);
gpswin.buttons[1].callback_clicked = (void*)gpswin_btnjump;
gpswin.buttons[1].callback_draw = (void*)gpswin_btndraw;
gpswin.buttons[1].id = GPSWIN_JUMP;
gpswin.buttons[1].w = 250-32*2;
gpswin.buttons[1].h = 31;
gpswin.buttons[1].x = 32;
gpswin.buttons[1].y = 0;
strncpy (gpswin.buttons[2].caption, _("Close"), GUI_TEXTLEN);
gpswin.buttons[2].callback_clicked = (void*)gpswin_btnclose;
gpswin.buttons[2].id = GPSWIN_CLOSE;
gpswin.buttons[2].w = 32;
gpswin.buttons[2].h = 31;
gpswin.buttons[2].x = 250-32;
gpswin.buttons[2].y = 0;
gui_show (&gpswin);
};
void gpswin_closecallback () {
d_printf ("GUI: gps win close");
guiwindow_close (&gpswin);
};
void gpswin_btndraw (GUIButton *btn) {
int i;
if (btn->id == GPSWIN_PAUSEPLAY) {
i = gps_file_get_state ();
if (i == GPSF_END) btn->col = &color[COLOR_white][1];
else if (i == GPSF_INIT) btn->col = &color[COLOR_green][0];
else if (i == GPSF_RUN) btn->col = &color[COLOR_green][2];
else if (i == GPSF_PAUSE) btn->col = &color[COLOR_redgray][1];
else btn->col = &color[COLOR_red][2];
gui_button_draw (btn);
}
else if (btn->id == GPSWIN_JUMP) {
struct line_style ls;
int x;
if (gps_file_get_size () == 0) x = 0;
else x = (btn->w * gps_file_get_pos()) / gps_file_get_size ();
ls.width = 1.0;
ls.c = ls.borderc = color[COLOR_white][3];
draw_polygonstart ();
draw_polygonadd (btn->x, btn->y);
draw_polygonadd (btn->x + x, btn->y);
draw_polygonadd (btn->x + x, btn->y + btn->h);
draw_polygonadd (btn->x, btn->y + btn->h);
draw_polygonfinish (currentwin->screen, ls, color[COLOR_white][1], 1);
draw_polygonstart ();
draw_polygonadd (btn->x + x, btn->y);
draw_polygonadd (btn->x + btn->w, btn->y);
draw_polygonadd (btn->x + btn->w, btn->y + btn->h);
draw_polygonadd (btn->x + x, btn->y + btn->h);
draw_polygonfinish (currentwin->screen, ls, color[COLOR_white][0], 1);
draw_line (currentwin->screen, btn->x + x, btn->y, btn->x + x, btn->y + btn->h, ls);
}
};
void gpswin_btnjump(int x, int y) {
int pos = x * gps_file_get_size() / (250-64);
gpswin.screen_changed = 1;
draw_set_flag (DRAW_GPSFOLLOW);
gps_file_set_pos (pos);
draw ();
};
void gpswin_btnclose(int x, int y) {
gui_close();
};
void gpswin_btnpauseplay(int x, int y) {
gpswin.screen_changed = 1;
if (gps_file_get_state () == GPSF_PAUSE) gps_file_set_state (GPSF_RUN);
else gps_file_set_state (GPSF_PAUSE);
draw ();
};