CHDK_DE Vorschauversion  Trunk Rev. 5294
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
gui_tbox.c-Dateireferenz
#include "camera_info.h"
#include "stdlib.h"
#include "keyboard.h"
#include "conf.h"
#include "lang.h"
#include "gui.h"
#include "gui_draw.h"
#include "gui_lang.h"
#include "gui_mbox.h"
#include "gui_tbox.h"
#include "module_def.h"
+ Include-Abhängigkeitsdiagramm für gui_tbox.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define MAX_LINES   6
 
#define MAX_WIDTH   40
 
#define MIN_WIDTH   28
 
#define SPACING_TITLE   4
 
#define SPACING_BTN   4
 
#define SPACING_BELOW_TEXT   10
 
#define BUTTON_SEP   18
 
#define BUTTON_SIZE   6
 
#define BUTTON_AREA_WIDTH   (2*BUTTON_SIZE*FONT_WIDTH+BUTTON_SEP)
 
#define BUTTON_CHAR_WIDTH   ((BUTTON_AREA_WIDTH + BUTTON_SEP) / FONT_WIDTH + 1)
 
#define MAX_TEXT_WIDTH   (MAX_WIDTH-2)
 
#define RESET_CHAR   lastKey = '\0'; curchar = -1; curgroup = -1;
 
#define MAX_MSG_LENGTH   20
 
#define MODE_KEYBOARD   0
 
#define MODE_NAVIGATE   1
 
#define MODE_BUTTON   2
 

Typdefinitionen

typedef void(* tbox_on_select_t )(const char *newstr)
 
typedef char * cmap [][4]
 

Funktionen

int gui_tbox_kbd_process ()
 
void gui_tbox_kbd_process_menu_btn ()
 
void gui_tbox_draw ()
 
static char * map_chars (int line, int group)
 
int textbox_init (int title, int msg, const char *defaultstr, unsigned int maxsize, void(*on_select)(const char *newstr), char *input_buffer)
 
static void gui_tbox_draw_buttons ()
 
static void tbox_move_cursor (int direction)
 
static void tbox_move_text (int direction)
 
static void insert_space ()
 
static void backspace ()
 
static void tbox_keyboard_key (char curKey, int subgroup)
 
int _module_unloader ()
 
int _module_can_unload ()
 
int _module_exit_alt ()
 

Variablen

gui_handler GUI_MODE_TBOX
 
static gui_handlergui_tbox_mode_old
 
static int running = 0
 
static int gui_tbox_redraw
 
static char text_limit_reached
 
static const char * tbox_title
 
static const char * tbox_msg
 
static char cursor_to_draw
 
tbox_on_select_t tbox_on_select = 0
 
static coord tbox_buttons_x
 
static coord tbox_buttons_y
 
cmap tbox_chars_default
 
cmap tbox_chars_german
 
cmap tbox_chars_russian
 
cmapcharmaps [] = { &tbox_chars_default, &tbox_chars_german, &tbox_chars_russian }
 
int lines = 0
 
int tbox_button_active
 
int line
 
int curchar
 
int curgroup
 
int cursor
 
char lastKey
 
char Mode
 
char text_buf [MAX_TEXT_SIZE+1]
 
char * text = 0
 
int maxlen
 
int offset
 
int fldlen
 
int window_width
 
coord text_offset_x
 
coord text_offset_y
 
coord key_offset_x
 
static int tbox_width
 
static int tbox_height
 
libtextbox_sym _libtextbox
 
ModuleInfo _module_info
 

Makro-Dokumentation

#define BUTTON_AREA_WIDTH   (2*BUTTON_SIZE*FONT_WIDTH+BUTTON_SEP)

Definiert in Zeile 41 der Datei gui_tbox.c.

#define BUTTON_CHAR_WIDTH   ((BUTTON_AREA_WIDTH + BUTTON_SEP) / FONT_WIDTH + 1)

Definiert in Zeile 42 der Datei gui_tbox.c.

#define BUTTON_SEP   18

Definiert in Zeile 39 der Datei gui_tbox.c.

#define BUTTON_SIZE   6

Definiert in Zeile 40 der Datei gui_tbox.c.

#define MAX_LINES   6

Definiert in Zeile 33 der Datei gui_tbox.c.

#define MAX_MSG_LENGTH   20

Definiert in Zeile 48 der Datei gui_tbox.c.

#define MAX_TEXT_WIDTH   (MAX_WIDTH-2)

