/* $Id: gui_softkeyboard.c,v 1.2 2013/03/09 00:02:30 steffen Exp $ */ /*************************************************************************** * gui_softkeyboard.c * * Copyright (C) 2013 Steffen Pohle * steffen@gulpe.de *************************************************************************** * softkeyboard: self written softkeyboard. ***************************************************************************/ /* * 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 . */ #include "osmroute.h" #include "draw.h" #include "gui.h" #include "system.h" GUISoftkeyboard *softkeyb = NULL; void gui_softkeyb_getpos (int row, int btnnr, int *x1, int *x2, int *y1, int *y2); void gui_softkeyb_show (int enable) { /* keys which are displayed.. */ char line[GUI_SOFTKEYB_MODE_MAX][GUI_SOFTKEYB_X][GUI_SOFTKEYB_X] = { { "qwertzuiop?", "asdfghjkl??", "yxcvbnm,.-_" }, { "QWERTZUIOP?", "ASDFGHIKL??", "YXCVBNM;:#+" }, { "0123456789=", " ", " " }}; int i, j; /* disable software keyboard */ if (cfg.softkeyboard == 0 || enable == 0) { if (softkeyb) softkeyb->enabled = FALSE; return; } /* check for allocation.. */ if (softkeyb == NULL) { softkeyb = (GUISoftkeyboard*) ml_malloc (sizeof (GUISoftkeyboard)); memset (softkeyb, 0x0, sizeof (GUISoftkeyboard)); } /* reset data */ for (i = 0; i < GUI_SOFTKEYB_MODE_MAX; i++) for (j = 0; j < 3; j++) strncpy (softkeyb->keys[i][j], line[i][j], GUI_SOFTKEYB_X); softkeyb->enabled = TRUE; softkeyb->mode = GUI_SOFTKEYB_MODE_NORM; }; /* only preparing the screen image... copying to the screen will be done later... */ static float _linepos[2][4] = { { 5.0, 25.0, 45.0, 65.0 }, { 20.0, 40.0, 60.0, 95.0 } }; static float _btnpos[2][4] = { { 5.0, 20.0, 35.0, 65.0 }, { 15.0, 30.0, 60.0, 95.0 } }; void gui_softkeyb_getpos (int row, int btnnr, int *x1, int *y1, int *x2, int *y2) { if (row < 3) { *x1 = 5 + (btnnr * (softkeyb->screen->width - 10)) / GUI_SOFTKEYB_X; *x2 = 5 + ((btnnr + 1) * (softkeyb->screen->width - 10)) / GUI_SOFTKEYB_X; *y1 = (_linepos[0][row] * softkeyb->screen->height)/100; *y2 = (_linepos[1][row] * softkeyb->screen->height)/100; } }; void gui_softkeyb_draw () { struct line_style ls; int i, j, x1, x2, y1, y2; if (softkeyb == NULL || gfx_screensize.x < 0 || softkeyb->enabled == FALSE) return; if (softkeyb->screen == NULL || softkeyb->screen->width != gfx_screensize.x) { if (softkeyb->screen) gfx_img_free (softkeyb->screen); softkeyb->screen = gfx_img_alloc (gfx_screensize.x, gfx_screensize.y * 0.8); } /* setup the lines... */ for (j = 0; j < 2; j++) for (i = 0; i < 4; i++) { softkeyb->linepos[j][i] = _linepos[j][i] * softkeyb->screen->width; softkeyb->btnpos[j][i] = _btnpos[j][i] * softkeyb->screen->height; } /* draw border */ ls.c = color[COLOR_white][2]; ls.width = 1; gfx_clear (softkeyb->screen, &color[COLOR_white][1]); draw_rectangle (softkeyb->screen, 1, 1, softkeyb->screen->width-2, softkeyb->screen->height-2, ls); /* draw 3 key rows.. */ ls.c = color[COLOR_blue][2]; ls.width = 1; for (j = 0; j < 3; j++) { for (i = 0; i < GUI_SOFTKEYB_X; i++) { gui_softkeyb_getpos (j, i, &x1, &y1, &x2, &y2); draw_rectangle (softkeyb->screen, x1, y1, x2, y2, ls); } } /* draw the last keys */ };