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

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  _gline
 

Makrodefinitionen

#define GRID_REDRAW_INTERVAL   4
 

Typdefinitionen

typedef struct _gline gline
 

Aufzählungen

enum  grid_elem_type {
  GRID_ELEM_LINE, GRID_ELEM_RECT, GRID_ELEM_FILLED_RECT, GRID_ELEM_ELLIPSE,
  GRID_ELEM_FILLED_ELLIPSE
}
 

Funktionen

static void grid_lines_free_data ()
 
static void new_grid ()
 
static glinenew_gline ()
 
static char * skip_whitespace (char *p)
 
static char * skip_to_eol (char *p)
 
static char * skip_token (char *p)
 
static void process_title (char *ptr)
 
static int get_color (char *p, char **np)
 
static int get_value (char *p, int *failed, int is_color)
 
static void process_element (char *ptr, int n, grid_elem_type type)
 
static int parse_grid_file (char *ptr, int size)
 
void grid_lines_load (const char *fn)
 
void gui_grid_draw_osd (int force)
 
int _module_loader (__attribute__((unused)) unsigned int *chdk_export_list)
 
int _module_unloader ()
 
int _module_can_unload ()
 

Variablen

static int resize
 
static glinehead
 
static glinelast
 
static int grid_loading = 0
 
static int interval = GRID_REDRAW_INTERVAL
 
libgrids_sym _libgrids
 
ModuleInfo _module_info
 

Makro-Dokumentation

#define GRID_REDRAW_INTERVAL   4

Definiert in Zeile 13 der Datei gui_grid.c.

Dokumentation der benutzerdefinierten Typen

typedef struct _gline gline

Dokumentation der Aufzählungstypen

Aufzählungswerte
GRID_ELEM_LINE 
GRID_ELEM_RECT 
GRID_ELEM_FILLED_RECT 
GRID_ELEM_ELLIPSE 
GRID_ELEM_FILLED_ELLIPSE 

Definiert in Zeile 16 der Datei gui_grid.c.

Dokumentation der Funktionen

int _module_can_unload ( )

Definiert in Zeile 304 der Datei gui_grid.c.

305 {
306  return (conf.show_grid_lines == 0 && !grid_loading);
307 }
int _module_loader ( __attribute__((unused)) unsigned int *  chdk_export_list)

Definiert in Zeile 288 der Datei gui_grid.c.

289 {
291  return 0;
292 }
int _module_unloader ( )

Definiert in Zeile 298 der Datei gui_grid.c.

299 {
301  return 0;
302 }
static int get_color ( char *  p,
char **  np 
)
static

Definiert in Zeile 95 der Datei gui_grid.c.

95  {
96  int rv = 0;
97  if (strncmp(p,"trans",5) == 0) rv = 255+1;
98  else if (strncmp(p,"black",5) == 0) rv = 255+2;
99  else if (strncmp(p,"white",5) == 0) rv = 255+3;
100  else if (strncmp(p,"red_dark",8) == 0) rv = 255+5;
101  else if (strncmp(p,"red_light",9) == 0) rv = 255+6;
102  else if (strncmp(p,"red",3) == 0) rv = 255+4;
103  else if (strncmp(p,"green_dark",10) == 0) rv = 255+8;
104  else if (strncmp(p,"green_light",11) == 0) rv = 255+9;
105  else if (strncmp(p,"green",5) == 0) rv = 255+7;
106  else if (strncmp(p,"blue_dark",9) == 0) rv = 255+11;
107  else if (strncmp(p,"blue_light",10) == 0) rv = 255+12;
108  else if (strncmp(p,"blue",4) == 0) rv = 255+10;
109  else if (strncmp(p,"grey_trans",10) == 0) rv = 255+19;
110  else if (strncmp(p,"grey_dark",9) == 0) rv = 255+14;
111  else if (strncmp(p,"grey_light",10) == 0) rv = 255+15;
112  else if (strncmp(p,"grey",4) == 0) rv = 255+13;
113  else if (strncmp(p,"yellow_dark",11) == 0) rv = 255+17;
114  else if (strncmp(p,"yellow_light",12) == 0) rv = 255+18;
115  else if (strncmp(p,"yellow",6) == 0) rv = 255+16;
116  else if (strncmp(p,"magenta",7) == 0) rv = 255+20;
117  if (rv > 0)
118  while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p != '\n') p += 1;
119  if (np) *np = p;
120  return rv;
121 }
static int get_value ( char *  p,
int *  failed,
int  is_color 
)
static