Definiert in Zeile 44 der Datei gui_tbox.c.

#define MAX_WIDTH   40

Definiert in Zeile 34 der Datei gui_tbox.c.

#define MIN_WIDTH   28

Definiert in Zeile 35 der Datei gui_tbox.c.

#define MODE_BUTTON   2

Definiert in Zeile 100 der Datei gui_tbox.c.

#define MODE_KEYBOARD   0

Definiert in Zeile 98 der Datei gui_tbox.c.

#define MODE_NAVIGATE   1

Definiert in Zeile 99 der Datei gui_tbox.c.

#define RESET_CHAR   lastKey = '\0'; curchar = -1; curgroup = -1;

Definiert in Zeile 46 der Datei gui_tbox.c.

#define SPACING_BELOW_TEXT   10

Definiert in Zeile 38 der Datei gui_tbox.c.

#define SPACING_BTN   4

Definiert in Zeile 37 der Datei gui_tbox.c.

#define SPACING_TITLE   4

Definiert in Zeile 36 der Datei gui_tbox.c.

Dokumentation der benutzerdefinierten Typen

typedef char* cmap[][4]

Definiert in Zeile 55 der Datei gui_tbox.c.

typedef void(* tbox_on_select_t)(const char *newstr)

Definiert in Zeile 50 der Datei gui_tbox.c.

Dokumentation der Funktionen

int _module_can_unload ( )

Definiert in Zeile 511 der Datei gui_tbox.c.

512 {
513  return running == 0;
514 }
int _module_exit_alt ( )

Definiert in Zeile 516 der Datei gui_tbox.c.

517 {
518  running = 0;
519  return 0;
520 }
int _module_unloader ( )

Definiert in Zeile 499 der Datei gui_tbox.c.

500 {
501  // clean allocated resource
502  if (tbox_on_select)
503  {
504  tbox_on_select(0); // notify callback about exit as cancel
505  tbox_on_select = 0; // prevent calling twice in the (unlikely) event of the unload called twice
506  }
507 
508  return 0;
509 }
static void backspace ( )
static

Definiert in Zeile 330 der Datei gui_tbox.c.

331 {
332  if (cursor >= 0)
333  {
334  tbox_move_text(-1);
335  tbox_move_cursor(-1);
336  if ((strlen(text) >= MAX_TEXT_WIDTH) && ((cursor-offset) >= MAX_TEXT_WIDTH-1))
337  offset--;
338  RESET_CHAR
339  }
340 }
void gui_tbox_draw ( )

Definiert in Zeile 180 der Datei gui_tbox.c.

181 {
183  {
184  if (gui_tbox_redraw==2)
185  {
186  text_limit_reached = 0;
187 
189 
195 
197  y += FONT_HEIGHT+2+SPACING_TITLE;
198 
199  // draw prompt
201 
204 
206  tbox_buttons_y = text_offset_y+FONT_HEIGHT+SPACING_BELOW_TEXT; // on place of symbol line
207 
208  if (Mode == MODE_BUTTON)
210  }
211 
212  // draw edit field
214 
215  // draw long text marker
217  draw_char(text_offset_x-FONT_WIDTH, text_offset_y, (offset>0) ? '\21' : ' ', MAKE_COLOR(COLOR_GREY, COLOR_RED));
218 
219  // symbol line
220  if (Mode == MODE_NAVIGATE)
221  {
222  //rect clears any previous message
226  }
227  else if (Mode == MODE_KEYBOARD)
228  {
229  // draw keyboard
230  // clean previous symbols line
232 
233  // draw current symbols line
234  int group;
235  static int y_offset[4] = { FONT_HEIGHT, 0, FONT_HEIGHT, 2*FONT_HEIGHT };
236  static int x_just[4] = { TEXT_LEFT, TEXT_CENTER, TEXT_RIGHT, TEXT_CENTER };
237 
238  for (group = 0; group < 4; group++)
239  {
240  char *tstr = map_chars(line,group);
241 
242  int y = tbox_buttons_y + y_offset[group];
243  int x = key_offset_x + 4*FONT_WIDTH;
244 
245  x = draw_text_justified(x, y, tstr, MAKE_COLOR(COLOR_GREY, COLOR_WHITE), tbox_width-8, 1, x_just[group]);
246  if ((group == curgroup) && (curchar >= 0))
247  draw_char(x+(curchar*FONT_WIDTH), y, tstr[curchar], MAKE_COLOR(COLOR_RED, COLOR_WHITE)); // Selected char cursor
248  }
249  }
250  gui_tbox_redraw = 0;
251  }
252 
253  if (text_limit_reached)
254  {
255  // clean max_keyboard_length chars long field
256  if (text_limit_reached%4 == 0)
261  }
262 
263  // Insertion point cursor
266 }
int gui_tbox_kbd_process ( )

