CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
gui_tbox.c-Dateireferenz
#include "camera_info.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 40 der Datei gui_tbox.c.

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

Definiert in Zeile 41 der Datei gui_tbox.c.

#define BUTTON_SEP   18

Definiert in Zeile 38 der Datei gui_tbox.c.

#define BUTTON_SIZE   6

Definiert in Zeile 39 der Datei gui_tbox.c.

#define MAX_LINES   6

Definiert in Zeile 32 der Datei gui_tbox.c.

#define MAX_MSG_LENGTH   20

Definiert in Zeile 47 der Datei gui_tbox.c.

#define MAX_TEXT_WIDTH   (MAX_WIDTH-2)

Definiert in Zeile 43 der Datei gui_tbox.c.

#define MAX_WIDTH   40

Definiert in Zeile 33 der Datei gui_tbox.c.

#define MIN_WIDTH   28

Definiert in Zeile 34 der Datei gui_tbox.c.

#define MODE_BUTTON   2

Definiert in Zeile 99 der Datei gui_tbox.c.

#define MODE_KEYBOARD   0

Definiert in Zeile 97 der Datei gui_tbox.c.

#define MODE_NAVIGATE   1

Definiert in Zeile 98 der Datei gui_tbox.c.

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

Definiert in Zeile 45 der Datei gui_tbox.c.

#define SPACING_BELOW_TEXT   10

Definiert in Zeile 37 der Datei gui_tbox.c.

#define SPACING_BTN   4

Definiert in Zeile 36 der Datei gui_tbox.c.

#define SPACING_TITLE   4

Definiert in Zeile 35 der Datei gui_tbox.c.

Dokumentation der benutzerdefinierten Typen

typedef char* cmap[][4]

Definiert in Zeile 54 der Datei gui_tbox.c.

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

Definiert in Zeile 49 der Datei gui_tbox.c.

Dokumentation der Funktionen

int _module_can_unload ( )

Definiert in Zeile 510 der Datei gui_tbox.c.

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

Definiert in Zeile 515 der Datei gui_tbox.c.

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

Definiert in Zeile 498 der Datei gui_tbox.c.

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

Definiert in Zeile 329 der Datei gui_tbox.c.

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

Definiert in Zeile 179 der Datei gui_tbox.c.

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

Definiert in Zeile 384 der Datei gui_tbox.c.

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

Definiert in Zeile 378 der Datei gui_tbox.c.

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

Definiert in Zeile 313 der Datei gui_tbox.c.

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

Definiert in Zeile 109 der Datei gui_tbox.c.

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

Definiert in Zeile 341 der Datei gui_tbox.c.

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

Definiert in Zeile 267 der Datei gui_tbox.c.

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

Definiert in Zeile 291 der Datei gui_tbox.c.

292 {
293  int i;
294  if (direction < 0)
295  {
296  //This loop moves all characters on the right of the cursor one place left
297  for (i=cursor; i<strlen(text); i++)
298  {
299  text[i] = text[i+1];
300  }
301  }
302  if (direction > 0)
303  {
304  //This loop moves all characters on the right of the cursor one place right
305  for (i=(strlen(text) < maxlen-1)?strlen(text):maxlen-1; i>cursor; i--)
306  {
307  text[i] = text[i-1];
308  }
309  }
310  gui_tbox_redraw = 1;
311 }
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 115 der Datei gui_tbox.c.

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

Variablen-Dokumentation

libtextbox_sym _libtextbox
Initialisierung:

Definiert in Zeile 523 der Datei gui_tbox.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 532 der Datei gui_tbox.c.

Definiert in Zeile 87 der Datei gui_tbox.c.

int curchar

Definiert in Zeile 92 der Datei gui_tbox.c.

int curgroup

Definiert in Zeile 93 der Datei gui_tbox.c.

int cursor

Definiert in Zeile 94 der Datei gui_tbox.c.

char cursor_to_draw
static

Definiert in Zeile 29 der Datei gui_tbox.c.

int fldlen

Definiert in Zeile 104 der Datei gui_tbox.c.

gui_handler GUI_MODE_TBOX
Initialisierung:

Definiert in Zeile 18 der Datei gui_tbox.c.

gui_handler* gui_tbox_mode_old
static

Definiert in Zeile 21 der Datei gui_tbox.c.

int gui_tbox_redraw
static

Definiert in Zeile 24 der Datei gui_tbox.c.

coord key_offset_x

Definiert in Zeile 105 der Datei gui_tbox.c.

char lastKey

Definiert in Zeile 95 der Datei gui_tbox.c.

int line

Definiert in Zeile 91 der Datei gui_tbox.c.

int lines = 0

Definiert in Zeile 89 der Datei gui_tbox.c.

int maxlen

Definiert in Zeile 104 der Datei gui_tbox.c.

char Mode

Definiert in Zeile 100 der Datei gui_tbox.c.

int offset

Definiert in Zeile 104 der Datei gui_tbox.c.

int running = 0
static

Definiert in Zeile 22 der Datei gui_tbox.c.

int tbox_button_active

Definiert in Zeile 91 der Datei gui_tbox.c.

coord tbox_buttons_x
static

Definiert in Zeile 52 der Datei gui_tbox.c.

coord tbox_buttons_y
static

Definiert in Zeile 52 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 57 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 66 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 76 der Datei gui_tbox.c.

int tbox_height
static

Definiert in Zeile 106 der Datei gui_tbox.c.

const char* tbox_msg
static

Definiert in Zeile 28 der Datei gui_tbox.c.

tbox_on_select_t tbox_on_select = 0

Definiert in Zeile 50 der Datei gui_tbox.c.

const char* tbox_title
static

Definiert in Zeile 27 der Datei gui_tbox.c.

int tbox_width
static

Definiert in Zeile 106 der Datei gui_tbox.c.

char* text = 0

Definiert in Zeile 103 der Datei gui_tbox.c.

char text_buf[MAX_TEXT_SIZE+1]

Definiert in Zeile 102 der Datei gui_tbox.c.

char text_limit_reached
static

Definiert in Zeile 25 der Datei gui_tbox.c.

coord text_offset_x

Definiert in Zeile 105 der Datei gui_tbox.c.

coord text_offset_y

Definiert in Zeile 105 der Datei gui_tbox.c.

int window_width

Definiert in Zeile 104 der Datei gui_tbox.c.