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.
130 lines
4.1 KiB
130 lines
4.1 KiB
/* $Id: gui_entry.c,v 1.5 2013/02/26 23:33:27 steffen Exp $ */
|
|
/***************************************************************************
|
|
* gui_entry.c
|
|
*
|
|
* Copyright (C) 2013 Steffen Pohle
|
|
* steffen@gulpe.de
|
|
***************************************************************************
|
|
* basic windows functions
|
|
***************************************************************************/
|
|
|
|
/*
|
|
* 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"
|
|
|
|
/****************************************************************************
|
|
* entry
|
|
*/
|
|
void gui_entry_draw (GUIItem *item) {
|
|
char text1[GUI_TEXTLEN];
|
|
char text2[GUI_TEXTLEN];
|
|
struct line_style ls;
|
|
GUIEntry *entry;
|
|
|
|
ls.width = 1.0;
|
|
if (currentwin->focus == (void*) item)
|
|
ls.c = ls.borderc = color[COLOR_white][3];
|
|
else
|
|
ls.c = ls.borderc = color[COLOR_white][2];
|
|
gfx_draw_line (currentwin->screen, item->x, item->y+item->h, item->x+item->w, item->y+item->h, ls);
|
|
gfx_draw_line (currentwin->screen, item->x, item->y+item->h, item->x, item->y+item->h-2, ls);
|
|
gfx_draw_line (currentwin->screen, item->x+item->w, item->y+item->h, item->x+item->w, item->y+item->h-2, ls);
|
|
|
|
if (entry->curpos >= strlen (entry->text)) {
|
|
entry->curpos = strlen (entry->text);
|
|
snprintf (text1, GUI_TEXTLEN, "%s|", entry->text);
|
|
}
|
|
else if (entry->curpos <= 0) {
|
|
entry->curpos = 0;
|
|
snprintf (text1, GUI_TEXTLEN, "|%s", entry->text);
|
|
}
|
|
else {
|
|
strncpy (text2, entry->text, entry->curpos);
|
|
snprintf (text1, GUI_TEXTLEN, "%s|%s", text2, entry->text+entry->curpos);
|
|
}
|
|
gfx_draw_text (currentwin->screen, entry->x+2, entry->y, text1, &color[COLOR_white][3]);
|
|
};
|
|
|
|
|
|
/*
|
|
* event handling
|
|
*/
|
|
void gui_entry_event (GUIEntry *entry, GUIEvent *event) {
|
|
char text1[GUI_TEXTLEN];
|
|
|
|
d_printf ("event: %d pos: %d,%d", event->event, event->mousepos.x, event->mousepos.y);
|
|
|
|
if (event->event == EGUI_MOUSERELEASED
|
|
&& event->mousepos.x >= 0 && entry->x+entry->w >= event->mousepos.x
|
|
&& event->mousepos.y >= 0 && entry->y+entry->h >= event->mousepos.y) {
|
|
d_printf ("gui_entry_event set focus");
|
|
currentwin->focus = entry;
|
|
}
|
|
|
|
else if (event->event == EGUI_KEYRELEASED) {
|
|
d_printf ("gui_entry_event: curpos:%d len:%d text:%s char:%x", entry->curpos, strlen (entry->text), entry->text, event->keyval);
|
|
if (event->keyval == 0xff08) { // backspace
|
|
// strncpy (text1, entry->text, entry->curpos-1);
|
|
// snprintf (text2, GUI_TEXTLEN, "%s%s", text1, entry->text+entry->curpos);
|
|
// strncpy (entry->text, text2, GUI_TEXTLEN);
|
|
// entry->curpos--;
|
|
entry->text[0] = 0;
|
|
entry->curpos = 0;
|
|
}
|
|
else if (event->keyval == 0xff1b) { // esc
|
|
gui_close ();
|
|
}
|
|
else if (event->keyval == 0xff0d) { // enter
|
|
if (entry->callback_enter) entry->callback_enter ();
|
|
}
|
|
else if (event->keyval == 0xff51) { // left
|
|
// entry->curpos--;
|
|
}
|
|
else if (event->keyval == 0xff53) { // right
|
|
// entry->curpos++;
|
|
}
|
|
else if ((event->keyval & 0xff00) == 0xff00) {
|
|
// ignore all the rest
|
|
}
|
|
else {
|
|
strncpy (text1, entry->text, GUI_TEXTLEN );
|
|
snprintf (entry->text, GUI_TEXTLEN, "%s%c", text1, event->keyval);
|
|
entry->curpos++;
|
|
}
|
|
}
|
|
currentwin->screen_changed = 1;
|
|
return;
|
|
};
|
|
|
|
|
|
GUIEntry *gui_entry_new (char *text, int x, int y, int w, int h) {
|
|
GUIEntry *item = (GUIEntry*) ml_malloc (sizeof (GUIEntry));
|
|
|
|
if (text == NULL) item->text[0] = 0;
|
|
else strncpy (item->text, text, GUI_TEXTLEN);
|
|
item->x = x;
|
|
item->y = y;
|
|
item->w = w;
|
|
item->h = h;
|
|
item->callback_changed = NULL;
|
|
item->callback_enter = NULL;
|
|
|
|
return item;
|
|
};
|