Definiert in Zeile 385 der Datei gui_tbox.c.

386 {
387  if (Mode == MODE_KEYBOARD)
388  {
390  {
391  case KEY_SHOOT_HALF:
392  line = (line+1)%lines;
393  RESET_CHAR
394  gui_tbox_redraw = 1;
395  break;
396  case KEY_UP:
397  tbox_keyboard_key('U',1);
398  break;
399  case KEY_DOWN:
400  tbox_keyboard_key('D',3);
401  break;
402  case KEY_LEFT:
403  tbox_keyboard_key('L',0);
404  break;
405  case KEY_RIGHT:
406  tbox_keyboard_key('R',2);
407  break;
408  case KEY_SET:
409  tbox_keyboard_key('O',0);
410  break;
411  case KEY_ZOOM_IN:
412  case KEY_DISPLAY:
413  insert_space();
414  break;
415  case KEY_ZOOM_OUT:
416  backspace();
417  break;
418  case JOGDIAL_LEFT:
419  tbox_move_cursor(-1);
420  RESET_CHAR
421  break;
422  case JOGDIAL_RIGHT:
423  if (text[cursor+1] != '\0') tbox_move_cursor(1);
424  RESET_CHAR
425  break;
426  }
427  }
428  else if (Mode == MODE_NAVIGATE)
429  {
431  {
432  case JOGDIAL_LEFT:
433  case KEY_LEFT:
434  tbox_move_cursor(-1);
435  RESET_CHAR
436  break;
437  case JOGDIAL_RIGHT:
438  case KEY_RIGHT:
439  if (text[cursor+1] != '\0') tbox_move_cursor(1);
440  RESET_CHAR
441  break;
442  case KEY_SHOOT_HALF:
443  backspace();
444  break;
445  case KEY_DISPLAY:
446  insert_space();
447  break;
448  case KEY_ZOOM_IN:
450  {
451  offset++;
452  if ((cursor+1)<offset) cursor++;
453  gui_tbox_redraw = 1;
454  }
455  break;
456  case KEY_ZOOM_OUT:
457  if (offset > 0)
458  {
459  offset--;
461  gui_tbox_redraw = 1;
462  }
463  break;
464  }
465  }
466  else { // Mode == MODE_BUTTON
468  {
469  case JOGDIAL_LEFT:
470  case JOGDIAL_RIGHT:
471  case KEY_LEFT:
472  case KEY_RIGHT:
475  break;
476  case KEY_SET:
478  if (tbox_on_select)
479  {
480  if (tbox_button_active == 0)
481  tbox_on_select(text); // ok
482  else
483  tbox_on_select(0); // cancel
484  tbox_on_select = 0; // Prevent unloader from calling this function again
485  }
486  running = 0;
487  break;
488  }
489  }
490  return 0;
491 }
void gui_tbox_kbd_process_menu_btn ( )

Definiert in Zeile 379 der Datei gui_tbox.c.

380 {
381  Mode = (Mode + 1) % 3;
382  gui_tbox_redraw=2;
383 }
static void insert_space ( )
static

Definiert in Zeile 314 der Datei gui_tbox.c.

315 {
316  if (strlen(text) < maxlen)
317  {
318  if (text[cursor+1] != '\0')
319  tbox_move_text(1); //check whether cursor is at the end of the string
320  tbox_move_cursor(1);
321  text[cursor] = ' ';
322  }
323  else
324  {
325  text_limit_reached = 8;
326  }
327  RESET_CHAR
328 }
static char* map_chars ( int  line,
int  group 
)
static

Definiert in Zeile 110 der Datei gui_tbox.c.

111 {
112  return (*charmaps[conf.tbox_char_map])[line][group];
113 }
static void tbox_keyboard_key ( char  curKey,
int  subgroup 
)
static

Definiert in Zeile 342 der Datei gui_tbox.c.

