Choco OS  V.0.16.9.0
Join to the chocolate world
oc_tgui.c
Go to the documentation of this file.
1 
27 #include <oc_tgui.h>
28 #include <oc_stdlib.h>
29 #include <oc_null.h>
30 #include <oc_object.h>
31 #include <oc_stdio.h>
32 #include <oc_kprint.h>
33 #include <string.h>
34 #include <oc_math.h>
35 #include <ctype.h>
36 #include <oc_struct.h>
37 #include <oc_string.h>
38 #include <oc_debug.h>
39 #include <oc_process.h>
40 #include <oc_string.h>
41 
47 #define _________________________________________TYPES_SECTION______________________________________________________________________________
48 
50 {
51  oC_ObjectControl_t ObjectControl;
52  oC_TGUI_Position_t StartPosition;
53  oC_TGUI_Column_t Width;
55  uint32_t MaximumValue;
56  uint32_t CurrentValue;
57 };
58 
59 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
60 
66 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
67 
68 static uint32_t GetIndexFromPosition ( oC_TGUI_Position_t TopLeft , oC_TGUI_Position_t BottomRight , oC_TGUI_Position_t Position , const char * Buffer );
69 static oC_TGUI_Position_t GetPositionFromIndex ( oC_TGUI_Position_t TopLeft , oC_TGUI_Position_t BottomRight , const char * Buffer , uint32_t Index );
70 static oC_TGUI_ActiveObject_t* GetActiveObjectOnRight ( oC_TGUI_ActiveObject_t * Array , uint32_t Size , oC_TGUI_ActiveObject_t * ActiveObject );
71 static oC_TGUI_ActiveObject_t* GetActiveObjectOnLeft ( oC_TGUI_ActiveObject_t * Array , uint32_t Size , oC_TGUI_ActiveObject_t * ActiveObject );
72 static oC_TGUI_ActiveObject_t* GetActiveObjectOnDown ( oC_TGUI_ActiveObject_t * Array , uint32_t Size , oC_TGUI_ActiveObject_t * OldObject );
73 static oC_TGUI_ActiveObject_t* GetActiveObjectOnUp ( oC_TGUI_ActiveObject_t * Array , uint32_t Size , oC_TGUI_ActiveObject_t * OldObject );
74 
75 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
76 
77 
83 #define _________________________________________FUNCTIONS_SECTION__________________________________________________________________________
84 
85 //==========================================================================================================================================
86 //==========================================================================================================================================
87 oC_TGUI_Color_t oC_TGUI_GetColorFromName( const char * Name )
88 {
89  oC_TGUI_Color_t color = 0;
90  int nameLength = strlen(Name);
91 
92  oC_ARRAY_FOREACH_IN_ARRAY(oC_TGUI_Colors , colorData)
93  {
94  int tempLength = strlen(colorData->Name);
95  bool theSame = tempLength > 0 && nameLength > 0;
96 
97  for(int i = 0; i < tempLength && i < nameLength && theSame; i++)
98  {
99  if(isalnum((int)colorData->Name[i]) && isalnum((int)Name[i]))
100  {
101  if(tolower( (int)colorData->Name[i]) != tolower((int)Name[i]))
102  {
103  theSame = false;
104  break;
105  }
106  }
107  else
108  {
109  break;
110  }
111  }
112  }
113 
114  return color;
115 }
116 
117 //==========================================================================================================================================
118 //==========================================================================================================================================
119 const char * oC_TGUI_GetNameFromColor( oC_TGUI_Color_t Color )
120 {
121  const char * name = "unknown";
122 
123  oC_ARRAY_FOREACH_IN_ARRAY(oC_TGUI_Colors , colorData)
124  {
125  if(colorData->Color == Color)
126  {
127  name = colorData->Name;
128  break;
129  }
130  }
131 
132  return name;
133 }
134 
135 //==========================================================================================================================================
136 //==========================================================================================================================================
137 bool oC_TGUI_ClearScreen( void )
138 {
139  return printf(oC_VT100_ERASE_SCREEN) == 0;
140 }
141 
142 //==========================================================================================================================================
151 //==========================================================================================================================================
153 {
154  return printf(oC_VT100_RESET_DEVICE) == 0;
155 }
156 //==========================================================================================================================================
157 //==========================================================================================================================================
158 bool oC_TGUI_SetCursorPosition( oC_TGUI_Position_t CursorPosition )
159 {
160  return oC_TGUI_Position_IsCorrect(CursorPosition) && printf(oC_VT100_SET_CURSOR_HOME("%d","%d"),CursorPosition.Line,CursorPosition.Column) == 0;
161 }
162 
163 //==========================================================================================================================================
164 //==========================================================================================================================================
165 bool oC_TGUI_ReadCursorPosition( oC_TGUI_Position_t * outCursorPosition )
166 {
167  bool success = false;
168 
169  if(isram(outCursorPosition))
170  {
171  success = true;
172  printf(oC_VT100_SEQ_QUERY_CURSOR_POSITION);
173  scanf(oC_VT100_SEQ_REPORT_CURSOR_POSITION("%d","%d") , (int*)&outCursorPosition->Line , (int*)&outCursorPosition->Column);
174  }
175 
176  return success;
177 }
178 
179 //==========================================================================================================================================
180 //==========================================================================================================================================
181 bool oC_TGUI_SetBackgroundColor( oC_TGUI_Color_t Color )
182 {
183  bool success = false;
184  uint16_t valueToPrint = 10;
185 
186  if(oC_TGUI_Color_IsCorrect(Color))
187  {
188  valueToPrint += Color;
189  success = printf("\033[%dm" , valueToPrint) == 0;
190  }
191 
192  return success;
193 }
194 
195 //==========================================================================================================================================
196 //==========================================================================================================================================
197 bool oC_TGUI_SetForegroundColor( oC_TGUI_Color_t Color )
198 {
199  bool success = false;
200  uint16_t valueToPrint = 0;
201 
202  if(oC_TGUI_Color_IsCorrect(Color))
203  {
204 
205  valueToPrint += Color;
206  success = printf("\033[%dm" , valueToPrint) == 0;
207  }
208 
209  return success;
210 }
211 
212 //==========================================================================================================================================
213 //==========================================================================================================================================
214 bool oC_TGUI_SetTextStyle( oC_TGUI_TextStyle_t TextStyle )
215 {
216  return printf(
217  "%s%s%s%s%s%s" ,
218  (TextStyle & oC_TGUI_TextStyle_Bold ) ? "\033[1m" : "\033[21m" ,
219  (TextStyle & oC_TGUI_TextStyle_Dim ) ? "\033[2m" : "\033[22m" ,
220  (TextStyle & oC_TGUI_TextStyle_Underline ) ? "\033[4m" : "\033[24m" ,
221  (TextStyle & oC_TGUI_TextStyle_Blink ) ? "\033[5m" : "\033[25m" ,
222  (TextStyle & oC_TGUI_TextStyle_Inverted ) ? "\033[7m" : "\033[27m" ,
223  (TextStyle & oC_TGUI_TextStyle_Hidden ) ? "\033[8m" : "\033[28m"
224  ) == 0;
225 }
226 
227 
228 //==========================================================================================================================================
229 //==========================================================================================================================================
230 bool oC_TGUI_SetStyle( const oC_TGUI_Style_t * Style )
231 {
232  return isaddresscorrect(Style) && oC_TGUI_SetForegroundColor(Style->Foreground) && oC_TGUI_SetBackgroundColor(Style->Background) && oC_TGUI_SetTextStyle(Style->TextStyle);
233 }
234 
235 //==========================================================================================================================================
236 //==========================================================================================================================================
237 bool oC_TGUI_SaveAttributes( void )
238 {
239  return printf(oC_VT100_SAVE_CURSOR_AND_ATTRS) == 0;
240 }
241 //==========================================================================================================================================
242 //==========================================================================================================================================
243 bool oC_TGUI_RestoreAttributes ( void )
244 {
245  return printf(oC_VT100_RESTORE_CURSOR_AND_ATTRS) == 0;
246 }
247 
248 //==========================================================================================================================================
249 //==========================================================================================================================================
250 int oC_TGUI_Position_Compare( oC_TGUI_Position_t P1 , oC_TGUI_Position_t P2)
251 {
252  int result = 0;
253 
254  if( P1.Line < P2.Line )
255  {
256  result = -1;
257  }
258  else if( P1.Line > P2.Line )
259  {
260  result = 1;
261  }
262  else
263  {
264  result = (P1.Column < P2.Column ) ? -1 : (int)(P1.Column - P2.Column);
265  }
266 
267  return result;
268 }
269 
270 //==========================================================================================================================================
271 //==========================================================================================================================================
272 oC_TGUI_Position_t oC_TGUI_Position_Increment( oC_TGUI_Position_t TopLeft , oC_TGUI_Position_t BottomRight , oC_TGUI_Position_t Position )
273 {
274  if(Position.Column < BottomRight.Column)
275  {
276  Position.Column++;
277  }
278  else
279  {
280  if(Position.Line < BottomRight.Line)
281  {
282  Position.Column = TopLeft.Column;
283  Position.Line++;
284  }
285  else
286  {
287  Position.Column = BottomRight.Column;
288  Position.Line = BottomRight.Line;
289  }
290  }
291 
292  return Position;
293 }
294 
295 //==========================================================================================================================================
296 //==========================================================================================================================================
297 oC_TGUI_Position_t oC_TGUI_Position_Decrement( oC_TGUI_Position_t TopLeft , oC_TGUI_Position_t BottomRight , oC_TGUI_Position_t Position )
298 {
299  if(Position.Column > TopLeft.Column)
300  {
301  Position.Column--;
302  }
303  else
304  {
305  if(Position.Line > TopLeft.Line)
306  {
307  Position.Line--;
308  Position.Column = BottomRight.Column;
309  }
310  else
311  {
312  Position.Column = TopLeft.Column;
313  Position.Line = TopLeft.Line;
314  }
315  }
316  return Position;
317 }
318 
319 //==========================================================================================================================================
320 //==========================================================================================================================================
321 bool oC_TGUI_DrawLine( oC_TGUI_Position_t StartPosition , oC_TGUI_Position_t EndPosition )
322 {
323  bool success = false;
324  oC_TGUI_Position_t position = {0};
325 
326  if(oC_TGUI_Position_IsCorrect(StartPosition) && oC_TGUI_Position_IsCorrect(EndPosition))
327  {
328  if(StartPosition.Line == EndPosition.Line && StartPosition.Column < EndPosition.Column)
329  {
330  success = true;
331  position = StartPosition;
332 
333  while(position.Column < EndPosition.Column && success)
334  {
335  success = oC_TGUI_DrawAtPosition(position,oC_VT100_BORDER_LR);
336  position.Column++;
337  }
338  }
339  else if(StartPosition.Column == EndPosition.Column && StartPosition.Line < EndPosition.Line)
340  {
341  success = true;
342  position = StartPosition;
343 
344  while(position.Line < EndPosition.Line && success)
345  {
346  success = oC_TGUI_DrawAtPosition(position,oC_VT100_BORDER_UD);
347  position.Line++;
348  }
349  }
350  }
351 
352  return success;
353 }
354 
355 //==========================================================================================================================================
356 //==========================================================================================================================================
357 bool oC_TGUI_DrawBorder( oC_TGUI_Position_t TopLeft , oC_TGUI_Position_t BottomRight )
358 {
359  bool success = false;
360 
361  if(TopLeft.Column < BottomRight.Column &&
362  TopLeft.Line < BottomRight.Line &&
363  oC_TGUI_Position_IsCorrect(TopLeft) &&
364  oC_TGUI_Position_IsCorrect(BottomRight) )
365  {
366  oC_TGUI_Position_t topRight = { .Line = TopLeft.Line , .Column = BottomRight.Column };
367  oC_TGUI_Position_t bottomLeft = { .Line = BottomRight.Line , .Column = TopLeft.Column };
368 
369  success = oC_TGUI_DrawLine( TopLeft ,topRight ) &&
370  oC_TGUI_DrawLine( bottomLeft,BottomRight ) &&
371  oC_TGUI_DrawLine( TopLeft ,bottomLeft ) &&
372  oC_TGUI_DrawLine( topRight ,BottomRight ) &&
373  oC_TGUI_DrawAtPosition( TopLeft, oC_VT100_BORDER_DR ) &&
374  oC_TGUI_DrawAtPosition( topRight, oC_VT100_BORDER_LD ) &&
375  oC_TGUI_DrawAtPosition( BottomRight, oC_VT100_BORDER_LU ) &&
376  oC_TGUI_DrawAtPosition( bottomLeft, oC_VT100_BORDER_UR );
377  }
378 
379  return success;
380 }
381 
382 //==========================================================================================================================================
383 //==========================================================================================================================================
384 bool oC_TGUI_DrawAtPosition( oC_TGUI_Position_t StartPosition , const char * String )
385 {
386  return oC_TGUI_SetCursorPosition(StartPosition) && oC_KPrint_WriteToStdOut(oC_IoFlags_Default , String , strlen(String)) == 0;
387 }
388 
389 //==========================================================================================================================================
390 //==========================================================================================================================================
391 bool oC_TGUI_DrawAtPositionWithSize ( oC_TGUI_Position_t StartPosition , const char * String , int Size )
392 {
393  bool success = false;
394 
395  if(oC_TGUI_SetCursorPosition(StartPosition))
396  {
397  int len = strlen(String);
398 
399  oC_TGUI_DrawNCharAtPosition(StartPosition,' ',Size);
400  oC_TGUI_SetCursorPosition(StartPosition);
401  oC_KPrint_WriteToStdOut(oC_IoFlags_Default , String , oC_MIN(len,Size));
402  success = true;
403  }
404 
405  return success;
406 }
407 
408 //==========================================================================================================================================
409 //==========================================================================================================================================
410 bool oC_TGUI_DrawCharAtPosition( oC_TGUI_Position_t StartPosition , char C )
411 {
412  return oC_TGUI_SetCursorPosition(StartPosition) && oC_KPrint_WriteToStdOut(oC_IoFlags_Default , &C , 1) == oC_ErrorCode_None;
413 }
414 
415 //==========================================================================================================================================
416 //==========================================================================================================================================
417 bool oC_TGUI_DrawNCharAtPosition( oC_TGUI_Position_t StartPosition , char C , int N )
418 {
419  bool success = oC_TGUI_SetCursorPosition(StartPosition);
420 
421  for(int i = 0; i < N && success ; i++)
422  {
423  success = oC_KPrint_WriteToStdOut(oC_IoFlags_Default , &C , 1) == oC_ErrorCode_None;
424  }
425 
426  return success;
427 }
428 
429 //==========================================================================================================================================
430 //==========================================================================================================================================
431 bool oC_TGUI_DrawFillBetween( oC_TGUI_Position_t StartPosition , oC_TGUI_Position_t EndPosition , char C )
432 {
433  bool success = false;
434 
435  if(oC_TGUI_Position_IsCorrect(StartPosition) && oC_TGUI_Position_IsCorrect(EndPosition) &&
436  StartPosition.Line <= EndPosition.Line &&
437  StartPosition.Column <= EndPosition.Column )
438  {
439  oC_TGUI_Position_t position = StartPosition;
440  oC_TGUI_Column_t width = EndPosition.Column - StartPosition.Column + 1;
441 
442  success = true;
443 
444  while(position.Line <= EndPosition.Line && success)
445  {
446  success = oC_TGUI_DrawNCharAtPosition(position,C,width);
447  position.Line++;
448  }
449  }
450 
451  return success;
452 }
453 
454 //==========================================================================================================================================
467 //==========================================================================================================================================
469 {
470  bool success = false;
471 
472  if(oC_TGUI_Position_IsCorrect(StartPosition) && Width > 0 && Height > 0)
473  {
474  oC_TGUI_Position_t endPosition = { .Column = StartPosition.Column + Width , .Line = StartPosition.Line + Height };
475  success = oC_TGUI_SetBackgroundColor(Color) &&
476  oC_TGUI_DrawFillBetween(StartPosition,endPosition,' ');
477 
478  }
479 
480  return success;
481 }
482 
483 //==========================================================================================================================================
484 //==========================================================================================================================================
485 bool oC_TGUI_DrawMultiLineText( oC_TGUI_Position_t StartPosition , oC_TGUI_Position_t EndPosition , const char * String , bool AsPassword )
486 {
487  bool success = false;
488 
489  if(oC_TGUI_Position_IsCorrect(StartPosition) && oC_TGUI_Position_IsCorrect(EndPosition) && isaddresscorrect(String))
490  {
491  int stringLength = strlen(String);
492  oC_TGUI_Position_t position = StartPosition;
493 
494  success = oC_TGUI_SetCursorPosition(position);
495 
496  for(int characterIndex = 0 ; success && characterIndex < stringLength && position.Line <= EndPosition.Line; characterIndex++)
497  {
498  if(String[characterIndex] == '\r')
499  {
500  continue;
501  }
502  else if(String[characterIndex] == '\t')
503  {
504  success = oC_KPrint_WriteToStdOut(oC_IoFlags_Default," ",2) == oC_ErrorCode_None;
505  position.Column+= 2;
506 
507  }
508  else if( String[characterIndex] == '\n' || position.Column > EndPosition.Column )
509  {
510  position.Column = StartPosition.Column;
511  position.Line++;
512  success = oC_TGUI_SetCursorPosition(position);
513  if(String[characterIndex] != '\n')
514  {
515  characterIndex--;
516  }
517  }
518  else
519  {
520  success = oC_KPrint_WriteToStdOut(oC_IoFlags_Default, AsPassword ? "*" : &String[characterIndex],1) == oC_ErrorCode_None;
521  position.Column++;
522  }
523  }
524  }
525 
526  return success;
527 }
528 
529 //==========================================================================================================================================
530 //==========================================================================================================================================
531 bool oC_TGUI_DrawFormatAtPosition( oC_TGUI_Position_t StartPosition , const char * Format , ... )
532 {
533  bool success = false;
534  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
535 
536  if(oC_TGUI_Position_IsCorrect(StartPosition))
537  {
538  if(oC_TGUI_SetCursorPosition(StartPosition))
539  {
540  va_list argumentList;
541  va_start(argumentList, Format);
542  errorCode = vprintf(Format,argumentList);
543  va_end(argumentList);
544  success = oC_ErrorOccur(errorCode) == false;
545  }
546  }
547  return success;
548 }
549 
550 //==========================================================================================================================================
551 //==========================================================================================================================================
552 bool oC_TGUI_FindPositionInBuffer( oC_TGUI_Position_t TopLeft , oC_TGUI_Position_t * Position ,oC_TGUI_Column_t Width , oC_TGUI_Line_t Height , const char * String , uint32_t * outIndex )
553 {
554  bool found = false;
555 
556  if(oC_TGUI_Position_IsCorrect(TopLeft) && isram(Position) && Width > 0 && Height > 0 && isaddresscorrect(String) && isram(outIndex))
557  {
558  oC_TGUI_Position_t bottomRight = { .Column = TopLeft.Column + Width , .Line = TopLeft.Line + Height };
559  oC_TGUI_Position_t position = TopLeft;
560  uint32_t strLength = strlen(String);
561  uint32_t signIndex = 0;
562 
563  for(signIndex = 0; signIndex < strLength && position.Line < bottomRight.Line ; signIndex++)
564  {
565  if(position.Column == Position->Column && position.Line == Position->Line)
566  {
567  *outIndex = signIndex;
568  found = true;
569  break;
570  }
571 
572  if(String[signIndex] == '\n')
573  {
574  if(position.Line == Position->Line)
575  {
576  break;
577  }
578  position.Line++;
579  }
580  else if(String[signIndex] == '\r')
581  {
582  position.Column = TopLeft.Column;
583  }
584  else
585  {
586  position.Column++;
587  }
588 
589  if(position.Column >= bottomRight.Column)
590  {
591  position.Column = TopLeft.Column;
592  position.Line++;
593  }
594  }
595 
596  if(!found)
597  {
598  Position->Column = position.Column;
599  Position->Line = position.Line;
600  *outIndex = signIndex;
601  }
602  }
603 
604  return found;
605 }
606 
607 //==========================================================================================================================================
608 //==========================================================================================================================================
609 void oC_TGUI_DrawSpiner( oC_TGUI_Spiner_t * outSpiner )
610 {
611  if(isram(outSpiner))
612  {
613  static const char string[] = "/-\\|";
614  if(outSpiner->SignIndex >= (sizeof(string)-1))
615  {
616  outSpiner->SignIndex = 0;
617  }
618  oC_KPrint_WriteToStdOut(oC_Process_GetIoFlags(getcurprocess()),&string[outSpiner->SignIndex],1);
619  outSpiner->SignIndex++;
620  }
621 }
622 
623 //==========================================================================================================================================
624 //==========================================================================================================================================
625 bool oC_TGUI_DrawProgressBar( oC_TGUI_Position_t Position , oC_TGUI_Column_t Width , uint32_t CurrentValue , uint32_t MaximumValue , const oC_TGUI_ProgressBarStyle_t * Style )
626 {
627  bool success = false;
628 
629  if( oC_TGUI_Position_IsCorrect(Position) && Width > 8 && MaximumValue > 0 && CurrentValue <= MaximumValue && isaddresscorrect(Style) )
630  {
631  oC_TGUI_Position_t topLeft = Position;
632  oC_TGUI_Position_t bottomRight = Position;
633  oC_TGUI_Position_t barPosition = Position;
634  oC_TGUI_Column_t endColumn = 0;
635  oC_TGUI_Column_t barWidth = 0;
636  double loadedRatio = ((double)CurrentValue) / ((double)MaximumValue);
637  oC_TGUI_Column_t loadedBarWidth = 0;
638  oC_TGUI_Column_t loadedEndColumn = 0;
639  oC_TGUI_Column_t stringBarColumn = 0;
640  oC_TGUI_Column_t stringBarEndColumn = 0;
641  char percentString[10];
642  char * stringReference = percentString;
643 
644  bottomRight.Line += 2;
645  bottomRight.Column += Width;
646 
647  barPosition.Line = topLeft.Line + 1;
648  barPosition.Column = topLeft.Column + 1;
649 
650  endColumn = barPosition.Column + Width - 1;
651  barWidth = Width - 2;
652  loadedBarWidth = (oC_TGUI_Column_t)(loadedRatio * ((double)barWidth));
653  loadedEndColumn = barPosition.Column + loadedBarWidth;
654  stringBarColumn = barPosition.Column + (barWidth / 2);
655 
656  oC_TGUI_SaveAttributes();
657  success = true;
658 
659  memset(percentString,0,sizeof(percentString));
660 
661  sprintf_s(percentString,sizeof(percentString),"%5.1f%%" , loadedRatio * ((double)100));
662 
663  stringBarColumn -= strlen(percentString) / 2;
664  stringBarEndColumn = stringBarColumn + strlen(percentString);
665 
666  if(Style->BorderStyle.DontDraw != true)
667  {
668  success = success && oC_TGUI_SetStyle(&Style->BorderStyle) &&
669  oC_TGUI_DrawBorder(topLeft,bottomRight);
670  }
671 
672  oC_TGUI_SetTextStyle(oC_TGUI_TextStyle_Default);
673 
674  while(success && barPosition.Column < endColumn)
675  {
676  if(barPosition.Column >= loadedEndColumn)
677  {
678  success = oC_TGUI_SetBackgroundColor(Style->NonActiveColor) &&
679  oC_TGUI_SetForegroundColor(Style->ActiveColor);
680  }
681  else
682  {
683  success = oC_TGUI_SetBackgroundColor(Style->ActiveColor) &&
684  oC_TGUI_SetForegroundColor(Style->NonActiveColor);
685  }
686  char c = ' ';
687 
688  if(barPosition.Column >= stringBarColumn && barPosition.Column < stringBarEndColumn)
689  {
690  c = *stringReference;
691  stringReference++;
692  }
693 
694  success = success && oC_TGUI_DrawCharAtPosition(barPosition,c);
695 
696  barPosition.Column++;
697  }
698 
699  oC_TGUI_RestoreAttributes();
700  }
701 
702  return success;
703 }
704 
705 //==========================================================================================================================================
706 //==========================================================================================================================================
707 bool oC_TGUI_DrawTextBox( const char * String , oC_TGUI_Position_t Position , oC_TGUI_Column_t FixedWidth , const oC_TGUI_TextBoxStyle_t * Style )
708 {
709  bool success = false;
710 
711  if(isaddresscorrect(String) && isaddresscorrect(Style) && oC_TGUI_Position_IsCorrect(Position))
712  {
713  int stringLength = strlen(String);
714  int stringToPrintLength = 0;
715  oC_TGUI_Position_t topLeft = Position;
716  oC_TGUI_Position_t topRight = Position;
717  oC_TGUI_Position_t bottomLeft = Position;
718  oC_TGUI_Position_t bottomRight = Position;
719  oC_TGUI_Position_t stringPosition = {0};
720 
721  oC_TGUI_SaveAttributes();
722 
723  FixedWidth = (FixedWidth == 0) ? stringLength + 2 : FixedWidth;
724  stringToPrintLength = FixedWidth - 2;
725 
726  topRight.Column += FixedWidth;
727  bottomLeft.Line += 2;
728  bottomRight.Line = bottomLeft.Line;
729  bottomRight.Column = topRight.Column;
730 
731  stringPosition.Line = topLeft.Line + 1;
732  stringPosition.Column = topLeft.Column + 1;
733 
734  success = true;
735  if(Style->BorderStyle.DontDraw != true)
736  {
737  success = oC_TGUI_SetStyle(&Style->BorderStyle) &&
738  oC_TGUI_DrawBorder(topLeft,bottomRight);
739  }
740  if(Style->TextStyle.DontDraw != true)
741  {
742  success = oC_TGUI_SetStyle(&Style->TextStyle) &&
743  oC_TGUI_DrawAtPositionWithSize(stringPosition , String , stringToPrintLength );
744  }
745 
746  oC_TGUI_RestoreAttributes();
747  }
748 
749  return success;
750 }
751 
752 //==========================================================================================================================================
769 //==========================================================================================================================================
770 bool oC_TGUI_DrawBox( const char * Title , const char * TextInside , oC_TGUI_Position_t TopLeft , oC_TGUI_Column_t Width , oC_TGUI_Line_t Height , const oC_TGUI_BoxStyle_t * Style )
771 {
772  bool success = false;
773 
774  if(
775  isaddresscorrect(Style) &&
776  (isaddresscorrect(Title) || Style->TitleStyle.DontDraw ) &&
777  oC_TGUI_Position_IsCorrect(TopLeft))
778  {
779  oC_TGUI_Position_t bottomRight = TopLeft;
780  oC_TGUI_Position_t stringPosition = TopLeft;
781  oC_TGUI_Position_t shadowRightStart;
782  oC_TGUI_Position_t shadowRightEnd;
783  oC_TGUI_Position_t shadowBottomStart;
784  oC_TGUI_Position_t shadowBottomEnd;
785  oC_TGUI_Position_t insideTopLeft;
786  oC_TGUI_Position_t insideBottomRight;
787 
788  bottomRight.Column += Width - 2;
789  bottomRight.Line += Height - 2;
790 
791  stringPosition.Column += (Width / 2) - (strlen(Title) / 2);
792 
793  shadowRightStart.Column = bottomRight.Column + 1;
794  shadowRightStart.Line = TopLeft.Line + 1;
795  shadowRightEnd.Column = shadowRightStart.Column;
796  shadowRightEnd.Line = bottomRight.Line + 1;
797 
798  shadowBottomStart.Column= TopLeft.Column + 1;
799  shadowBottomStart.Line = bottomRight.Line + 1;
800  shadowBottomEnd.Column = shadowRightEnd.Column;
801  shadowBottomEnd.Line = shadowBottomStart.Line;
802 
803  insideTopLeft.Column = TopLeft.Column + 1;
804  insideTopLeft.Line = TopLeft.Line + 1;
805  insideBottomRight.Column= bottomRight.Column - 1;
806  insideBottomRight.Line = bottomRight.Line - 1;
807 
808  oC_TGUI_SaveAttributes();
809 
810  success = true;
811 
812  if(Style->BorderStyle.DontDraw != true)
813  {
814  success = success && oC_TGUI_SetStyle(&Style->BorderStyle) &&
815  oC_TGUI_DrawBorder(TopLeft,bottomRight);
816  }
817 
818  if(Style->TitleStyle.DontDraw != true)
819  {
820  success = success && oC_TGUI_SetStyle(&Style->TitleStyle) &&
821  oC_TGUI_DrawAtPosition(stringPosition,Title);
822  }
823 
824  if(Style->ShadowStyle.DontDraw != true)
825  {
826  success = success && oC_TGUI_SetBackgroundColor(Style->ShadowStyle.Background) &&
827  oC_TGUI_DrawFillBetween(shadowRightStart,shadowRightEnd,' ') &&
828  oC_TGUI_DrawFillBetween(shadowBottomStart,shadowBottomEnd,' ');
829  }
830 
831  if(Style->InsideStyle.DontDraw != true)
832  {
833  success = success && oC_TGUI_SetStyle(&Style->InsideStyle) &&
834  oC_TGUI_DrawFillBetween(insideTopLeft,insideBottomRight,' ');
835 
836  if(isaddresscorrect(TextInside))
837  {
838  success = success && oC_TGUI_DrawMultiLineText(insideTopLeft,insideBottomRight,TextInside,false);
839  }
840  }
841 
842  oC_TGUI_RestoreAttributes();
843  }
844 
845  return success;
846 }
847 
848 //==========================================================================================================================================
849 //==========================================================================================================================================
850 bool oC_TGUI_DrawProperties( const oC_TGUI_DrawPropertyConfig_t * Config )
851 {
852  bool success = false;
853 
854  if(
855  isaddresscorrect(Config) &&
856  isaddresscorrect(Config->Style) &&
857  isaddresscorrect(Config->Properties) &&
858  oC_TGUI_Position_IsCorrect(Config->StartPosition) &&
859  Config->Height > 0 &&
860  Config->Width > 0 &&
861  Config->DescriptionWidth > 0 &&
862  Config->NumberOfProperties > 0 &&
863  Config->DescriptionWidth < Config->Width
864  )
865  {
866  oC_TGUI_EntryIndex_t entryIndex = 0;
867  oC_TGUI_Position_t position = Config->StartPosition;
868  oC_TGUI_Position_t valuePosition = Config->StartPosition;
869  oC_TGUI_Position_t bottomRight = { .Column = Config->StartPosition.Column + Config->Width , .Line = Config->StartPosition.Line + Config->Height };
870 
871  success = true;
872 
873  /* Drawing menu entries */
874  for(position = Config->StartPosition , entryIndex = 0 ; position.Line < bottomRight.Line && success ; position.Line++ , entryIndex++)
875  {
876  if(entryIndex < Config->NumberOfProperties)
877  {
878 
879  if(Config->Style->DescriptionStyle.DontDraw != true)
880  {
881  success = success && oC_TGUI_SetStyle(&Config->Style->DescriptionStyle) &&
882  oC_TGUI_DrawAtPositionWithSize(position,Config->Properties[entryIndex].Description,Config->DescriptionWidth);
883  }
884 
885  if(Config->Style->ValueStyle.DontDraw != true)
886  {
887  success = success &&oC_TGUI_SetStyle(&Config->Style->ValueStyle);
888 
889  valuePosition = position;
890  valuePosition.Column += Config->DescriptionWidth;
891 
892  switch(Config->Properties[entryIndex].Type)
893  {
894  case oC_TGUI_ValueType_UINT: success = success && oC_TGUI_DrawFormatAtPosition(valuePosition,Config->Properties[entryIndex].Format,Config->Properties[entryIndex].ValueUINT); break;
895  case oC_TGUI_ValueType_U32: success = success && oC_TGUI_DrawFormatAtPosition(valuePosition,Config->Properties[entryIndex].Format,Config->Properties[entryIndex].ValueU32); break;
896  case oC_TGUI_ValueType_U64: success = success && oC_TGUI_DrawFormatAtPosition(valuePosition,Config->Properties[entryIndex].Format,Config->Properties[entryIndex].ValueU64); break;
897  case oC_TGUI_ValueType_I32: success = success && oC_TGUI_DrawFormatAtPosition(valuePosition,Config->Properties[entryIndex].Format,Config->Properties[entryIndex].ValueI32); break;
898  case oC_TGUI_ValueType_I64: success = success && oC_TGUI_DrawFormatAtPosition(valuePosition,Config->Properties[entryIndex].Format,Config->Properties[entryIndex].ValueI64); break;
899  case oC_TGUI_ValueType_ValueFloat: success = success && oC_TGUI_DrawFormatAtPosition(valuePosition,Config->Properties[entryIndex].Format,Config->Properties[entryIndex].ValueFloat); break;
900  case oC_TGUI_ValueType_ValueDouble: success = success && oC_TGUI_DrawFormatAtPosition(valuePosition,Config->Properties[entryIndex].Format,Config->Properties[entryIndex].ValueDouble); break;
901  case oC_TGUI_ValueType_ValueChar: success = success && oC_TGUI_DrawFormatAtPosition(valuePosition,Config->Properties[entryIndex].Format,Config->Properties[entryIndex].ValueChar); break;
902  case oC_TGUI_ValueType_ValueString: success = success && oC_TGUI_DrawFormatAtPosition(valuePosition,Config->Properties[entryIndex].Format,Config->Properties[entryIndex].ValueString); break;
903  default:
904  oC_TGUI_DrawAtPositionWithSize(valuePosition,"INCORRECT TYPE!",Config->Width - Config->DescriptionWidth);
905  break;
906  }
907  }
908  }
909  else
910  {
911  oC_TGUI_SetStyle(&Config->Style->DescriptionStyle);
912  oC_TGUI_DrawNCharAtPosition(position,' ', Config->Width);
913  }
914  }
915  }
916 
917  return success;
918 }
919 
920 //==========================================================================================================================================
940 //==========================================================================================================================================
942 {
943  oC_TGUI_EntryIndex_t selectedIndex = -1;
944 
945  if(oC_TGUI_Position_IsCorrect(TopLeft) && Width > 0 && Height > 0 && isaddresscorrect(MenuEntries) && NumberOfEntries > 0 && isaddresscorrect(Style))
946  {
947  oC_TGUI_Position_t bottomRight = { .Column = TopLeft.Column + Width , .Line = TopLeft.Line + Height };
948  bool success = true;
949 
950  if(Style->Border.DontDraw != true)
951  {
952  success = success && oC_TGUI_SetStyle(&Style->Border) &&
953  oC_TGUI_DrawBorder(TopLeft,bottomRight);
954  TopLeft.Column++;
955  TopLeft.Line++;
956  bottomRight.Column--;
957  bottomRight.Line--;
958  Width -= 2;
959  Height -= 2;
960  }
961 
962  if(success)
963  {
964  oC_TGUI_Key_t key = 0;
965  oC_TGUI_EntryIndex_t entryIndex = 0;
966  oC_TGUI_EntryIndex_t lastIndex = NumberOfEntries - 1;
967  oC_TGUI_EntryIndex_t displayedStartIndex = 0;
968  oC_TGUI_EntryIndex_t displayedLastIndex = lastIndex;
969  oC_TGUI_EntryIndex_t numberOfEntriesOnScreen = oC_MIN(NumberOfEntries,Height);
970  oC_TGUI_Position_t position = TopLeft;
971 
972  selectedIndex = 0;
973 
974  do
975  {
976  if(key == oC_TGUI_Key_ArrowDown)
977  {
978  if(selectedIndex < lastIndex)
979  {
980  if( selectedIndex == displayedLastIndex
981  && numberOfEntriesOnScreen < NumberOfEntries
982  && displayedLastIndex < lastIndex
983  )
984  {
985  displayedStartIndex++;
986  displayedLastIndex++;
987  }
988  selectedIndex++;
989  }
990  else
991  {
992  selectedIndex = 0;
993  displayedStartIndex = 0;
994  displayedLastIndex = numberOfEntriesOnScreen;
995  }
996  }
997  else if(key == oC_TGUI_Key_ArrowUp)
998  {
999  if(selectedIndex > 0)
1000  {
1001  if( selectedIndex == displayedStartIndex
1002  && numberOfEntriesOnScreen < NumberOfEntries
1003  && displayedStartIndex > 0
1004  )
1005  {
1006  displayedStartIndex--;
1007  displayedLastIndex--;
1008  }
1009  selectedIndex--;
1010  }
1011  else
1012  {
1013  selectedIndex = lastIndex;
1014  displayedLastIndex = lastIndex;
1015  displayedStartIndex = lastIndex - numberOfEntriesOnScreen + 1;
1016  }
1017  }
1018  else if(key == oC_TGUI_Key_Enter)
1019  {
1020  if(selectedIndex >= 0 && selectedIndex < NumberOfEntries)
1021  {
1022  if(isaddresscorrect(MenuEntries[selectedIndex].Handler))
1023  {
1024  MenuEntries[selectedIndex].Handler(MenuEntries[selectedIndex].Parameter);
1025  }
1026  else
1027  {
1028  break;
1029  }
1030  }
1031  }
1032  else if(key == oC_TGUI_Key_ESC)
1033  {
1034  selectedIndex = NumberOfEntries;
1035  break;
1036  }
1037 
1038  /* Drawing menu entries */
1039  for(position = TopLeft , entryIndex = displayedStartIndex ; position.Line <= bottomRight.Line; position.Line++ , entryIndex++)
1040  {
1041  if(entryIndex < NumberOfEntries)
1042  {
1043  if(entryIndex == selectedIndex)
1044  {
1045  oC_TGUI_SetStyle(&Style->ActiveEntry);
1046 
1047  if(isaddresscorrect(MenuEntries[entryIndex].OnHoverHandler))
1048  {
1049  MenuEntries[selectedIndex].OnHoverHandler(MenuEntries[selectedIndex].OnHoverParameter);
1050  }
1051  }
1052  else
1053  {
1054  oC_TGUI_SetStyle(&Style->NotActiveEntry);
1055  }
1056 
1057  oC_TGUI_DrawAtPositionWithSize(position,MenuEntries[entryIndex].Title,Width);
1058  }
1059  else
1060  {
1061  oC_TGUI_SetStyle(&Style->NotActiveEntry);
1062  oC_TGUI_DrawNCharAtPosition(position,' ',Width);
1063  }
1064  }
1065  }
1066  while(oC_TGUI_WaitForKeyPress(&key));
1067  }
1068  }
1069 
1070  return selectedIndex;
1071 }
1072 
1073 //==========================================================================================================================================
1074 //==========================================================================================================================================
1075 bool oC_TGUI_DrawListMenu( const oC_TGUI_DrawListMenuConfig_t * Config )
1076 {
1077  bool success = false;
1078 
1079  if(
1080  isaddresscorrect(Config) &&
1081  oC_TGUI_Position_IsCorrect(Config->TopLeft) &&
1082  Config->Width > 0 &&
1083  Config->Height> 0 &&
1084  oC_List_IsCorrect(Config->List) &&
1085  isaddresscorrect(Config->DrawHandler) &&
1086  isaddresscorrect(Config->Style)
1087  )
1088  {
1089  oC_TGUI_Column_t width = Config->Width;
1090  oC_TGUI_Line_t height = Config->Height;
1091  oC_TGUI_Position_t topLeft = Config->TopLeft;
1092  oC_TGUI_Position_t bottomRight = { .Column = topLeft.Column + width , .Line = topLeft.Line + height };
1093  oC_TGUI_Position_t position = topLeft;
1094  oC_TGUI_Key_t key = 0;
1095  oC_List_ElementHandle_t first = oC_List_GetFirstElementHandle(Config->List);
1096  oC_List_ElementHandle_t last = oC_List_GetLastElementHandle(Config->List);
1097  uint32_t elementsCount = oC_List_Count(Config->List);
1098  oC_List_ElementHandle_t firstToDisplay = first;
1099  oC_List_ElementHandle_t lastToDisplay = last;
1100  oC_List_ElementHandle_t selected = first;
1101  oC_List_ElementHandle_t element = first;
1102  uint32_t onScreenCount = 0;
1103 
1104  success = true;
1105 
1106  if(Config->Style->Border.DontDraw != true)
1107  {
1108  success = success && oC_TGUI_SetStyle(&Config->Style->Border) &&
1109  oC_TGUI_DrawBorder(topLeft,bottomRight);
1110  topLeft.Column++;
1111  topLeft.Line++;
1112  bottomRight.Column--;
1113  bottomRight.Line--;
1114  width-=2;
1115  height-=2;
1116  }
1117 
1118  onScreenCount = height;
1119 
1120  if(onScreenCount < elementsCount)
1121  {
1122  lastToDisplay = List_ElementOfIndex(Config->List,onScreenCount - 1);
1123  }
1124 
1125  if(success)
1126  {
1127  do
1128  {
1129  if(key == oC_TGUI_Key_ArrowUp)
1130  {
1131  if(selected != first)
1132  {
1133  if(
1134  selected == firstToDisplay &&
1135  elementsCount > onScreenCount &&
1136  firstToDisplay != first
1137  )
1138  {
1139  firstToDisplay = oC_List_ElementHandle_Previous(firstToDisplay);
1140  lastToDisplay = oC_List_ElementHandle_Previous(lastToDisplay);
1141  }
1142  selected = oC_List_ElementHandle_Previous(selected);
1143  }
1144  else
1145  {
1146  selected = last;
1147  while(lastToDisplay != last && lastToDisplay != NULL)
1148  {
1149  lastToDisplay = oC_List_ElementHandle_Next(lastToDisplay);
1150  firstToDisplay = oC_List_ElementHandle_Next(firstToDisplay);
1151  }
1152  }
1153  }
1154  else if(key == oC_TGUI_Key_ArrowDown)
1155  {
1156  if(selected != last)
1157  {
1158  if(
1159  selected == lastToDisplay &&
1160  elementsCount > onScreenCount &&
1161  lastToDisplay != last
1162  )
1163  {
1164  firstToDisplay = oC_List_ElementHandle_Next(firstToDisplay);
1165  lastToDisplay = oC_List_ElementHandle_Next(lastToDisplay);
1166  }
1167  selected = oC_List_ElementHandle_Next(selected);
1168  }
1169  else
1170  {
1171  selected = first;
1172  while(firstToDisplay != first && firstToDisplay != NULL)
1173  {
1174  lastToDisplay = oC_List_ElementHandle_Previous(lastToDisplay);
1175  firstToDisplay = oC_List_ElementHandle_Previous(firstToDisplay);
1176  }
1177  }
1178  }
1179  else if(key == oC_TGUI_Key_Enter)
1180  {
1181  if(isaddresscorrect(Config->SelectHandler))
1182  {
1183  Config->SelectHandler(selected);
1184  }
1185  }
1186  else if(key == oC_TGUI_Key_ESC)
1187  {
1188  selected = NULL;
1189  break;
1190  }
1191 
1192  for(element = firstToDisplay , position = topLeft; position.Line <= bottomRight.Line ; position.Line++)
1193  {
1194  if(isram(element))
1195  {
1196  if(element == selected)
1197  {
1198  oC_TGUI_SetStyle(&Config->Style->ActiveEntry);
1199  }
1200  else
1201  {
1202  oC_TGUI_SetStyle(&Config->Style->NotActiveEntry);
1203  }
1204 
1205  oC_TGUI_DrawNCharAtPosition(position,' ',width);
1206  oC_TGUI_SetCursorPosition(position);
1207  Config->DrawHandler(position,element,width);
1208 
1209  element = oC_List_ElementHandle_Next(element);
1210  }
1211  else
1212  {
1213  oC_TGUI_SetStyle(&Config->Style->NotActiveEntry);
1214  oC_TGUI_DrawNCharAtPosition(position,' ',width);
1215  }
1216  }
1217  } while(oC_TGUI_WaitForKeyPress(&key));
1218  }
1219  }
1220 
1221  return success;
1222 }
1223 
1224 //==========================================================================================================================================
1225 //==========================================================================================================================================
1226 oC_TGUI_Key_t oC_TGUI_DrawPushButton( oC_TGUI_Position_t Position , oC_TGUI_Column_t Width , oC_TGUI_Line_t Height , const oC_TGUI_PushButton_t * PushButton , bool Active )
1227 {
1228  oC_TGUI_Key_t key = 0;
1229  bool success = false;
1230 
1231  if(oC_TGUI_Position_IsCorrect(Position) && Width > 0 && Height > 0 && isaddresscorrect(PushButton) && isaddresscorrect(PushButton->Text) && isaddresscorrect(PushButton->Style))
1232  {
1233  oC_TGUI_Position_t topLeft = Position;
1234  oC_TGUI_Position_t bottomRight = { .Column = Position.Column + Width , .Line = Position.Line + Height };
1235  uint32_t textLength = strlen(PushButton->Text);
1236  oC_TGUI_Position_t textPosition= Position;
1237 
1238 
1239  success = true;
1240 
1241  if(PushButton->Style->ActiveBorder.DontDraw != true)
1242  {
1243  success = success && oC_TGUI_SetStyle(&PushButton->Style->ActiveBorder) &&
1244  oC_TGUI_DrawBorder(topLeft,bottomRight);
1245  topLeft.Column++;
1246  topLeft.Line++;
1247  bottomRight.Column--;
1248  bottomRight.Line--;
1249  Width--;
1250  Height--;
1251  }
1252 
1253  textPosition.Column = topLeft.Column + (Width/2) - (textLength/2);
1254  textPosition.Line = topLeft.Line;
1255 
1256 
1257  if(Active)
1258  {
1259  success = success && oC_TGUI_SetStyle(&PushButton->Style->Active);
1260  }
1261  else
1262  {
1263  success = success && oC_TGUI_SetStyle(&PushButton->Style->NotActive);
1264  }
1265 
1266  success = success && oC_TGUI_DrawNCharAtPosition(topLeft,' ',Width) &&
1267  oC_TGUI_DrawAtPosition(textPosition,PushButton->Text);
1268 
1269  if(Active)
1270  {
1271  while(oC_TGUI_WaitForKeyPress(&key))
1272  {
1273  if(key == oC_TGUI_Key_Enter)
1274  {
1275  if(isaddresscorrect(PushButton->PressHandler))
1276  {
1277  if(PushButton->PressHandler(PushButton->PressParameter))
1278  {
1279  key = oC_TGUI_Key_ESC;
1280  }
1281  }
1282  else
1283  {
1284  key = oC_TGUI_Key_ESC;
1285  }
1286  break;
1287  }
1288  else if(
1289  key == oC_TGUI_Key_ArrowDown ||
1290  key == oC_TGUI_Key_ArrowUp ||
1291  key == oC_TGUI_Key_ArrowLeft ||
1292  key == oC_TGUI_Key_ArrowRight ||
1293  key == oC_TGUI_Key_Tab
1294  )
1295  {
1296  break;
1297  }
1298  }
1299  }
1300  }
1301 
1302  return key;
1303 }
1304 
1305 //==========================================================================================================================================
1306 //==========================================================================================================================================
1307 oC_TGUI_Key_t oC_TGUI_DrawEditBox( oC_TGUI_Position_t Position , oC_TGUI_Column_t Width , oC_TGUI_Line_t Height , oC_TGUI_EditBox_t * EditBox , bool Active )
1308 {
1309  oC_TGUI_Key_t key = 0;
1310 
1311  if(oC_TGUI_Position_IsCorrect(Position) && Width >= 3 && Height > 0 &&
1312  isaddresscorrect(EditBox) && isram(EditBox->Buffer) && EditBox->BufferSize > 0 &&
1313  isaddresscorrect(EditBox->Style))
1314  {
1315  oC_TGUI_Position_t topLeft = Position;
1316  oC_TGUI_Position_t bottomRight = { .Column = Position.Column + Width , .Line = Position.Line + Height };
1317  oC_TGUI_Position_t borderTopLeft = topLeft;
1318  oC_TGUI_Position_t borderBottomRight = bottomRight;
1319  oC_TGUI_Position_t insideTopLeft = { .Column = topLeft.Column + 1 , .Line = topLeft.Line + 1 };
1320  oC_TGUI_Position_t insideBottomRight = { .Column = bottomRight.Column - 1 , .Line = bottomRight.Line - 1 };
1321  oC_TGUI_Position_t cursorPosition = insideTopLeft;
1322  uint32_t signIndex = strlen(EditBox->Buffer);
1323  uint32_t maxStringLength = EditBox->BufferSize - 1;
1324 
1325  /* ========================================================================================================== */
1326  /* Drawing not active first */
1327  if((EditBox->Style->NotActiveBorder.DontDraw != true && Active == false) ||
1328  (EditBox->Style->ActiveBorder.DontDraw != true && Active == true ) )
1329  {
1330  oC_TGUI_SetStyle(Active ? &EditBox->Style->ActiveBorder : &EditBox->Style->NotActiveBorder);
1331  oC_TGUI_DrawBorder(borderTopLeft,borderBottomRight);
1332  Width--;
1333  Height--;
1334  }
1335  else
1336  {
1337  insideTopLeft = topLeft;
1338  insideBottomRight = bottomRight;
1339  }
1340  oC_TGUI_SetStyle(&EditBox->Style->DisabledText);
1341  oC_TGUI_DrawFillBetween(insideTopLeft,insideBottomRight,' ');
1342  oC_TGUI_DrawMultiLineText(insideTopLeft,insideBottomRight,EditBox->Buffer,oC_Bits_AreBitsSetU32(EditBox->InputType,oC_TGUI_InputType_Password));
1343 
1344  /* ========================================================================================================== */
1345  /* Drawing active */
1346  if(Active)
1347  {
1348  bool activated = false;
1349 
1350  do
1351  {
1352  if(activated == false)
1353  {
1354  if(key == oC_TGUI_Key_Enter)
1355  {
1356  key = 0;
1357  activated = true;
1358  }
1359  else if(key == oC_TGUI_Key_ESC
1360  || key == oC_TGUI_Key_ArrowUp
1361  || key == oC_TGUI_Key_ArrowDown
1362  || key == oC_TGUI_Key_ArrowLeft
1363  || key == oC_TGUI_Key_ArrowRight
1364  || key == oC_TGUI_Key_Tab )
1365  {
1366  break;
1367  }
1368  }
1369  if(activated == true)
1370  {
1371  if(key == oC_TGUI_Key_ESC)
1372  {
1373  if(isaddresscorrect(EditBox->SaveHandler))
1374  {
1375  EditBox->SaveHandler(EditBox->Buffer,EditBox->BufferSize,EditBox->SaveParameter);
1376  }
1377  activated = false;
1378  }
1379  else if( key == oC_TGUI_Key_ArrowUp )
1380  {
1381  if(cursorPosition.Line > insideTopLeft.Line)
1382  {
1383  cursorPosition.Line--;
1384  signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,EditBox->Buffer);
1385  cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,EditBox->Buffer,signIndex);
1386  }
1387  }
1388  else if( key == oC_TGUI_Key_ArrowDown )
1389  {
1390  if(cursorPosition.Line < insideBottomRight.Line)
1391  {
1392  cursorPosition.Line++;
1393  signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,EditBox->Buffer);
1394  cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,EditBox->Buffer,signIndex);
1395  }
1396  }
1397  else if( key == oC_TGUI_Key_ArrowLeft )
1398  {
1399  if(cursorPosition.Column > insideTopLeft.Column)
1400  {
1401  cursorPosition.Column--;
1402  signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,EditBox->Buffer);
1403  cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,EditBox->Buffer,signIndex);
1404  }
1405  }
1406  else if( key == oC_TGUI_Key_ArrowRight)
1407  {
1408  if(cursorPosition.Column < bottomRight.Column)
1409  {
1410  cursorPosition.Column++;
1411  signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,EditBox->Buffer);
1412  cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,EditBox->Buffer,signIndex);
1413  }
1414  }
1415  else if( key == oC_TGUI_Key_Backspace )
1416  {
1417  signIndex = string_backspace(EditBox->Buffer,signIndex);
1418  cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,EditBox->Buffer,signIndex);
1419  }
1420  else if( key == oC_TGUI_Key_Enter )
1421  {
1422  if(oC_Bits_AreBitsSetU32(EditBox->InputType,oC_TGUI_InputType_SpecialChars) && cursorPosition.Line < insideBottomRight.Line)
1423  {
1424  signIndex = put_to_string(EditBox->Buffer,EditBox->BufferSize,signIndex,'\n');
1425  signIndex = put_to_string(EditBox->Buffer,EditBox->BufferSize,signIndex,'\r');
1426  cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,EditBox->Buffer,signIndex);
1427  }
1428  }
1429  else if(isprint((int)key) && signIndex < maxStringLength && (cursorPosition.Line < insideBottomRight.Line || cursorPosition.Column < insideBottomRight.Column))
1430  {
1431  if(
1432  (oC_Bits_AreBitsSetU32(EditBox->InputType,oC_TGUI_InputType_Digits) && isdigit((int)key)) ||
1433  (oC_Bits_AreBitsSetU32(EditBox->InputType,oC_TGUI_InputType_Characters) && isalpha((int)key)) ||
1434  (oC_Bits_AreBitsSetU32(EditBox->InputType,oC_TGUI_InputType_SpecialChars) && (isgraph((int)key) || isspace((int)key)))
1435  )
1436  {
1437  signIndex = put_to_string(EditBox->Buffer,EditBox->BufferSize,signIndex,(char)key);
1438  cursorPosition = oC_TGUI_Position_Increment(insideTopLeft,insideBottomRight,cursorPosition);
1439  }
1440  }
1441 
1442  oC_TGUI_SetStyle(activated ? &EditBox->Style->Text : &EditBox->Style->DisabledText);
1443  oC_TGUI_DrawFillBetween(insideTopLeft,insideBottomRight,' ');
1444  oC_TGUI_DrawMultiLineText(insideTopLeft,insideBottomRight,EditBox->Buffer,oC_Bits_AreBitsSetU32(EditBox->InputType,oC_TGUI_InputType_Password));
1445  oC_TGUI_SetCursorPosition(cursorPosition);
1446  }
1447  } while(oC_TGUI_WaitForKeyPress(&key));
1448  }
1449 
1450  }
1451 
1452  return key;
1453 }
1454 
1455 //==========================================================================================================================================
1456 //==========================================================================================================================================
1457 oC_TGUI_Key_t oC_TGUI_DrawQuickEditBox( oC_TGUI_Position_t Position , oC_TGUI_Column_t Width , oC_TGUI_QuickEditBox_t * QuickEditBox , bool Active )
1458 {
1459  oC_TGUI_Key_t key = 0;
1460 
1461  if(oC_TGUI_Position_IsCorrect(Position) && Width > 0 && isram(QuickEditBox) && isram(QuickEditBox->Buffer) && QuickEditBox->BufferSize > 0 && isaddresscorrect(QuickEditBox->Style))
1462  {
1463  oC_TGUI_Position_t topLeft = Position;
1464  oC_TGUI_Position_t bottomRight = { .Column = Position.Column + Width - 1 , .Line = Position.Line };
1465  oC_TGUI_Position_t borderTopLeft = topLeft;
1466  oC_TGUI_Position_t borderBottomRight = { .Column = bottomRight.Column , .Line = Position.Line + 2 };
1467  oC_TGUI_Position_t insideTopLeft = topLeft;
1468  oC_TGUI_Position_t insideBottomRight = bottomRight;
1469 
1470  /* ========================================================================================================== */
1471  /* Drawing not active first */
1472  if((QuickEditBox->Style->NotActiveBorder.DontDraw != true && Active == false) ||
1473  (QuickEditBox->Style->ActiveBorder.DontDraw != true && Active == true ) )
1474  {
1475  oC_TGUI_SetStyle(Active ? &QuickEditBox->Style->ActiveBorder : &QuickEditBox->Style->NotActiveBorder);
1476  oC_TGUI_DrawBorder(borderTopLeft,borderBottomRight);
1477  Width--;
1478  insideTopLeft.Column++;
1479  insideBottomRight.Column--;
1480  }
1481 
1482  oC_TGUI_SetStyle(&QuickEditBox->Style->NotActiveText);
1483  oC_TGUI_DrawFillBetween(insideTopLeft,insideBottomRight,' ');
1484  oC_TGUI_DrawMultiLineText(insideTopLeft,insideBottomRight,QuickEditBox->Buffer,oC_Bits_AreBitsSetU32(QuickEditBox->InputType,oC_TGUI_InputType_Password));
1485 
1486  if(Active)
1487  {
1488  oC_TGUI_Position_t cursorPosition = insideTopLeft;
1489  uint32_t maxStringLength = QuickEditBox->BufferSize - 1;
1490  uint32_t signIndex = strlen(QuickEditBox->Buffer);
1491 
1492  cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,QuickEditBox->Buffer,signIndex);
1493 
1494  do
1495  {
1496  if( key == oC_TGUI_Key_ESC
1497  || key == oC_TGUI_Key_ArrowUp
1498  || key == oC_TGUI_Key_ArrowDown
1499  || key == oC_TGUI_Key_Tab )
1500  {
1501  break;
1502  }
1503  else if(key == oC_TGUI_Key_Enter)
1504  {
1505  if(isaddresscorrect(QuickEditBox->SaveHandler))
1506  {
1507  QuickEditBox->SaveHandler(QuickEditBox->Buffer,QuickEditBox->BufferSize,QuickEditBox->SaveParameter);
1508  }
1509  else
1510  {
1511  break;
1512  }
1513  }
1514  else if(key == oC_TGUI_Key_ArrowRight)
1515  {
1516  if(cursorPosition.Column < insideBottomRight.Column && signIndex < strlen(QuickEditBox->Buffer))
1517  {
1518  cursorPosition.Column++;
1519  signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,QuickEditBox->Buffer);
1520  cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,QuickEditBox->Buffer,signIndex);
1521  }
1522  else
1523  {
1524  break;
1525  }
1526  }
1527  else if( key == oC_TGUI_Key_ArrowLeft )
1528  {
1529  if(cursorPosition.Column > insideTopLeft.Column)
1530  {
1531  cursorPosition.Column--;
1532  signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,QuickEditBox->Buffer);
1533  cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,QuickEditBox->Buffer,signIndex);
1534  }
1535  else
1536  {
1537  break;
1538  }
1539  }
1540  else if( key == oC_TGUI_Key_Backspace )
1541  {
1542  signIndex = string_backspace(QuickEditBox->Buffer,signIndex);
1543  cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,QuickEditBox->Buffer,signIndex);
1544  }
1545  else if(isprint((int)key) && signIndex < maxStringLength && (cursorPosition.Line < insideBottomRight.Line || cursorPosition.Column < insideBottomRight.Column))
1546  {
1547  if(
1548  (oC_Bits_AreBitsSetU32(QuickEditBox->InputType,oC_TGUI_InputType_Digits) && isdigit((int)key)) ||
1549  (oC_Bits_AreBitsSetU32(QuickEditBox->InputType,oC_TGUI_InputType_Characters) && isalpha((int)key)) ||
1550  (oC_Bits_AreBitsSetU32(QuickEditBox->InputType,oC_TGUI_InputType_SpecialChars) && (isgraph((int)key) || isspace((int)key)))
1551  )
1552  {
1553  signIndex = put_to_string(QuickEditBox->Buffer,QuickEditBox->BufferSize,signIndex,(char)key);
1554  cursorPosition = oC_TGUI_Position_Increment(insideTopLeft,insideBottomRight,cursorPosition);
1555  }
1556  }
1557 
1558  oC_TGUI_SetStyle(&QuickEditBox->Style->ActiveText);
1559  oC_TGUI_DrawFillBetween(insideTopLeft,insideBottomRight,' ');
1560  oC_TGUI_DrawMultiLineText(insideTopLeft,insideBottomRight,QuickEditBox->Buffer,oC_Bits_AreBitsSetU32(QuickEditBox->InputType,oC_TGUI_InputType_Password));
1561  oC_TGUI_SetCursorPosition(cursorPosition);
1562  } while(oC_TGUI_WaitForKeyPress(&key));
1563  }
1564  }
1565 
1566  return key;
1567 }
1568 
1569 //==========================================================================================================================================
1570 //==========================================================================================================================================
1571 oC_TGUI_Key_t oC_TGUI_DrawSelectionBox( oC_TGUI_Position_t Position , oC_TGUI_Column_t Width , const oC_TGUI_SelectionBox_t * SelectionBox , bool Active )
1572 {
1573  oC_TGUI_Key_t key = 0;
1574 
1575  if(
1576  isaddresscorrect(SelectionBox)
1577  && isaddresscorrect(SelectionBox->Style)
1578  && isaddresscorrect(SelectionBox->Options)
1579  && isram(SelectionBox->SelectedIndex)
1580  && SelectionBox->NumberOfOptions > 1
1581  && oC_TGUI_Position_IsCorrect(Position)
1582  && Width > 0
1583  )
1584  {
1585  if(Active == false)
1586  {
1587  oC_TGUI_SetStyle(&SelectionBox->Style->NotActive);
1588  oC_TGUI_DrawAtPositionWithSize(Position,SelectionBox->Options[*SelectionBox->SelectedIndex],Width);
1589  }
1590  else
1591  {
1592  oC_TGUI_Column_t textWidth = Width - 2;
1593  oC_TGUI_Position_t textPosition = { .Column = Position.Column + 1 , .Line = Position.Line };
1594  oC_TGUI_Position_t rightArrowPosition = { .Column = textPosition.Column + textWidth , .Line = Position.Line };
1595 
1596  do
1597  {
1598  if(key == oC_TGUI_Key_ArrowLeft)
1599  {
1600  uint32_t selected = *SelectionBox->SelectedIndex;
1601  if( selected > 0 )
1602  {
1603  *SelectionBox->SelectedIndex = selected - 1;
1604  }
1605  }
1606  else if(key == oC_TGUI_Key_ArrowRight)
1607  {
1608  uint32_t selected = *SelectionBox->SelectedIndex;
1609  if( selected < (SelectionBox->NumberOfOptions - 1) )
1610  {
1611  *SelectionBox->SelectedIndex = selected + 1;
1612  }
1613  }
1614  else if(
1615  key == oC_TGUI_Key_ArrowDown ||
1616  key == oC_TGUI_Key_ArrowUp ||
1617  key == oC_TGUI_Key_Tab ||
1618  key == oC_TGUI_Key_Enter ||
1619  key == oC_TGUI_Key_ESC
1620  )
1621  {
1622  break;
1623  }
1624 
1625  oC_TGUI_SetStyle(&SelectionBox->Style->Arrow);
1626  oC_TGUI_DrawAtPosition(Position,"<");
1627  oC_TGUI_SetStyle(&SelectionBox->Style->Active);
1628  oC_TGUI_DrawAtPositionWithSize(textPosition,SelectionBox->Options[*SelectionBox->SelectedIndex],textWidth);
1629  oC_TGUI_SetStyle(&SelectionBox->Style->Arrow);
1630  oC_TGUI_DrawAtPosition(rightArrowPosition,">");
1631  } while(oC_TGUI_WaitForKeyPress(&key));
1632  }
1633  }
1634 
1635  return key;
1636 }
1637 
1638 //==========================================================================================================================================
1639 //==========================================================================================================================================
1640 oC_TGUI_Key_t oC_TGUI_DrawActiveObject( oC_TGUI_ActiveObject_t * ActiveObject , bool Active )
1641 {
1642  oC_TGUI_Key_t key = 0;
1643 
1644  if(isaddresscorrect(ActiveObject) && ActiveObject->Width > 0 && oC_TGUI_Position_IsCorrect(ActiveObject->Position))
1645  {
1646  if(isaddresscorrect(ActiveObject->LabelStyle) && ActiveObject->LabelStyle->DontDraw != true)
1647  {
1648  oC_TGUI_SetStyle(ActiveObject->LabelStyle);
1649  oC_TGUI_DrawAtPositionWithSize(ActiveObject->LabelPosition,ActiveObject->LabelText,ActiveObject->LabelWidth);
1650  }
1651  switch(ActiveObject->Type)
1652  {
1653  case oC_TGUI_ActiveObjecType_PushButton:
1654  key = oC_TGUI_DrawPushButton(ActiveObject->Position,ActiveObject->Width,ActiveObject->Height,&ActiveObject->PushButton,Active);
1655  break;
1656  case oC_TGUI_ActiveObjecType_EditBox:
1657  key = oC_TGUI_DrawEditBox(ActiveObject->Position,ActiveObject->Width,ActiveObject->Height,&ActiveObject->EditBox,Active);
1658  break;
1659  case oC_TGUI_ActiveObjecType_QuickEdit:
1660  key = oC_TGUI_DrawQuickEditBox(ActiveObject->Position,ActiveObject->Width,&ActiveObject->QuickEdit,Active);
1661  break;
1662  case oC_TGUI_ActiveObjecType_SelectionBox:
1663  key = oC_TGUI_DrawSelectionBox(ActiveObject->Position,ActiveObject->Width,&ActiveObject->SelectionBox,Active);
1664  break;
1665  }
1666  }
1667 
1668  return key;
1669 }
1670 
1671 //==========================================================================================================================================
1683 //==========================================================================================================================================
1684 bool oC_TGUI_DrawActiveObjects( oC_TGUI_ActiveObject_t * ActiveObjects, uint32_t NumberOfObjects )
1685 {
1686  bool success = false;
1687 
1688  if(isaddresscorrect(ActiveObjects) && NumberOfObjects > 0)
1689  {
1690  oC_TGUI_Key_t key = 0;
1691  oC_TGUI_ActiveObject_t * activeObject = ActiveObjects;
1692  oC_TGUI_ActiveObject_t * currentObject = NULL;
1693 
1694  do
1695  {
1696  for(uint32_t i = 0 ; i < NumberOfObjects ; i++)
1697  {
1698  oC_TGUI_DrawActiveObject(&ActiveObjects[i],false);
1699  }
1700 
1701  key = oC_TGUI_DrawActiveObject(activeObject,true);
1702 
1703  if(key == oC_TGUI_Key_ArrowUp)
1704  {
1705  activeObject = GetActiveObjectOnUp(ActiveObjects,NumberOfObjects,activeObject);
1706  }
1707  else if(key == oC_TGUI_Key_ArrowDown)
1708  {
1709  activeObject = GetActiveObjectOnDown(ActiveObjects,NumberOfObjects,activeObject);
1710  }
1711  else if(key == oC_TGUI_Key_ArrowLeft)
1712  {
1713  activeObject = GetActiveObjectOnLeft(ActiveObjects,NumberOfObjects,activeObject);
1714  }
1715  else if(key == oC_TGUI_Key_ArrowRight)
1716  {
1717  activeObject = GetActiveObjectOnRight(ActiveObjects,NumberOfObjects,activeObject);
1718  }
1719  else if(key == oC_TGUI_Key_Tab || key == oC_TGUI_Key_Enter)
1720  {
1721  currentObject = GetActiveObjectOnRight(ActiveObjects,NumberOfObjects,activeObject);
1722 
1723  if(currentObject == activeObject)
1724  {
1725  currentObject = GetActiveObjectOnDown(ActiveObjects,NumberOfObjects,activeObject);
1726  }
1727  if(currentObject == activeObject)
1728  {
1729  currentObject = &ActiveObjects[0];
1730  }
1731  activeObject = currentObject;
1732  }
1733  else if(key == oC_TGUI_Key_ESC)
1734  {
1735  break;
1736  }
1737  } while(key != 0);
1738 
1739  success = key != 0;
1740  }
1741 
1742  return success;
1743 }
1744 
1745 //==========================================================================================================================================
1746 //==========================================================================================================================================
1747 bool oC_TGUI_WaitForKeyPress( oC_TGUI_Key_t * outKey )
1748 {
1749  bool pressed = false;
1750  char buffer[30];
1751  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1752 
1753  memset(buffer,0,sizeof(buffer));
1754 
1755  if(oC_AssignErrorCode(&errorCode,oC_KPrint_ReadFromStdIn(oC_IoFlags_NoTimeout | oC_IoFlags_SleepWhileWaiting | oC_IoFlags_WaitForSomeElements , buffer , sizeof(buffer))))
1756  {
1757  pressed = true;
1758 
1759  if(isram(outKey))
1760  {
1761  if(buffer[0] == 13)
1762  {
1763  *outKey = oC_TGUI_Key_Enter;
1764  }
1765  else if(buffer[0] == 127)
1766  {
1767  *outKey = oC_TGUI_Key_Backspace;
1768  }
1769  else if(buffer[0] == 9)
1770  {
1771  *outKey = oC_TGUI_Key_Tab;
1772  }
1773  else if(buffer[0] == '\033')
1774  {
1775  *outKey = oC_TGUI_Key_SpecialKeysId +
1776  ((oC_TGUI_Key_t)buffer[1]) +
1777  ((oC_TGUI_Key_t)buffer[2]) +
1778  ((oC_TGUI_Key_t)buffer[3]) +
1779  ((oC_TGUI_Key_t)buffer[4]) +
1780  ((oC_TGUI_Key_t)buffer[5]);
1781  }
1782  else
1783  {
1784  *outKey = (oC_TGUI_Key_t)buffer[0];
1785  }
1786  }
1787  }
1788 
1789  return pressed;
1790 }
1791 
1792 //==========================================================================================================================================
1793 //==========================================================================================================================================
1794 bool oC_TGUI_CheckKeyPressed( oC_TGUI_Key_t * outKey )
1795 {
1796  bool pressed = false;
1797  char buffer[30];
1798  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1799 
1800  memset(buffer,0,sizeof(buffer));
1801 
1802  if(oC_AssignErrorCode(&errorCode,oC_KPrint_ReadFromStdIn(oC_IoFlags_WaitForSomeElements | oC_IoFlags_0sTimeout , buffer , sizeof(buffer))))
1803  {
1804  pressed = true;
1805 
1806  if(isram(outKey))
1807  {
1808  if(buffer[0] == 13)
1809  {
1810  *outKey = oC_TGUI_Key_Enter;
1811  }
1812  else if(buffer[0] == 127)
1813  {
1814  *outKey = oC_TGUI_Key_Backspace;
1815  }
1816  else if(buffer[0] == 9)
1817  {
1818  *outKey = oC_TGUI_Key_Tab;
1819  }
1820  else if(buffer[0] == '\033')
1821  {
1822  *outKey = oC_TGUI_Key_SpecialKeysId +
1823  ((oC_TGUI_Key_t)buffer[1]) +
1824  ((oC_TGUI_Key_t)buffer[2]) +
1825  ((oC_TGUI_Key_t)buffer[3]) +
1826  ((oC_TGUI_Key_t)buffer[4]) +
1827  ((oC_TGUI_Key_t)buffer[5]);
1828  }
1829  else
1830  {
1831  *outKey = (oC_TGUI_Key_t)buffer[0];
1832  }
1833  }
1834  }
1835 
1836  return pressed;
1837 }
1838 
1839 #undef _________________________________________FUNCTIONS_SECTION__________________________________________________________________________
1840 
1846 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
1847 
1848 //==========================================================================================================================================
1849 //==========================================================================================================================================
1850 static uint32_t GetIndexFromPosition( oC_TGUI_Position_t TopLeft , oC_TGUI_Position_t BottomRight , oC_TGUI_Position_t Position , const char * Buffer )
1851 {
1852  uint32_t index = 0;
1853  uint32_t strLength = strlen(Buffer);
1854  oC_TGUI_Position_t currentPosition = TopLeft;
1855 
1856  for(index = 0 ; index < strLength && oC_TGUI_Position_IsSmaller(currentPosition,BottomRight); index++)
1857  {
1858  if(oC_TGUI_Position_Compare(currentPosition,Position) >= 0 && isprint((int)Buffer[index]) )
1859  {
1860  break;
1861  }
1862  else if(Buffer[index] == '\n')
1863  {
1864  currentPosition.Line++;
1865  }
1866  else if(Buffer[index] == '\r')
1867  {
1868  currentPosition.Column = TopLeft.Column;
1869  }
1870  else
1871  {
1872  currentPosition = oC_TGUI_Position_Increment(TopLeft,BottomRight,currentPosition);
1873  }
1874  }
1875 
1876  return index;
1877 }
1878 
1879 //==========================================================================================================================================
1880 //==========================================================================================================================================
1881 static oC_TGUI_Position_t GetPositionFromIndex( oC_TGUI_Position_t TopLeft , oC_TGUI_Position_t BottomRight , const char * Buffer , uint32_t Index )
1882 {
1883  oC_TGUI_Position_t currentPosition = TopLeft;
1884  uint32_t bufferLength = strlen(Buffer);
1885 
1886  for(uint32_t i = 0 ; i < bufferLength && oC_TGUI_Position_IsSmaller(currentPosition,BottomRight) ; i++ )
1887  {
1888  if(Index == i)
1889  {
1890  break;
1891  }
1892  else if(Buffer[i] == '\n')
1893  {
1894  currentPosition.Line++;
1895  }
1896  else if(Buffer[i] == '\r')
1897  {
1898  currentPosition.Column = TopLeft.Column;
1899  }
1900  else
1901  {
1902  currentPosition = oC_TGUI_Position_Increment(TopLeft,BottomRight,currentPosition);
1903  }
1904  }
1905 
1906  return currentPosition;
1907 }
1908 
1909 //==========================================================================================================================================
1910 //==========================================================================================================================================
1911 static oC_TGUI_ActiveObject_t* GetActiveObjectOnRight( oC_TGUI_ActiveObject_t * Array , uint32_t Size , oC_TGUI_ActiveObject_t * ActiveObject )
1912 {
1913  oC_TGUI_ActiveObject_t* activeObject = ActiveObject;
1914 
1915  for(uint32_t i = 0; i < Size ;i++)
1916  {
1917  if(Array[i].Position.Line == activeObject->Position.Line && Array[i].Position.Column > ActiveObject->Position.Column)
1918  {
1919  if(activeObject == ActiveObject || Array[i].Position.Column < activeObject->Position.Column)
1920  {
1921  activeObject = &Array[i];
1922  }
1923  }
1924  }
1925 
1926  return activeObject;
1927 }
1928 
1929 //==========================================================================================================================================
1930 //==========================================================================================================================================
1931 static oC_TGUI_ActiveObject_t* GetActiveObjectOnLeft( oC_TGUI_ActiveObject_t * Array , uint32_t Size , oC_TGUI_ActiveObject_t * ActiveObject )
1932 {
1933  oC_TGUI_ActiveObject_t* activeObject = ActiveObject;
1934 
1935  for(uint32_t i = 0; i < Size ;i++)
1936  {
1937  if(Array[i].Position.Line == activeObject->Position.Line && Array[i].Position.Column < ActiveObject->Position.Column)
1938  {
1939  if(activeObject == ActiveObject || Array[i].Position.Column > activeObject->Position.Column)
1940  {
1941  activeObject = &Array[i];
1942  }
1943  }
1944  }
1945 
1946  return activeObject;
1947 }
1948 
1949 //==========================================================================================================================================
1950 //==========================================================================================================================================
1951 static oC_TGUI_ActiveObject_t* GetActiveObjectOnDown( oC_TGUI_ActiveObject_t * Array , uint32_t Size , oC_TGUI_ActiveObject_t * OldObject )
1952 {
1953  oC_TGUI_ActiveObject_t* selectedObject = OldObject;
1954 
1955  for(uint32_t i = 0; i < Size ;i++)
1956  {
1957  if(oC_TGUI_Position_IsLower(Array[i].Position,OldObject->Position))
1958  {
1959  if(oC_TGUI_Position_IsLower(selectedObject->Position,OldObject->Position))
1960  {
1961  if(oC_TGUI_Position_IsHigher(Array[i].Position,selectedObject->Position))
1962  {
1963  selectedObject = &Array[i];
1964  }
1965  else if(Array[i].Position.Line == selectedObject->Position.Line && oC_ABS(Array[i].Position.Column,OldObject->Position.Column) < oC_ABS(selectedObject->Position.Column,OldObject->Position.Column))
1966  {
1967  selectedObject = &Array[i];
1968  }
1969  }
1970  else
1971  {
1972  selectedObject = &Array[i];
1973  }
1974  }
1975  }
1976 
1977  return selectedObject;
1978 }
1979 
1980 //==========================================================================================================================================
1981 //==========================================================================================================================================
1982 static oC_TGUI_ActiveObject_t* GetActiveObjectOnUp( oC_TGUI_ActiveObject_t * Array , uint32_t Size , oC_TGUI_ActiveObject_t * OldObject )
1983 {
1984  oC_TGUI_ActiveObject_t* selectedObject = OldObject;
1985 
1986  for(uint32_t i = 0; i < Size ;i++)
1987  {
1988  if(oC_TGUI_Position_IsHigher(Array[i].Position,OldObject->Position))
1989  {
1990  if(oC_TGUI_Position_IsHigher(selectedObject->Position,OldObject->Position))
1991  {
1992  if(oC_TGUI_Position_IsLower(Array[i].Position,selectedObject->Position))
1993  {
1994  selectedObject = &Array[i];
1995  }
1996  else if(Array[i].Position.Line == selectedObject->Position.Line && oC_ABS(Array[i].Position.Column,OldObject->Position.Column) < oC_ABS(selectedObject->Position.Column,OldObject->Position.Column))
1997  {
1998  selectedObject = &Array[i];
1999  }
2000  }
2001  else
2002  {
2003  selectedObject = &Array[i];
2004  }
2005  }
2006  }
2007 
2008  return selectedObject;
2009 }
2010 
2011 
2012 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
2013 
oC_TGUI_Color_t NonActiveColor
Color of the not filled part of progress bar.
Definition: oc_tgui.h:276
Value of type uint32_t.
Definition: oc_tgui.h:548
Basic math operations.
static bool oC_Bits_AreBitsSetU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if all bits in field are set
Definition: oc_bits.h:884
FILE__DESCRIPTION
oC_TGUI_Style_t TextStyle
Style of the text inside the box.
Definition: oc_tgui.h:294
Default style for a text.
Definition: oc_tgui.h:180
Value of type string.
Definition: oc_tgui.h:555
Value of type char.
Definition: oc_tgui.h:554
Text will be bold
Definition: oc_tgui.h:181
oC_TGUI_MenuHandler_t Handler
Handler of function, that will be called, when the menu is selected.
Definition: oc_tgui.h:512
oC_TGUI_Line_t Line
Number of line.
Definition: oc_tgui.h:384
bool oC_TGUI_DrawActiveObjects(oC_TGUI_ActiveObject_t *ActiveObjects, uint32_t NumberOfObjects)
draws array of active objects and handles it
Definition: oc_tgui.c:1684
oC_TGUI_EntryIndex_t oC_TGUI_DrawMenu(oC_TGUI_Position_t TopLeft, oC_TGUI_Column_t Width, oC_TGUI_Line_t Height, const oC_TGUI_MenuEntry_t *MenuEntries, oC_TGUI_EntryIndex_t NumberOfEntries, const oC_TGUI_MenuStyle_t *Style)
draws a menu
Definition: oc_tgui.c:941
Tab key.
Definition: oc_tgui.h:100
Special value - minimum ID for special keys.
Definition: oc_tgui.h:103
#define oC_VT100_ERASE_SCREEN
Definition: oc_vt100.h:240
stores style of elements
Definition: oc_tgui.h:229
oC_TGUI_Style_t InsideStyle
Style of text inside.
Definition: oc_tgui.h:342
Style of the menu.
Definition: oc_tgui.h:529
oC_TGUI_Style_t BorderStyle
Style of the border.
Definition: oc_tgui.h:278
Foreground and background will be lighter.
Definition: oc_tgui.h:182
#define oC_VT100_RESET_DEVICE
Resets terminal.
Definition: oc_vt100.h:48
Value of type uint64_t.
Definition: oc_tgui.h:549
Text will blink.
Definition: oc_tgui.h:184
bool DontDraw
Additional field for TGUI functions.
Definition: oc_tgui.h:234
oC_TGUI_Color_t Background
Color of the background.
Definition: oc_tgui.h:231
oC_TGUI_Style_t BorderStyle
Style of the border (set DontDraw to true if you do not want it)
Definition: oc_tgui.h:295
oC_TGUI_Style_t ShadowStyle
Shadow (right down and right bottom)
Definition: oc_tgui.h:341
oC_TGUI_Color_t
stores terminal colors
Definition: oc_tgui.h:140
oC_TGUI_TextStyle_t
text attributes
Definition: oc_tgui.h:178
stores cursor position
Definition: oc_tgui.h:382
Arrow UP key.
Definition: oc_tgui.h:105
Invert foreground with background colors.
Definition: oc_tgui.h:185
oC_TGUI_Color_t ActiveColor
Color of the filled part of progress bar.
Definition: oc_tgui.h:277
oC_TGUI_Color_t Foreground
Color of the foreground.
Definition: oc_tgui.h:232
ENTER key.
Definition: oc_tgui.h:98
The file with interface for the GPIO driver.
Value of type float.
Definition: oc_tgui.h:552
ESC key.
Definition: oc_tgui.h:104
oC_TGUI_Style_t NotActiveEntry
Style of not selected item.
Definition: oc_tgui.h:532
style for box
Definition: oc_tgui.h:337
The file with helper macros for managing objects.
bool oC_TGUI_DrawBox(const char *Title, const char *TextInside, oC_TGUI_Position_t TopLeft, oC_TGUI_Column_t Width, oC_TGUI_Line_t Height, const oC_TGUI_BoxStyle_t *Style)
draws a box
Definition: oc_tgui.c:770
Arrow RIGHT key.
Definition: oc_tgui.h:107
uint32_t oC_ObjectControl_t
stores object control value
Definition: oc_object.h:141
oC_TGUI_Style_t Border
Style of border.
Definition: oc_tgui.h:533
style for text box
Definition: oc_tgui.h:292
oC_TGUI_MenuHandler_t OnHoverHandler
Handler of the function, that will be called, when the menu is hovered.
Definition: oc_tgui.h:514
style for progress bar
Definition: oc_tgui.h:274
Arrow LEFT key.
Definition: oc_tgui.h:108
The file with interface for kernel print operations.
oC_TGUI_Style_t BorderStyle
Style of the box border.
Definition: oc_tgui.h:339
oC_TGUI_TextStyle_t TextStyle
Text attributes (bold/underline,etc)
Definition: oc_tgui.h:233
#define oC_ABS(A, B)
Definition: oc_math.h:46
#define oC_VT100_SAVE_CURSOR_AND_ATTRS
Definition: oc_vt100.h:141
#define oC_VT100_BORDER_LU
Definition: oc_vt100.h:276
Value of type int32_t.
Definition: oc_tgui.h:550
bool oC_TGUI_ClearPartOfScreen(oC_TGUI_Position_t StartPosition, oC_TGUI_Column_t Width, oC_TGUI_Line_t Height, oC_TGUI_Color_t Color)
clears selected part of the screen
Definition: oc_tgui.c:468
Arrow DOWN key.
Definition: oc_tgui.h:106
oC_TGUI_Style_t ActiveEntry
Style of selected item.
Definition: oc_tgui.h:531
Value of type oC_UInt_t.
Definition: oc_tgui.h:547
The file with interface for TGUI.
int32_t oC_TGUI_EntryIndex_t
stores index for menu
Definition: oc_tgui.h:200
The file with interface for process mechanism.
The file with interface for string library.
#define oC_VT100_RESTORE_CURSOR_AND_ATTRS
Definition: oc_vt100.h:148
Definition of the null pointer.
Entry in menu.
Definition: oc_tgui.h:508
oC_TGUI_Style_t TitleStyle
Title style.
Definition: oc_tgui.h:340
bool oC_TGUI_ResetDevice(void)
function for reseting a terminal
Definition: oc_tgui.c:152
Text will be underlined.
Definition: oc_tgui.h:183
Value of type int64_t.
Definition: oc_tgui.h:551
uint16_t oC_TGUI_Column_t
stores column or width of terminal cursor position
Definition: oc_tgui.h:368
oC_TGUI_Key_t
stores pressed key
Definition: oc_tgui.h:96
#define oC_VT100_SET_CURSOR_HOME(ROW, COLUMN)
Definition: oc_vt100.h:77
Value of type double.
Definition: oc_tgui.h:553
Text will be hidden.
Definition: oc_tgui.h:186
oC_TGUI_Column_t Column
Number of column.
Definition: oc_tgui.h:385
Backspace key.
Definition: oc_tgui.h:99
uint16_t oC_TGUI_Line_t
stores line or height of terminal cursor position
Definition: oc_tgui.h:356
The file with standard input/output operations.
#define NULL
pointer to a zero
Definition: oc_null.h:37