CircleOS  1
toolbar.c
Go to the documentation of this file.
1 /****************** COPYRIGHT (C) 2007-2013 KEOLABS S.A.S. ********************/
14 /******************************************************************************/
15 
16 /* Includes ------------------------------------------------------------------*/
17 #include "circle.h"
18 
20 
21 /* Private define ------------------------------------------------------------*/
22 
23 /* Extern variables ---------------------------------------------------------*/
24 
25 //-- System toolbar shown by default
26 extern const u16 ButtonMenuBmp[];
27 extern const u16 ButtonLowSoundHPBmp[];
28 extern const u16 ButtonHighSoundHPBmp[];
29 extern const u16 ButtonMuteHPBmp[];
30 extern const u16 ButtonSoundHPBmp[];
31 extern const u16 ButtonLowSoundLSBmp[];
32 extern const u16 ButtonHighSoundLSBmp[];
33 extern const u16 ButtonMuteLSBmp[];
34 extern const u16 ButtonSoundLSBmp[];
35 
36 /* Private functions ---------------------------------------------------------*/
37 enum MENU_code fLowSound();
38 enum MENU_code fHighSound();
39 enum MENU_code fMuteSound();
40 enum MENU_code fDefaultAction();
41 
42 /* Private variables ---------------------------------------------------------*/
43 s32 ScreenButton = -1; // Current pushed button (on the touchscreen)
44 s32 CurOrientation = V12; // Current orientation of the screen
45 s32 OldOrientation = V12;
46 s32 RedrawToolbarRequest;
47 //~ divider_t Max_cnt_tb = 100; // System tick divider
48 
49 tToolbar* CurrentToolbar = 0;
50 tToolbarItem* CurrentTbCommand = 0;
51 
52 
53 tToolbar DefaultToolbar =
54 {
55  TB_NB_BUTTONS,
56  0,
57  {
58  { ButtonMenuBmp, fDefaultAction },
59  { ButtonLowSoundLSBmp, fLowSound },
60  { ButtonHighSoundLSBmp, fHighSound },
61  { ButtonMuteLSBmp, fMuteSound },
62  }
63 };
64 
65 /*******************************************************************************
66 *
67 * TOOLBAR_Init
68 *
69 *******************************************************************************/
77 /******************************************************************************/
78 NODEBUG void TOOLBAR_Init( void )
79 {
80  LCD_FillRect_Circle( 0, PHYS_SCREEN_HEIGHT - BUTTON_HEIGHT, PHYS_SCREEN_WIDTH, BUTTON_HEIGHT, RGB_WHITE );
82 }
83 
84 /*******************************************************************************
85 *
86 * TOOLBAR_Handler
87 *
88 *******************************************************************************/
96 /******************************************************************************/
97 void TOOLBAR_Handler( void )
98 {
99  //~ static divider_t divider_coord = 0;
100  s32 OldButton = ScreenButton;
101  s32 X, Y;
102  vs32 i;
103 
104  // Don't execute, if it's not time
105  //~ if ( ( divider_coord++ % Max_cnt_tb ) != 0 ) //YRT130718 divider is now managed by scheduler
106  //~ return;
107 
108  // Don't execute, if touchscreen not operational (calibration...)
109  if ( TOUCHSCR_GetMode() == TS_CALIBRATION )
110  return;
111 
112  // See if a hit on the touchscreen has been done
113  if ( TOUCHSCR_IsPressed() )
114  {
115  // Get the position
116  X = TOUCHSCR_Info.xAbsPos;
117  Y = TOUCHSCR_Info.yAbsPos;
118 
119  // First test whether a button is pressed...
120  if ( Y > APP_SCREEN_HEIGHT )
121  {
122  // A button is pushed
123  ScreenButton = X / BUTTON_WIDTH;
124  if ( ScreenButton > ( CurrentToolbar->NbItems - 1 ) )
125  {
126  ScreenButton = CurrentToolbar->NbItems - 1;
127  }
128  if ( ScreenButton < 0 )
129  {
130  ScreenButton = 0;
131  }
132  }
133  else
134  // No button selected
135  ScreenButton = -1;
136  }
137  else
138  {
139  // See if a redraw is requested
140  if ( RedrawToolbarRequest )
141  {
142  if ( ( RedrawToolbarRequest >> 4 ) )
143  {
144  // System toolbar requested
145  CurrentToolbar = &DefaultToolbar;
146  if ( AUDIO_SpeakerOn )
147  {
148  TOOLBAR_ChangeButton( 0, ButtonMenuBmp, fDefaultAction ); // restore the 'config' button
149  TOOLBAR_ChangeButton( 1, ButtonLowSoundLSBmp, fLowSound ); // restore the 'sound --' button
150  TOOLBAR_ChangeButton( 2, ButtonHighSoundLSBmp, fHighSound ); // restore the 'sound ++' button
151  TOOLBAR_ChangeButton( 3, AUDIO_IsMute() ? ButtonMuteLSBmp : ButtonSoundLSBmp, fMuteSound ); // restore the 'mute' button
152  }
153  else
154  {
155  TOOLBAR_ChangeButton( 0, ButtonMenuBmp, fDefaultAction ); // restore the 'config' button
156  TOOLBAR_ChangeButton( 1, ButtonLowSoundHPBmp, fLowSound ); // restore the 'sound --' button
157  TOOLBAR_ChangeButton( 2, ButtonHighSoundHPBmp, fHighSound ); // restore the 'sound ++' button
158  TOOLBAR_ChangeButton( 3, AUDIO_IsMute() ? ButtonMuteHPBmp : ButtonSoundHPBmp, fMuteSound ); // restore the 'mute' button
159  }
160  }
161 
162  // At least 1 button redraw requested
163  if ( RedrawToolbarRequest & 0x0F )
164  {
165  // Redraw the buttons
166  for ( i = 0 ; i < CurrentToolbar->NbItems ; i++ )
167  {
168  if ( ( RedrawToolbarRequest >> i ) & 1 )
169  TOOLBAR_UnSelectButton( i );
170  }
171  }
172 
173  // Requested treated
174  RedrawToolbarRequest = 0;
175  } // End if( RedrawToolbarRequest )
176 
177  // Memorize state
178  OldOrientation = CurOrientation;
179 
180  // No touch, no button selected
181  ScreenButton = -1;
182 
183  } // End if TOUCHSCR_IsPressed
184 
185  // Button selection management
186  if ( OldButton != ScreenButton )
187  {
188  if ( OldButton != -1 )
189  TOOLBAR_UnSelectButton( OldButton );
190 
191  if ( ScreenButton != -1 )
192  TOOLBAR_SelectButton( ScreenButton );
193  }
194 
195 }
196 
197 
198 /*******************************************************************************
199 *
200 * TOOLBAR_UnselectButton
201 *
202 *******************************************************************************/
209 /******************************************************************************/
210 void TOOLBAR_UnSelectButton( u16 button )
211 {
212  TOOLBAR_Button( button, DEFAULT_BUTTON_BGND, DEFAULT_BUTTON_BGND, FALSE );
213 }
214 
215 /*******************************************************************************
216 *
217 * TOOLBAR_SelectButton
218 *
219 *******************************************************************************/
227 /******************************************************************************/
228 void TOOLBAR_SelectButton( u16 button )
229 {
230  s32 index;
231 
232  // Draw the button in selected mode
233  TOOLBAR_Button( button, DEFAULT_BUTTON_BGND, ACTIVE_BUTTON_BGND, TRUE ) ;
234 
235  // Beep
236  if ( BUZZER_GetMode() == BUZZER_OFF )
237  {
238  BUZZER_SetFrequency( 440 );
240  }
241 
242  // Launch the function corresponding to the absolute index of the item
243  index = ( button + CurrentToolbar->FirstDispItem ) % CurrentToolbar->NbItems;
244  if ( CurrentToolbar->Items[index].Fct_Manage )
245  {
246 #if POWER_MNGT
247  POWER_Reset_Time();
248 #endif
249  CurrentToolbar->Items[index].Fct_Manage();
250 #if POWER_MNGT
251  POWER_Set_Time();
252 #endif
253  }
254 }
255 
256 /*******************************************************************************
257 *
258 * TOOLBAR_Button
259 *
260 *******************************************************************************/
270 /******************************************************************************/
271 void TOOLBAR_Button( u16 button, u16 bgnd_color, u16 bgnd_color_sel, bool sel )
272 {
273  s32 index, deltaWidth, deltaHeight, Icon_Width, Icon_Height;
274  coord_t Save_Screen_Width, Save_Screen_Height, Save_LCD_Offset;
275 
276  // Find the absolute index of the item
277  index = ( button + CurrentToolbar->FirstDispItem ) % CurrentToolbar->NbItems;
278 
279  // Find the size of the icon in the header (only for BMP icons)
280  if ( ( CurrentToolbar->Items[index].icon[0] == 0x424D ) && ( CurrentToolbar->Items[index].icon[3] == 0 ) )
281  {
282  Icon_Width = ( CurrentToolbar->Items[index].icon[9] ) >> 8;
283  Icon_Height = ( CurrentToolbar->Items[index].icon[11] ) >> 8;
284  }
285  else
286  {
287  Icon_Width = ICON_WIDTH;
288  Icon_Height = ICON_HEIGHT;
289  }
290 
291  // Calculate the size difference for center icons
292  deltaWidth = ( BUTTON_WIDTH - Icon_Width ) / 2;
293  deltaHeight = ( BUTTON_HEIGHT - Icon_Height ) / 2;
294 
295  // Save screen current virtual values, if application with offset running
296  Save_Screen_Width = LCD_GetScreenWidth();
297  Save_Screen_Height = LCD_GetScreenHeight();
298  Save_LCD_Offset = LCD_Offset;
299 
300  // Restore real values for DRAW and LCD functions
301  Screen_Width = APP_SCREEN_WIDTH;
302  Screen_Height = APP_SCREEN_HEIGHT;
303  LCD_Offset = 0;
304 
305  switch ( LCD_GetScreenOrientation() )
306  {
307  case V12:
308  LCD_FillRect_Circle( BUTTON_WIDTH * button, APP_SCREEN_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT, RGB_WHITE );
309 
310  if ( sel )
311  DRAW_SetImageSel( CurrentToolbar->Items[index].icon, ( BUTTON_WIDTH * button ) + deltaWidth, APP_SCREEN_HEIGHT + deltaHeight, Icon_Height, Icon_Width,
312  bgnd_color, bgnd_color_sel );
313  else
314  DRAW_SetImage( CurrentToolbar->Items[index].icon, ( BUTTON_WIDTH * button ) + deltaWidth, APP_SCREEN_HEIGHT + deltaHeight, Icon_Height, Icon_Width );
315 
316  DRAW_Line_Circle( BUTTON_WIDTH * button, APP_SCREEN_HEIGHT, BUTTON_WIDTH * ( button + 1 ) - 1, APP_SCREEN_HEIGHT, RGB_BUTTON_SEPARATOR );
317 
318  if ( index != ( CurrentToolbar->NbItems - 1 ) )
319  DRAW_Line_Circle( BUTTON_WIDTH * ( button + 1 ) - 1, APP_SCREEN_HEIGHT, BUTTON_WIDTH * ( button + 1 ) - 1, APP_SCREEN_HEIGHT + BUTTON_HEIGHT - 1, RGB_BUTTON_SEPARATOR );
320  break;
321 
322  case V3:
323  LCD_FillRect_Circle( APP_SCREEN_WIDTH, BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ), BUTTON_HEIGHT, BUTTON_WIDTH, RGB_WHITE );
324 
325  if ( sel )
326  DRAW_SetImageSel( CurrentToolbar->Items[index].icon, APP_SCREEN_WIDTH + deltaHeight, BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ) + deltaWidth, Icon_Width, Icon_Height,
327  bgnd_color, bgnd_color_sel );
328  else
329  DRAW_SetImage( CurrentToolbar->Items[index].icon, APP_SCREEN_WIDTH + deltaHeight, BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ) + deltaWidth, Icon_Width, Icon_Height );
330 
331  DRAW_Line_Circle( APP_SCREEN_WIDTH, BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ), APP_SCREEN_WIDTH, BUTTON_WIDTH * ( CurrentToolbar->NbItems - button ), RGB_BUTTON_SEPARATOR );
332 
333  if ( index != ( CurrentToolbar->NbItems - 1 ) )
334  DRAW_Line_Circle( APP_SCREEN_WIDTH + BUTTON_HEIGHT, BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ), APP_SCREEN_WIDTH, BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ), RGB_BUTTON_SEPARATOR );
335  break;
336 
337  case V6:
338  LCD_FillRect_Circle( BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ), -BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT, RGB_WHITE );
339 
340  if ( sel )
341  DRAW_SetImageSel( CurrentToolbar->Items[index].icon, ( BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ) ) + deltaWidth, -BUTTON_HEIGHT + deltaHeight, Icon_Height, Icon_Width,
342  bgnd_color, bgnd_color_sel );
343  else
344  DRAW_SetImage( CurrentToolbar->Items[index].icon, ( BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ) ) + deltaWidth, -BUTTON_HEIGHT + deltaHeight, Icon_Height, Icon_Width );
345 
346  DRAW_Line_Circle( BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ), -1, BUTTON_WIDTH * ( CurrentToolbar->NbItems - button ), -1, RGB_BUTTON_SEPARATOR );
347 
348  if ( index != ( CurrentToolbar->NbItems - 1 ) )
349  DRAW_Line_Circle( BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ), -BUTTON_HEIGHT, BUTTON_WIDTH * ( CurrentToolbar->NbItems - button - 1 ), -1, RGB_BUTTON_SEPARATOR );
350  break;
351 
352  case V9:
353  LCD_FillRect_Circle( -BUTTON_HEIGHT, BUTTON_WIDTH * button, BUTTON_HEIGHT, BUTTON_WIDTH, RGB_WHITE );
354 
355  if ( sel )
356  DRAW_SetImageSel( CurrentToolbar->Items[index].icon, -BUTTON_HEIGHT + deltaHeight, ( BUTTON_WIDTH * button ) + deltaWidth, Icon_Height, Icon_Width,
357  bgnd_color, bgnd_color_sel );
358  else
359  DRAW_SetImage( CurrentToolbar->Items[index].icon, -BUTTON_HEIGHT + deltaHeight, ( BUTTON_WIDTH * button ) + deltaWidth, Icon_Height, Icon_Width );
360 
361  DRAW_Line_Circle( -1, BUTTON_WIDTH * button, -1, BUTTON_WIDTH * ( button + 1 ) - 1, RGB_BUTTON_SEPARATOR );
362 
363  if ( index != ( CurrentToolbar->NbItems - 1 ) )
364  DRAW_Line_Circle( -1, BUTTON_WIDTH * ( button + 1 ) - 1, -BUTTON_HEIGHT, BUTTON_WIDTH * ( button + 1 ) - 1, RGB_BUTTON_SEPARATOR );
365  break;
366 
367  default:
368  break;
369  }
370 
371  // Restore virtual values for DRAW and LCD functions
372  Screen_Width = Save_Screen_Width;
373  Screen_Height = Save_Screen_Height;
374  LCD_Offset = Save_LCD_Offset;
375 }
376 
377 /*******************************************************************************
378 *
379 * Default system functions
380 *
381 *******************************************************************************/
382 enum MENU_code fLowSound( void )
383 {
384  AUDIO_Dec_Volume( 2 );
385  return MENU_CONTINUE;
386 }
387 
388 enum MENU_code fHighSound( void )
389 {
390  AUDIO_Inc_Volume( 2 );
391  return MENU_CONTINUE;
392 }
393 
394 enum MENU_code fMuteSound( void )
395 {
396  AUDIO_MUTE_OnOff( AUDIO_IsMute() ? 0 : 1 );
397 
398  if ( AUDIO_SpeakerOn )
399  TOOLBAR_ChangeButton( 3, AUDIO_IsMute() ? ButtonMuteLSBmp : ButtonSoundLSBmp, fMuteSound ); // restore the 'mute' button
400  else
401  TOOLBAR_ChangeButton( 3, AUDIO_IsMute() ? ButtonMuteHPBmp : ButtonSoundHPBmp, fMuteSound ); // restore the 'mute' button
402 
403  return MENU_CONTINUE;
404 }
405 
406 enum MENU_code fDefaultAction( void )
407 {
408  index_t CurrentApplicationIndex = -1;
409 
410  if ( fInitDone == FALSE )
411  return MENU_CONTINUE;
412 
413  // Retrieve the current appli index
414  CurrentApplicationIndex = UTIL_ReadBackupRegister( BKP_SYS1 );
415 
416  // Try to launch the current appli
417  if ( APP_LaunchAppli( CurrentApplicationIndex ) == MENU_LEAVE )
418  {
419  return fConfig();
420  }
421  else
422  {
423  return MENU_CONTINUE;
424  }
425 }
426 
427 /*******************************************************************************
428 *
429 * TOOLBAR_RedrawToolbar
430 *
431 *******************************************************************************/
443 /******************************************************************************/
444 void TOOLBAR_RedrawToolbar( s32 Request )
445 {
446  RedrawToolbarRequest |= Request;
447 }
448 
450 
451 /*******************************************************************************
452 *
453 * TOOLBAR_Set
454 *
455 *******************************************************************************/
462 /******************************************************************************/
463 void TOOLBAR_Set( const tToolbar* NewToolbar )
464 {
465  CurrentToolbar = ( tToolbar* ) NewToolbar;
466  TOOLBAR_RedrawToolbar( TOOLBAR_REDRAW ); // To redraw...
467 }
468 
469 /*******************************************************************************
470 *
471 * TOOLBAR_SetDefaultToolbar
472 *
473 *******************************************************************************/
479 /******************************************************************************/
481 {
482  TOOLBAR_RedrawToolbar( TOOLBAR_DEFAULT );
483 }
484 
485 /*******************************************************************************
486 *
487 * TOOLBAR_ChangeButton
488 *
489 *******************************************************************************/
498 /******************************************************************************/
499 void TOOLBAR_ChangeButton( s32 button, const u16* newicon, enum MENU_code( *newfct )( void ) )
500 {
501  CurrentToolbar->Items[button].icon = newicon;
502  CurrentToolbar->Items[button].Fct_Manage = newfct;
503  TOOLBAR_RedrawToolbar( 1 << button );
504 }
505 
506 
507