343 {
344  if (lastKey == curKey)
345  {
346  curchar++;
347  curgroup = subgroup;
348  char *tstr = map_chars(line,subgroup);
349  if (tstr[curchar] == 0) curchar = 0;
350  text[cursor] = tstr[curchar];
351  }
352  else if (curKey == 'O')
353  {
354  RESET_CHAR
355  }
356  else
357  {
358  if (strlen(text)<maxlen)
359  {
360  curchar = 0; curgroup = subgroup;
361  if (cursor < (maxlen-1))
362  {
363  if (text[cursor+1] != '\0') tbox_move_text(1); //check whether cursor is at the end of the string
364  tbox_move_cursor(1);
365  }
366  lastKey = curKey;
367  char *tstr = map_chars(line,subgroup);
368  text[cursor] = tstr[curchar];
369  }
370  else
371  {
372  text_limit_reached = 8;
373  RESET_CHAR
374  }
375  }
376  gui_tbox_redraw = 1;
377 }
static void tbox_move_cursor ( int  direction)
static

Definiert in Zeile 268 der Datei gui_tbox.c.

269 {
271  if (direction < 0)
272  {
273  if (cursor >= 0)
274  {
275  cursor--;
276  if (maxlen>MAX_TEXT_WIDTH && offset != 0 && cursor<offset)
277  offset--;
278  }
279  }
280  if (direction > 0)
281  {
282  if (cursor < (maxlen-1))
283  {
284  cursor++;
286  offset++;
287  }
288  }
289  gui_tbox_redraw = 1;
290 }
static void tbox_move_text ( int  direction)
static

Definiert in Zeile 292 der Datei gui_tbox.c.

293 {
294  int i;
295  if (direction < 0)
296  {
297  //This loop moves all characters on the right of the cursor one place left
298  for (i=cursor; i<strlen(text); i++)
299  {
300  text[i] = text[i+1];
301  }
302  }
303  if (direction > 0)
304  {
305  //This loop moves all characters on the right of the cursor one place right
306  for (i=(strlen(text) < maxlen-1)?strlen(text):maxlen-1; i>cursor; i--)
307  {
308  text[i] = text[i-1];
309  }
310  }
311  gui_tbox_redraw = 1;
312 }
int textbox_init ( int  title,
int  msg,
const char *  defaultstr,
unsigned int  maxsize,
void(*)(const char *newstr)  on_select,
char *  input_buffer 
)

Definiert in Zeile 116 der Datei gui_tbox.c.

117 {
118  running = 1;
119 
120  if (input_buffer)
121  text = input_buffer;
122  else
123  {
124  if (maxsize > MAX_TEXT_SIZE) maxsize = MAX_TEXT_SIZE;
125  text = text_buf;
126  }
127 
128  // Count number of entries in selected 'charmap'
129  for (lines=0; map_chars(lines,0); lines++) ;
130 
131  memset(text, '\0', sizeof(char)*(maxsize+1));
132 
133  if ( defaultstr )
134  strncpy(text, defaultstr, maxsize);
135 
136  tbox_button_active = 0;
137 
138  tbox_title = lang_str(title);
139  tbox_msg = lang_str(msg);
140  tbox_on_select = on_select;
141 
143  line = 0;
144  RESET_CHAR
145  cursor = -1;
146  maxlen = maxsize;
147  fldlen = (maxlen < MAX_TEXT_WIDTH) ? maxlen : MAX_TEXT_WIDTH; // length of edit field
148  offset = 0;
149 
153  if (tbox_width < MIN_WIDTH)
154  tbox_width = MIN_WIDTH; // keyboard length
156  tbox_width = MAX_MSG_LENGTH; // max message length
157  if (tbox_width < maxlen)
158  {
159  if (maxlen < MAX_TEXT_WIDTH)
160  tbox_width = maxlen + 2; // text length
161  else if (tbox_width < MAX_WIDTH)
163  }
164 
167 
168  gui_tbox_redraw = 2;
170 
171  return 1;
172 }

Variablen-Dokumentation

libtextbox_sym _libtextbox
Initialisierung:

Definiert in Zeile 524 der Datei gui_tbox.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 533 der Datei gui_tbox.c.

Definiert in Zeile 88 der Datei gui_tbox.c.

int curchar

Definiert in Zeile 93 der Datei gui_tbox.c.

int curgroup

Definiert in Zeile 94 der Datei gui_tbox.c.

int cursor

Definiert in Zeile 95 der Datei gui_tbox.c.

char cursor_to_draw
static

Definiert in Zeile 30 der Datei gui_tbox.c.

int fldlen