Definiert in Zeile 123 der Datei gui_grid.c.

123  {
124  int rv = 0;
125  int fnd = 0;
126  char *np = p;
127  rv = strtol(p, &np, 0);
128  if (np != p) fnd = 1;
129  if (!fnd && is_color) {
130  char* np = p;
131  rv = get_color(p, &np);
132  if (np != p) fnd = 1;
133  }
134  *failed = !fnd;
135  return rv;
136 }
static void grid_lines_free_data ( )
static

Definiert in Zeile 39 der Datei gui_grid.c.

39  {
40  while (head) {
41  gline* p = head;
42  head = head->next;
43  free(p);
44  }
45 }
void grid_lines_load ( const char *  fn)

Definiert in Zeile 209 der Datei gui_grid.c.

210 {
211  grid_loading = 1;
212  if (process_file(fn, parse_grid_file, 1) > 0) // non-zero length file found?
213  {
214  if (conf.grid_title[0]==0) // use filename if no @title string found
215  {
216  char* c = strrchr(fn, '/');
217  strncpy(conf.grid_title, (c)?c+1:fn, sizeof(conf.grid_title));
218  conf.grid_title[sizeof(conf.grid_title)-1] = 0;
219  }
221  }
222  grid_loading = 0;
223 }
void gui_grid_draw_osd ( int  force)

Definiert in Zeile 226 der Datei gui_grid.c.

227 {
229  {
230  int xs=0, xo=0, ys=0, yo=0;
231  gline* ptr;
233 
234  if (force || --interval==0) {
235  if (resize) {
236  // Grid aspect ratio is 4:3 - fit to 3:2 or 16:9 as needed and center on screen
237  // Note: assumes aspect ratio of screen dimensions matches display aspect ratio
238  xs = (camera_screen.height * 4) / 3;
239  xo = (camera_screen.width - xs) / 2;
240  ys = camera_screen.height;
241  yo = 0;
242  }
243  for (ptr = head; ptr; ptr = ptr->next) {
245  int x0 = ptr->x0;
246  int y0 = ptr->y0;
247  int x1 = ptr->x1;
248  int y1 = ptr->y1;
249  if (resize) {
250  x0 = ((x0 * xs + 8192) >> 14) + xo;
251  y0 = ((y0 * ys + 8192) >> 14) + yo;
252  x1 = ((x1 * xs + 8192) >> 14);
253  y1 = ((y1 * ys + 8192) >> 14);
254  }
255  switch (ptr->type) {
256  case GRID_ELEM_LINE:
257  draw_line(x0, y0, x1+xo, y1+yo, col);
258  break;
259  case GRID_ELEM_RECT:
260  draw_rectangle(x0, y0, x1+xo, y1+yo, col, RECT_BORDER1);
261  break;
263  draw_rectangle(x0, y0, x1+xo, y1+yo, col, RECT_BORDER1|DRAW_FILLED);
264  break;
265  case GRID_ELEM_ELLIPSE:
266  draw_ellipse(x0, y0, (unsigned int)x1, (unsigned int)y1, col, 0);
267  break;
269  draw_ellipse(x0, y0, (unsigned int)x1, (unsigned int)y1, col, DRAW_FILLED);
270  break;
271  }
272  }
274  }
275  }
276 }
static gline* new_gline ( )
static

Definiert in Zeile 53 der Datei gui_grid.c.

53  {
54  gline* p = malloc(sizeof(gline));
55  if (p) {
56  memset(p, 0, sizeof(gline));
57  if (!head) head = p;
58  if (last) last->next = p;
59  last = p;
60  }
61  return p;
62 }
static void new_grid ( )
static

Definiert in Zeile 47 der Datei gui_grid.c.

