CircleOS  1
list.c
Go to the documentation of this file.
1 /****************** COPYRIGHT (C) 2007-2013 KEOLABS S.A.S. ********************/
12 /******************************************************************************/
13 
14 /* Includes ------------------------------------------------------------------*/
15 #include "circle.h"
16 
18 
19 /* Private defines -----------------------------------------------------------*/
20 #define MAXLOCKMEMS 200
21 #define ANGLEPAUSE -100
22 #define MIN_ANGLE_FOR_SHIFT_UP (ANGLEPAUSE+CurrentAngleStart + 150)
23 #define MIN_ANGLE_FOR_SHIFT_DOWN (ANGLEPAUSE-CurrentAngleStart - 150)
24 #define TIME_FOR_TOUCH_LIST (2000)
25 #define LIST_DIVIDER 10
26 #define DELAY_BEFORE_DBCLK 80
27 
28 /* define for joystick management*/
29 #define JOY_MAXBTIME 20
30 #define JOY_HIGH_SPEED 5
31 #define JOY_LOW_SPEED 1
32 
33 #define FIRST_VISIBLE ( CurrentList->FirstDisplayItem - ( (nb_move<0) ? 1 : 0 ) )
34 
35 /* Extern variables ----------------------------------------------------------*/
36 extern color_t bmpTmp[LCD_DMA_SIZE]; /* 16 bits words : buffer to scroll display */
37 
38 /* Private variables ---------------------------------------------------------*/
39 //u16 CharMagniCoeff_List = 1;
40 s32 NewSelList = 0;
41 s32 DisplaySelectedItem = 0;
42 s32 CurOrientList = V12; /* Current orientation of the screen*/
43 s32 OldOrientList = -1;
44 bool move_old_Pressed = FALSE;
45 s32 nb_move = 0;
46 s32 Max_X_List, Min_X_List;
47 s32 Max_Y_List, Min_Y_List;
48 u16 ListCharWidth;
49 s32 ListCharHeight;
50 static s32 ListTimePressed = 0;
51 static divider_t ListCptDivider = 0;
52 
53 /* Rq: 3 bytes by pixel but transfer in 16 bits bus format*/
54 tList* CurrentList = 0;
55 
56 /* Variables for joystick*/
57 static enum JOYSTICK_state JoyPos;
58 static u16 JoyDelay = 0;
59 static u16 JoyInc = 1;
60 
61 
62 /* Private function prototypes -----------------------------------------------*/
63 void LIST_RefreshItem( index_t sel, bool isInverted );
64 s32 LIST_GetNewSelectedItem( void );
65 s32 LIST_DetectMove( void );
66 void StoreStringWithMode( u16* buffer, const u8* ptr, u8 len, u8 offset, u8 nblines );
67 void StoreChar( u16* buffer, u8* bmp, u8 nblines, u8 offset, color_t textColor, color_t bGndColor, mag_t CharMagniCoeff );
68 void SearchNewFirstItem( void );
69 void InitListDMA( void );
70 void LIST_LCD_RectRead( coord_t x, coord_t y, coord_t width, coord_t height );
71 void LIST_DRAW_SetImage( coord_t x, coord_t y, coord_t width, coord_t height );
72 void LIST_StoreString( u16* buffer, const u8* ptr, u8 len, u8 offset, u8 nblines, u16 textColor, u16 bGndColor, u16 CharMagniCoeff );
73 void LIST_StoreChar( u16* buffer, u8* bmp, u8 nblines, u8 offset, u16 textColor, u16 bGndColor, u16 CharMagniCoeff );
74 
75 /* Public function prototype -------------------------------------------------*/
76 
77 /* Private functions ---------------------------------------------------------*/
78 
79 extern u32 DoubleClickCounter_Menu;
80 extern color_t title_BGndColor;
81 extern color_t title_TextColor;
82 extern color_t selected_BGndColor;
83 extern color_t selected_TextColor;
84 extern s16 CurrentAngleStart;
85 
86 /*******************************************************************************
87 *
88 * SearchNewFirstItem
89 *
90 *******************************************************************************/
96 /******************************************************************************/
97 NODEBUG2 void SearchNewFirstItem( void )
98 {
99  s32 nb_char_move;
100 
101  /* Calculate the new first item*/
102  nb_char_move = ( nb_move * DeltaY ) / ListCharHeight;
103  if ( ( ( nb_char_move > 0 ) && ( CurrentList->FirstDisplayItem < ( CurrentList->NbItems - CurrentList->NbDisp ) ) )
104  || ( ( nb_char_move < 0 ) && ( CurrentList->FirstDisplayItem > 0 ) ) )
105  {
106  CurrentList->FirstDisplayItem += nb_char_move;
107  DisplaySelectedItem -= nb_char_move;
108  nb_move -= ( nb_char_move * ListCharHeight / DeltaY );
109  ListTimePressed = 0;
110  }
111 }
112 
113 /*******************************************************************************
114 *
115 * LIST_GetSelectedItem
116 *
117 *******************************************************************************/
125 /******************************************************************************/
126 #if TOUCHSCREEN_AVAIL
127 NODEBUG2 s32 LIST_GetNewSelectedItem( void )
128 {
129  u16 X, Y;
130  s32 SelectedItem = -1;
131  static bool fJoystickHasInput_old = 0;
132  bool fIsPressed = TOUCHSCR_IsPressed();
133  static s32 MemsLockCounter = MAXLOCKMEMS ;
134  bool fJoystickHasInput;
135 
136 
137  /* See if a hit on the touchscreen has been done*/
138  if ( fIsPressed )
139  {
140  /* Get the position*/
141  X = TOUCHSCR_GetPosX();
142  Y = TOUCHSCR_GetPosY();
143 
144  /* If touch is on the screen (not on toolbar)*/
145  if ( ( X < Screen_Width ) && ( Y < Screen_Height ) )
146  {
147  /* We capture the touch, even it's not into the list*/
148  if ( ( Y < Min_Y_List ) || ( Y > Max_Y_List ) )
149  Y = Max_Y_List;
150 
151  /* An item is just selected*/
152  SelectedItem = ( Max_Y_List - Y + ( nb_move * DeltaY ) ) / ListCharHeight ;
153  if ( SelectedItem >= CurrentList->NbDisp )
154  {
155  SelectedItem = CurrentList->NbDisp - ( nb_move ? 0 : 1 );
156  }
157  if ( SelectedItem < 0 )
158  {
159  SelectedItem = 0;
160  }
161  if ( SelectedItem != DisplaySelectedItem )
162  {
163  ListTimePressed = 0;
164  }
165  }
166  }
167  fJoystickHasInput = FALSE;
168 
169  /*-- Option management of the pointer by the joystick */
170  if ( JoystickAsInput && ( SelectedItem == -1 ) )
171  {
172  JoyPos = JOYSTICK_GetState();
173 
174  if ( JoyPos != JOYSTICK_RELEASED )
175  {
176  fJoystickHasInput = TRUE;
177  JoyDelay++;
178  }
179  else
180  {
181  JoyDelay = 0;
182  }
183 
184  if ( ( fJoystickHasInput_old == 0 ) || ( JoyDelay >= WEIGHTED_TIME( 3 * JOY_MAXBTIME ) ) )
185  {
186  JoyDelay = 0;
187 
188  if ( ( JoyPos == JOYSTICK_DOWN ) || ( JoyPos == JOYSTICK_LEFT_DOWN ) || ( JoyPos == JOYSTICK_RIGHT_DOWN ) )
189  {
190 
191  if ( ( DisplaySelectedItem < CurrentList->NbDisp ) && ( CurrentList->SelectedItem < CurrentList->NbItems - 1 ) )
192  SelectedItem = DisplaySelectedItem + 1;
193  }
194 
195  if ( ( JoyPos == JOYSTICK_UP ) || ( JoyPos == JOYSTICK_LEFT_UP ) || ( JoyPos == JOYSTICK_RIGHT_UP ) )
196  {
197  if ( DisplaySelectedItem > 0 )
198  SelectedItem = DisplaySelectedItem - 1;
199 
200  }
201 
202  }
203  fJoystickHasInput_old = fJoystickHasInput;
204  }
205 
206  /*-- Option management of the pointer by the mems */
207  if ( SelectedItem != -1 )
208  {
209  MemsLockCounter = WEIGHTED_TIME( 2 * MAXLOCKMEMS );
210  }
211 
212  if ( MemsLockCounter )
213  {
214  MemsLockCounter--;
215  }
216  else
217  {
218  if ( MEMSASINPUT && ( SelectedItem == -1 ) && ( JoyPos == JOYSTICK_RELEASED ) && ( fIsPressed == 0 ) )
219  {
220 
221  if ( ( DisplaySelectedItem < CurrentList->NbDisp ) && ( CurrentList->SelectedItem < CurrentList->NbItems - 1 )
222  && ( MEMS_Info.RELATIVE_Y < MIN_ANGLE_FOR_SHIFT_DOWN ) )
223  {
224  SelectedItem = DisplaySelectedItem + 1;
225  }
226  if ( ( DisplaySelectedItem > 0 ) && ( MEMS_Info.RELATIVE_Y > MIN_ANGLE_FOR_SHIFT_UP ) )
227  {
228  SelectedItem = DisplaySelectedItem - 1;
229  }
230  if ( SelectedItem != -1 )
231  {
232  MemsLockCounter = WEIGHTED_TIME( MAXLOCKMEMS / 3 );
233  }
234  }
235  }
236  return SelectedItem;
237 }
238 #endif //TOUCHSCREEN_AVAIL
239 
240 
241 /*******************************************************************************
242 *
243 * LIST_DetectMove
244 *
245 *******************************************************************************/
255 /******************************************************************************/
256 #if TOUCHSCREEN_AVAIL
257 NODEBUG2 s32 LIST_DetectMove( void )
258 {
259  static s32 move_old_Y = 0;
260  s32 dir = 0;
261  s32 move_cur_Y, X;
262  static s32 MemsLockCounter = MAXLOCKMEMS ;
263  bool fJoystickHasInput;
264 
265 
266  /* See if a hit on the touchscreen is always done*/
267  if ( TOUCHSCR_IsPressed() )
268  {
269  /* Get the new position*/
270  X = TOUCHSCR_GetPosX();
271  move_cur_Y = TOUCHSCR_GetPosY();
272 
273  if ( ( X > Min_X_List ) && ( X < Max_X_List ) )
274  {
275  if ( move_old_Pressed == FALSE )
276  {
277  move_old_Y = move_cur_Y;
278  }
279  else
280  {
281  dir = ( move_cur_Y - move_old_Y ) / DeltaY;
282  if ( dir >= 1 )
283  {
284  dir = 1;
285  move_old_Y += DeltaY;
286  }
287  else if ( dir <= -1 )
288  {
289  dir = -1;
290  move_old_Y -= DeltaY;
291  }
292  }
293  move_old_Pressed = TRUE;
294  }
295  }
296  else
297  {
298  /* Touch release*/
299  move_old_Pressed = FALSE;
300  dir = 0;
301  }
302 
303  /*-- Option management of the pointer by the joystick */
304  fJoystickHasInput = FALSE;
305  if ( JoystickAsInput )
306  {
307  JoyPos = JOYSTICK_GetState();
308  if ( ( JoyPos == JOYSTICK_UP ) || ( JoyPos == JOYSTICK_LEFT_UP ) || ( JoyPos == JOYSTICK_RIGHT_UP ) )
309  {
310  if ( DisplaySelectedItem <= 0 )
311  dir = - JoyInc ;
312  }
313  if ( ( JoyPos == JOYSTICK_DOWN ) || ( JoyPos == JOYSTICK_LEFT_DOWN ) || ( JoyPos == JOYSTICK_RIGHT_DOWN ) )
314  {
315  if ( DisplaySelectedItem >= CurrentList->NbDisp )
316  dir = + JoyInc ;
317  }
318 
319 
320  if ( JoyPos != JOYSTICK_RELEASED )
321  {
322  fJoystickHasInput = TRUE;
323  JoyDelay++;
324  }
325  else
326  {
327  JoyDelay = 0;
328  }
329 
330  if ( JoyDelay >= JOY_MAXBTIME )
331  JoyInc = JOY_HIGH_SPEED;
332  else
333  JoyInc = JOY_LOW_SPEED;
334  }
335 
336  /*-- Option management of the pointer by the mems */
337  if ( dir )
338  {
339  MemsLockCounter = WEIGHTED_TIME( MAXLOCKMEMS );
340  }
341 
342  if ( MemsLockCounter )
343  {
344  MemsLockCounter--;
345  }
346  else
347  {
348  if ( MEMSASINPUT && ( dir == 0 ) && ( JoyPos == JOYSTICK_RELEASED ) && ( move_old_Pressed == 0 ) )
349  {
350  extern s16 CurrentAngleStart ;
351 
352  if ( ( ( DisplaySelectedItem >= CurrentList->NbDisp ) && ( MEMS_Info.RELATIVE_Y < MIN_ANGLE_FOR_SHIFT_DOWN ) )
353  || ( ( DisplaySelectedItem <= 0 ) && ( MEMS_Info.RELATIVE_Y > MIN_ANGLE_FOR_SHIFT_UP ) ) )
354  {
355  dir = -MEMS_Info.RELATIVE_Y ;
356  }
357  }
358  }
359  return dir;
360 }
361 #endif //TOUCHSCREEN_AVAIL
362 
363 /*******************************************************************************
364 *
365 * LIST_RefreshItem
366 *
367 *******************************************************************************/
375 /******************************************************************************/
376 NODEBUG2 void LIST_RefreshItem( index_t sel, bool isInverted )
377 {
378  s32 lg = CurrentList->LgMax;
379  s32 save_BGndColor = DRAW_GetBGndColor();
380  s32 save_TextColor = DRAW_GetTextColor();
381  s32 offs;
382 
383  /* Calculate the index into the original list*/
384  s32 index = sel + CurrentList->FirstDisplayItem; /*FIRST_VISIBLE ; //FL090103 */
385 
386  /* If not title, do not draw the title*/
387  if ( ( !CurrentList->fdispTitle ) && ( sel == -1 ) )
388  return;
389 
390  /* Set menu DRAW params*/
391  LCD_ChangeFont( Menu_Font );
392  ListCharWidth = Char_Width * DRAW_GetCharMagniCoeff();
393  ListCharHeight = Char_Height * DRAW_GetCharMagniCoeff();
394  DRAW_SetBGndColor( ( sel == -1 ) ? title_BGndColor : BGndColor_Menu );
395  DRAW_SetTextColor( ( sel == -1 ) ? title_TextColor : TextColor_Menu );
396 
397  offs = ( sel == -1 ) ? 0 : ( nb_move * DeltaY );
398 
399  /* Standard display*/
400  if ( !isInverted )
401  {
402  if ( sel != -1 ) /* Title is always complete*/
403  LCD_DrawCharSetFilter( Min_X_List, Max_X_List, Min_Y_List, Max_Y_List );
404 
405  DRAW_DisplayString( Min_X_List,
406  CurrentList->YPos - ( ( sel + 2 ) * ListCharHeight ) - ListCharHeight / 4 + offs,
407  ( sel == -1 ) ? ( char* )CurrentList->Title : ( char* )( CurrentList->Items[index].Text ),
408  lg );
409 
410  if ( sel != -1 ) /* Title is always complete*/
411  {
412  // Remove filter
413  LCD_DrawCharSetFilter( 0, Screen_Width, 0, Screen_Height );
414  }
415  }
416  else
417  {
418  /* Inverted display.*/
419  DRAW_SetBGndColor( ( sel == -1 ) ? title_BGndColor : selected_BGndColor );
420  DRAW_SetTextColor( ( sel == -1 ) ? title_TextColor : selected_TextColor );
421  if ( sel != -1 ) /* Title is always complete*/
422  LCD_DrawCharSetFilter( Min_X_List, Max_X_List, Min_Y_List, Max_Y_List );
423 
424  DRAW_DisplayString( Min_X_List,
425  CurrentList->YPos - ( ( sel + 2 ) * ListCharHeight ) - ListCharHeight / 4 + offs,
426  ( sel == -1 ) ? ( char* ) CurrentList->Title : ( char* )( CurrentList->Items[index].Text ),
427  lg );
428 
429  if ( sel != -1 ) /*Title is always complete*/
430  {
431  // Remove filter
432  LCD_DrawCharSetFilter( 0, Screen_Width, 0, Screen_Height );
433  }
434  }
435 
436  /* Restore previous DRAW params.*/
437  DRAW_SetBGndColor( save_BGndColor );
438  DRAW_SetTextColor( save_TextColor );
439 }
440 
441 
442 /*******************************************************************************
443 *
444 * LIST_StoreString
445 *
446 *******************************************************************************/
460 /******************************************************************************/
461 NODEBUG2 void LIST_StoreString( u16* buffer, const u8* ptr, u8 len, u8 offset, u8 nblines, u16 textColor, u16 bGndColor, u16 charMagniCoeff )
462 {
463  u8 c, car = 0, Char_By_Line;
464 
465  Char_By_Line = Screen_Width / ( Char_Width * charMagniCoeff ); /* Calculate the maximum characters by line */
466 
467  /* Up to x characters*/
468  if ( len > Char_By_Line )
469  len = Char_By_Line;
470 
471 
472  /* Store each character */
473  for ( car = 0 ; car < len ; car++ )
474  {
475  c = *ptr;
476  if ( c )
477  {
478  ptr++; /* Point to the next character */
479  }
480  else
481  {
482  c = ' '; /* fill with space when len exceeds strlen(ptr) */
483  }
484 
485  /* Store one character */
486  /* LIST_StoreChar((u16*) buffer, (u8*)&AsciiDotsTable[((c-32) * 14)], nblines, offset, textColor, bGndColor, charMagniCoeff ); // YRT20090304*/
487  LIST_StoreChar( ( u16* ) buffer, ( u8* )&CurrentFont[( ( c - 32 ) * ( 2 * Char_Width ) )], nblines / charMagniCoeff, offset, textColor, bGndColor, charMagniCoeff );
488 
489  /* next buffer word*/
490  buffer += ( nblines * Char_Width * charMagniCoeff ); /* height (up to 14 pixels) * width (7 pixels)*/
491  }
492 }
493 
494 
495 /*******************************************************************************
496 *
497 * LIST_StoreChar
498 *
499 *******************************************************************************/
516 /******************************************************************************/
517 NODEBUG2 void LIST_StoreChar( u16* buffer, u8* bmp, u8 nblines, u8 offset, u16 textColor, u16 bGndColor, u16 charMagniCoeff )
518 {
519  u8 i = 0;
520  u16 mask;
521  u16 k1, k2, k3, k4;
522  u16 matrix;
523 
524  /* First line to store*/
525  k3 = 0x8000;
526  for ( i = 0 ; i < offset; i++ )
527  k3 >>= 1;
528 
529  /* End line to store*/
530  k4 = k3;
531  for ( i = 0 ; i < nblines; i++ )
532  k4 >>= 1;
533 
534  /* For each pixel column of the character*/
535  for ( i = 0; i < Char_Width ; i++ )
536  {
537  /* Concatenation of even and odd lines of the matrix*/
538  matrix = ( bmp[2 * i] << 8 ) | bmp[2 * i + 1];
539 
540  for ( k1 = 0; k1 < charMagniCoeff; k1++ )
541  {
542  /* Scan all bits from bottom to top of character*/
543  for ( mask = k3; mask > k4 ; mask >>= 1 )
544  {
545  for ( k2 = 0; k2 < charMagniCoeff; k2++ )
546  {
547  *( buffer++ ) = ( ( matrix & mask ) ? textColor : bGndColor ) ;
548  }
549  }
550  }
551  }
552 }
553 
555 
556 /* Public functions ----------------------------------------------------------*/
557 
558 /*******************************************************************************
559 *
560 * LIST_Set
561 *
562 *******************************************************************************/
575 /******************************************************************************/
576 void LIST_Set( tList* lptr, coord_t posX, coord_t posY, bool center )
577 {
578  s32 i, lg;
579  s32 lg_max = 0;
580  s32 XSize;
581  s32 YSize;
582 
583  s32 save_BGndColor = DRAW_GetBGndColor();
584  s32 save_TextColor = DRAW_GetTextColor();
585 
586  /* Initialize colors*/
587  DRAW_SetBGndColor( BGndColor_Menu );
588  DRAW_SetTextColor( TextColor_Menu );
589 
590  /* Lock RotateScreen*/
591  /* PreviousRotateScreen = LCD_GetRotateScreen(); // YRT20090304*/
592  /* LCD_SetRotateScreen(0); */
593  POINTER_SetMode( POINTER_OFF ); /* YRT20090325 fix bug square on the list*/
594 
595  /* Affect the current list to the newlist */
596  CurrentList = lptr;
597 
598  /* Set variables used for filtering/stability.*/
599  DisplaySelectedItem = 0;
600  CurrentList->SelectedItem = 0;
601  CurrentList->FirstDisplayItem = 0; /*first visible item*/
602  nb_move = 0;
603  ListTimePressed = 0;
604 
605 
606  if ( CurrentList->NbItems < CurrentList->NbDisp )
607  CurrentList->NbDisp = CurrentList->NbItems;
608 
609  /* Calculate the max length of the lines*/
610  for ( i = 0; i < CurrentList->NbItems; i++ )
611  {
612  lg = my_strlen( ( u8* )CurrentList->Items[i].Text );
613 
614  if ( lg > lg_max )
615  lg_max = lg;
616  }
617  if ( CurrentList->fdispTitle )
618  {
619  lg = my_strlen( ( u8* )CurrentList->Title );
620 
621  if ( lg > lg_max )
622  {
623  lg_max = lg;
624  }
625  }
626 
627  CurrentList->LgMax = lg_max;
628 
629  /* Calculate the size of the list and it's position*/
630  LCD_ChangeFont( Menu_Font );
631  ListCharWidth = Char_Width * DRAW_GetCharMagniCoeff();
632  ListCharHeight = Char_Height * DRAW_GetCharMagniCoeff();
633 
634  CurrentList->XSize = ( lg_max + 1 ) * ListCharWidth;
635  CurrentList->YSize = ( ( CurrentList->NbDisp + 1 ) * ListCharHeight ) + ListCharHeight / 2;
636  if ( center )
637  {
638  CurrentList->XPos = ( Screen_Width - CurrentList->XSize ) / 2;
639  CurrentList->YPos = ( ( Screen_Height - CurrentList->YSize ) / 2 ) + CurrentList->YSize;
640  }
641  else
642  {
643  CurrentList->XPos = posX;
644  CurrentList->YPos = posY;
645  }
646 
647  /* Calculate the active zone of the list (the title is excluded)*/
648  Max_Y_List = CurrentList->YPos - ListCharHeight - ListCharHeight / 4;
649  Min_Y_List = Max_Y_List - CurrentList->NbDisp * ListCharHeight ;
650  XSize = ( lg_max ) * ListCharWidth;
651  YSize = ( Max_Y_List - Min_Y_List ) + ( ListCharHeight );
652  Min_X_List = ( CurrentList->XPos ) + ( ListCharWidth / 2 );
653  Max_X_List = Min_X_List + XSize;
654 
655  /* Clear the screen*/
656  LCD_FillRect_Circle( CurrentList->XPos, CurrentList->YPos - CurrentList->YSize, CurrentList->XSize, CurrentList->YSize, BGndColor_Menu );
657  LCD_DrawRect( CurrentList->XPos, CurrentList->YPos - CurrentList->YSize, CurrentList->XSize, CurrentList->YSize, 0 );
658 
659  /* Display title.*/
660  if ( CurrentList->fdispTitle )
661  {
662  LIST_RefreshItem( -1, NORMAL_TEXT );
663  }
664 
665  /* See if empty list*/
666  if ( CurrentList->NbItems != 0 )
667  {
668  /* Display the list of items.*/
669  for ( i = 0 ; i < CurrentList->NbDisp ; i++ )
670  {
671  LIST_RefreshItem( i, ( i == DisplaySelectedItem ) ? INVERTED_TEXT : NORMAL_TEXT );
672  }
673  }
674 
675  /* No time display while a menu is active.*/
676  fDisplayTime = 0;
677 
678  /* BUTTON_SetMode( BUTTON_ONOFF_FORMAIN ); // YRT20080204*/
679  /* Rq : the mode is ONOFF if called by an application*/
680  /* but it's forced to FORMAIN if called by menu handler*/
682  DoubleClickCounter_Menu = MEMS_Info.DoubleClick;
683 
684  /* Initialize DMA for optimize screen scroll*/
685  InitListDMA();
686 
687  /* Restore previous DRAW params.*/
688  DRAW_SetBGndColor( save_BGndColor );
689  DRAW_SetTextColor( save_TextColor );
690 
691  ListCptDivider = 0;
692 
693 }
694 
695 /*******************************************************************************
696 *
697 * LIST_Manager
698 *
699 *******************************************************************************/
707 /******************************************************************************/
708 s32 LIST_Manager( void )
709 {
710 #if TOUCHSCREEN_AVAIL
711  s32 i;
712  const u8* ptr;
713  u16 x, y, width;
714  s32 offset, move = 0;
715  u16 txtcolor;
716  u16 bgdcolor;
717 
718  /* No list to manage, exit*/
719  if ( CurrentList == 0 )
720  return -1;
721 
722  ListCptDivider++;
723 
724  x = Min_X_List;
725  width = Max_X_List - Min_X_List;
726  ListCharWidth = Char_Width * DRAW_GetCharMagniCoeff();
727  ListCharHeight = Char_Height * DRAW_GetCharMagniCoeff();
728  TOUCHSCR_SetSensibility( 3000 );
729 
730  /* Determine the new selection if any*/
731  NewSelList = move_old_Pressed ? DisplaySelectedItem : LIST_GetNewSelectedItem();
732 
733  if ( ( NewSelList != -1 ) && ( NewSelList != DisplaySelectedItem ) )
734  {
735  /* First refresh CurrentMenu->SelectItem (the old selected item)*/
736  if ( ( DisplaySelectedItem >= 0 ) && ( DisplaySelectedItem <= CurrentList->NbDisp ) )
737  {
738  LIST_RefreshItem( DisplaySelectedItem, NORMAL_TEXT );
739  }
740 
741  /* Update the selected item*/
742  DisplaySelectedItem = NewSelList;
743  /* CurrentList->SelectedItem = DisplaySelectedItem + FIRST_VISIBLE ; //FL090103 +CurrentList->FirstDisplayItem ; // YRT20080226*/
744  CurrentList->SelectedItem = DisplaySelectedItem + CurrentList->FirstDisplayItem ;
745 
746  /* Then select the new selected item*/
747  if ( ( DisplaySelectedItem >= 0 ) && ( DisplaySelectedItem <= CurrentList->NbDisp ) )
748  {
749  LIST_RefreshItem( DisplaySelectedItem, INVERTED_TEXT );
750  }
751  }
752 
753  /* See if the orientation of the screen has changed*/
754  CurOrientList = LCD_GetScreenOrientation();
755 
756  /* Redraw items if needed (if menu called, the redraw is made by the LIST_Set() call)*/
757  if ( ( CurOrientList != OldOrientList )
758  && ( CurrentMenu == 0 ) ) /* YRT200903004*/
759  {
760  LCD_FillRect_Circle( CurrentList->XPos, CurrentList->YPos - CurrentList->YSize, CurrentList->XSize, CurrentList->YSize, BGndColor_Menu );
761  LCD_DrawRect( CurrentList->XPos, CurrentList->YPos - CurrentList->YSize, CurrentList->XSize, CurrentList->YSize, RGB_BLACK );
762 
763  /* Redraw the title*/
764  LIST_RefreshItem( -1, NORMAL_TEXT );
765 
766  /* Redraw the list of items.*/
767  for ( i = 0 ; i < CurrentList->NbDisp ; i++ )
768  {
769  LIST_RefreshItem( i, ( i == DisplaySelectedItem ) ? INVERTED_TEXT : NORMAL_TEXT );
770  }
771  }
772  OldOrientList = CurOrientList;
773 
774  /* See if scroll request*/
775  move = LIST_DetectMove();
776 
777  if ( move != 0 )
778  {
779  /* Redraw the list of items.*/
780  if ( move < 0 )
781  {
782  /* Move to the bottom of the screen => to the top of the list*/
783  if ( CurrentList->FirstDisplayItem > 0 )
784  {
785  /* Scroll the screen each DeltaY lines to the bottom*/
786  for ( y = Min_Y_List + DeltaY; y < Max_Y_List ; y += DeltaY )
787  {
788  LIST_LCD_RectRead( x, y, width, DeltaY );
789  LIST_DRAW_SetImage( x, y - DeltaY, width, DeltaY );
790  }
791 
792  nb_move--;
793 
794  /* Store new string into the top cache and show it*/
795  if ( CurrentList->FirstDisplayItem > 0 )
796  {
797  ptr = ( u8* )( CurrentList->Items[FIRST_VISIBLE/*CurrentList->FirstDisplayItem - 1*/].Text );
798  offset = ( ( nb_move + 1 ) * DeltaY / DRAW_GetCharMagniCoeff() ) % Char_Height;
799  offset *= -1;
800  while ( offset < 0 )
801  {
802  offset += Char_Height;
803  }
804  txtcolor = ( ( DisplaySelectedItem + ( ( nb_move < 0 ) ? 1 : 0 ) ) == 0 ) ? selected_TextColor : TextColor_Menu ;
805  bgdcolor = ( ( DisplaySelectedItem + ( ( nb_move < 0 ) ? 1 : 0 ) ) == 0 ) ? selected_BGndColor : BGndColor_Menu ;
806  LIST_StoreString( ( u16* )&bmpTmp, ptr, CurrentList->LgMax + 1, offset, DeltaY, txtcolor, bgdcolor, DRAW_GetCharMagniCoeff() );
807  /* Load top cache into the screen*/
808  DRAW_SetImage( ( const color_t* ) &bmpTmp, x, Max_Y_List - DeltaY, width, DeltaY );
809  }
810  }
811  }
812  else
813  {
814  /* To the top of the screen => to the bottom of the list*/
815  if ( CurrentList->FirstDisplayItem < ( CurrentList->NbItems - CurrentList->NbDisp ) )
816  {
817  /* Scroll the screen each DeltaY lignes to the top*/
818  for ( y = Max_Y_List - ( 2 * DeltaY ) ; y >= Min_Y_List ; y -= DeltaY )
819  {
820  LIST_LCD_RectRead( x, y, width, DeltaY );
821  LIST_DRAW_SetImage( x, y + DeltaY, width, DeltaY );
822  }
823  nb_move++;
824 
825  /* Store new string into the bottom cache and show it*/
826  if ( ( CurrentList->FirstDisplayItem + CurrentList->NbDisp ) < CurrentList->NbItems )
827  {
828  ptr = ( u8* )( CurrentList->Items[FIRST_VISIBLE + CurrentList->NbDisp].Text );
829  offset = ( Char_Height - ( nb_move * DeltaY / DRAW_GetCharMagniCoeff() ) ) % Char_Height;
830  if ( offset < 0 )
831  offset = Char_Height - offset;
832 
833  txtcolor = ( DisplaySelectedItem == ( CurrentList->NbDisp - ( ( nb_move <= 0 ) ? 1 : 0 ) ) ) ? selected_TextColor : TextColor_Menu ;
834  bgdcolor = ( DisplaySelectedItem == ( CurrentList->NbDisp - ( ( nb_move <= 0 ) ? 1 : 0 ) ) ) ? selected_BGndColor : BGndColor_Menu ;
835 
836  LIST_StoreString( ( u16* )&bmpTmp, ptr, CurrentList->LgMax + 1, offset, DeltaY, txtcolor, bgdcolor, DRAW_GetCharMagniCoeff() );
837 
838  /* Load bottom cache into the screen*/
839  DRAW_SetImage( ( const color_t* ) &bmpTmp, x, Min_Y_List, width, DeltaY );
840  }
841  }
842  } /* else move< 0*/
843  SearchNewFirstItem();
844 
845  } /* end if move!=0*/
846 
847 #if 0 /* For debugging purpose, display the state of the list in the title bar*/
848  static u8 buffer[15] = "F10 M-XX S02";
849  UTIL_uint2str( buffer + 1, FIRST_VISIBLE /* CurrentList->FirstDisplayItem */ + 1, 2, 1 );
850  buffer[3] = ' ';
851 
852  if ( nb_move < 0 )
853  {
854  buffer[5] = '-';
855  UTIL_uint2str( buffer + 6, -nb_move, 2, 1 );
856  }
857  else
858  {
859  buffer[5] = '+';
860  UTIL_uint2str( buffer + 6, +nb_move, 2, 1 );
861  }
862  buffer[8] = ' ';
863  /* UTIL_uint2str( buffer+10, DisplaySelectedItem + CurrentList->FirstDisplayItem +1, 2, 1 ); // YRT090107*/
864  UTIL_uint2str( buffer + 10, CurrentList->SelectedItem, 2, 1 );
865  CurrentList->Title = buffer;
866  LIST_RefreshItem( -1, NORMAL_TEXT );
867 #endif
868 
869  /* Inhibition of the mems doubleclick */
870  if ( ListCptDivider < DELAY_BEFORE_DBCLK )
871  DoubleClickCounter_Menu = MEMS_Info.DoubleClick;
872 
873  /* Check item selection validation */
874  if ( ( BUTTON_GetState() == BUTTON_PUSHED_FORMAIN ) /* YRT20090226*/
875  || ( BUTTON_GetState() == BUTTON_PUSHED )
876  || ( DoubleClickCounter_Menu != MEMS_Info.DoubleClick )
877  || ( ( ( ListTimePressed * freqTIM2[SPEED_MEDIUM] ) / freqTIM2[CurrentSpeed] ) > TIME_FOR_TOUCH_LIST ) )
878  {
880  DoubleClickCounter_Menu = MEMS_Info.DoubleClick;
881 
882  return CurrentList->SelectedItem;
883  }
884 
885  /* Increment duration of the screen pressed state*/
886 // if ( !TOUCHSCR_IsPressed() ) //YRT130704
887  if ( !TOUCHSCR_IsPressed() || !TchscrAsInput)
888  {
889  ListTimePressed = 0;
890  }
891  else
892  {
893  ListTimePressed += LIST_DIVIDER;
894  }
895 
896  return -1;
897 #endif
898 }
899