Definiert in Zeile 105 der Datei gui_tbox.c.

gui_handler GUI_MODE_TBOX
Initialisierung:

Definiert in Zeile 19 der Datei gui_tbox.c.

gui_handler* gui_tbox_mode_old
static

Definiert in Zeile 22 der Datei gui_tbox.c.

int gui_tbox_redraw
static

Definiert in Zeile 25 der Datei gui_tbox.c.

coord key_offset_x

Definiert in Zeile 106 der Datei gui_tbox.c.

char lastKey

Definiert in Zeile 96 der Datei gui_tbox.c.

int line

Definiert in Zeile 92 der Datei gui_tbox.c.

int lines = 0

Definiert in Zeile 90 der Datei gui_tbox.c.

int maxlen

Definiert in Zeile 105 der Datei gui_tbox.c.

char Mode

Definiert in Zeile 101 der Datei gui_tbox.c.

int offset

Definiert in Zeile 105 der Datei gui_tbox.c.

int running = 0
static

Definiert in Zeile 23 der Datei gui_tbox.c.

int tbox_button_active

Definiert in Zeile 92 der Datei gui_tbox.c.

coord tbox_buttons_x
static

Definiert in Zeile 53 der Datei gui_tbox.c.

coord tbox_buttons_y
static

Definiert in Zeile 53 der Datei gui_tbox.c.

cmap tbox_chars_default
Initialisierung:
=
{
{"ABCDEF","GHIJKL","MNOPQRS","TUVWXYZ"},
{"abcdef","ghijkl","mnopqrs","tuvwxyz"},
{"123","456","789","0+-=/"},
{".,:;?!","@#$%^& {0} }","()[]{}","<>\"'`~_"},
{0}
}

Definiert in Zeile 58 der Datei gui_tbox.c.

cmap tbox_chars_german
Initialisierung:
=
{
{"ABCDEF","GHIJKL","MNOPQRS","TUVWXYZ"},
{"abcdef","ghijkl","mnopqrs","tuvwxyz"},
{"123","456","789","0+-=/"},
{".,:;?!","@#$%^& {"","","",""}, {0} }","()[]{}","<>\"'`~_"},
{" {0} }"," {0} }"," {0} }"," {0} }"},
{0}
}

Definiert in Zeile 67 der Datei gui_tbox.c.

cmap tbox_chars_russian
Initialisierung:
=
{
{"ABCDEF","GKLHIJ","MNOPQRS","TUVWXYZ"},
{"abcdef","ghijkl","mnopqrs","tuvwxyz"},
{" {"","","",""}, {"123","456","789","0+-="}, {" .:,",";/\\","'\"*","#%&"}, {0} }"," {"","","",""}, {"123","456","789","0+-="}, {" .:,",";/\\","'\"*","#%&"}, {0} }"," {"","","",""}, {"123","456","789","0+-="}, {" .:,",";/\\","'\"*","#%&"}, {0} }",""},
{" {"123","456","789","0+-="}, {" .:,",";/\\","'\"*","#%&"}, {0} }"," {"123","456","789","0+-="}, {" .:,",";/\\","'\"*","#%&"}, {0} }",""," {"123","456","789","0+-="}, {" .:,",";/\\","'\"*","#%&"}, {0} }"},
{"123","456","789","0+-="},
{" .:,",";/\\","'\"*","#%&"},
{0}
}

Definiert in Zeile 77 der Datei gui_tbox.c.

int tbox_height
static

Definiert in Zeile 107 der Datei gui_tbox.c.

const char* tbox_msg
static

Definiert in Zeile 29 der Datei gui_tbox.c.

tbox_on_select_t tbox_on_select = 0

Definiert in Zeile 51 der Datei gui_tbox.c.

const char* tbox_title
static

Definiert in Zeile 28 der Datei gui_tbox.c.

int tbox_width
static

Definiert in Zeile 107 der Datei gui_tbox.c.

char* text = 0

Definiert in Zeile 104 der Datei gui_tbox.c.

char text_buf[MAX_TEXT_SIZE+1]

Definiert in Zeile 103 der Datei gui_tbox.c.

char text_limit_reached
static

Definiert in Zeile 26 der Datei gui_tbox.c.

coord text_offset_x

Definiert in Zeile 106 der Datei gui_tbox.c.

coord text_offset_y

Definiert in Zeile 106 der Datei gui_tbox.c.

int window_width

Definiert in Zeile 105 der Datei gui_tbox.c.