47  {
49  head = last = 0;
50  resize = (camera_screen.width != 360) || (camera_screen.height != 240);
51 }
static int parse_grid_file ( char *  ptr,
int  size 
)
static

Definiert in Zeile 168 der Datei gui_grid.c.

169 {
170  conf.grid_title[0]=0;
171 
172  if (size > 0)
173  {
174  new_grid();
175 
176  while (ptr[0])
177  {
179  if (ptr[0]=='@')
180  {
181  if (strncmp("@title", ptr, 6)==0) {
182  ptr+=6;
184  } else if (strncmp("@line", ptr, 5)==0) {
185  ptr+=5;
187  } else if (strncmp("@rectf", ptr, 6)==0) {
188  ptr+=6;
190  } else if (strncmp("@rect", ptr, 5)==0) {
191  ptr+=5;
193  } else if (strncmp("@elpsf", ptr, 6)==0) {
194  ptr+=6;
196  } else if (strncmp("@elps", ptr, 5)==0) {
197  ptr+=5;
199  }
200  }
201  ptr = skip_to_eol(ptr);
202  }
203  }
204 
205  return size;
206 }
static void process_element ( char *  ptr,
int  n,
grid_elem_type  type 
)
static

Definiert in Zeile 138 der Datei gui_grid.c.

138  {
139  int i, failed;
140  long nums[6];
141 
142  for (i=0; i<(int)(sizeof(nums)/sizeof(nums[0])) && i<n; ++i) {
144  nums[i] = get_value(ptr, &failed, i >= 4);
145  if (failed) // error
146  return;
147  ptr = skip_token(ptr);
148  }
149 
150  gline* gptr = new_gline();
151 
152  if (gptr) {
153  gptr->type=type;
154  if (resize) {
155  // Scale values for later resizing
156  nums[0] = ((nums[0] << 14) + 180) / 360;
157  nums[1] = ((nums[1] << 14) + 120) / 240;
158  nums[2] = ((nums[2] << 14) + 180) / 360;
159  nums[3] = ((nums[3] << 14) + 120) / 240;
160  }
161  gptr->x0=nums[0]; gptr->y0=nums[1];
162  gptr->x1=nums[2]; gptr->y1=nums[3];
163  gptr->clf=nums[4]; gptr->clb=nums[5];
164  }
165 }
static void process_title ( char *  ptr)
static

Definiert in Zeile 82 der Datei gui_grid.c.

82  {
83  register int i=0;
84 
86  while (i<(int)(sizeof(conf.grid_title)-1) && ptr[i] && ptr[i]!='\r' && ptr[i]!='\n') {
87  conf.grid_title[i]=ptr[i];
88  ++i;
89  }
90  conf.grid_title[i]=0;
91 }
static char* skip_to_eol ( char *  p)
static

Definiert in Zeile 70 der Datei gui_grid.c.

70  {
71  while (*p && *p != '\n') p += 1; // skip to eol
72  if (*p) p += 1;
73  return p;
74 }
static char* skip_token ( char *  p)
static

Definiert in Zeile 76 der Datei gui_grid.c.

76  {
77  while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p != '\n') p += 1;
78  return p;
79 }
static char* skip_whitespace ( char *  p)
static

Definiert in Zeile 65 der Datei gui_grid.c.

65  {
66  while (*p && (*p == ' ' || *p == '\t' || *p == ',')) p += 1; // skip whitespace or comma
67  return p;
68 }

Variablen-Dokumentation

libgrids_sym _libgrids
Initialisierung:

Definiert in Zeile 311 der Datei gui_grid.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 321 der Datei gui_grid.c.

int grid_loading = 0
static

Definiert in Zeile 35 der Datei gui_grid.c.

gline* head
static

Definiert in Zeile 32 der Datei gui_grid.c.

int interval = GRID_REDRAW_INTERVAL
static

Definiert in Zeile 36 der Datei gui_grid.c.

gline* last
static

Definiert in Zeile 33 der Datei gui_grid.c.

int resize
static

Definiert in Zeile 31 der Datei gui_grid.c.