28 #include <oc_stdlib.h> 47 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 55 uint32_t MaximumValue;
56 uint32_t CurrentValue;
59 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 66 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 75 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 83 #define _________________________________________FUNCTIONS_SECTION__________________________________________________________________________ 90 int nameLength = strlen(Name);
92 oC_ARRAY_FOREACH_IN_ARRAY(oC_TGUI_Colors , colorData)
94 int tempLength = strlen(colorData->Name);
95 bool theSame = tempLength > 0 && nameLength > 0;
97 for(
int i = 0; i < tempLength && i < nameLength && theSame; i++)
99 if(isalnum((
int)colorData->Name[i]) && isalnum((
int)Name[i]))
101 if(tolower( (
int)colorData->Name[i]) != tolower((
int)Name[i]))
121 const char * name =
"unknown";
123 oC_ARRAY_FOREACH_IN_ARRAY(oC_TGUI_Colors , colorData)
125 if(colorData->Color == Color)
127 name = colorData->Name;
137 bool oC_TGUI_ClearScreen(
void )
167 bool success =
false;
169 if(isram(outCursorPosition))
172 printf(oC_VT100_SEQ_QUERY_CURSOR_POSITION);
173 scanf(oC_VT100_SEQ_REPORT_CURSOR_POSITION(
"%d",
"%d") , (
int*)&outCursorPosition->
Line , (
int*)&outCursorPosition->
Column);
183 bool success =
false;
184 uint16_t valueToPrint = 10;
186 if(oC_TGUI_Color_IsCorrect(Color))
188 valueToPrint += Color;
189 success = printf(
"\033[%dm" , valueToPrint) == 0;
199 bool success =
false;
200 uint16_t valueToPrint = 0;
202 if(oC_TGUI_Color_IsCorrect(Color))
205 valueToPrint += Color;
206 success = printf(
"\033[%dm" , valueToPrint) == 0;
232 return isaddresscorrect(Style) && oC_TGUI_SetForegroundColor(Style->
Foreground) && oC_TGUI_SetBackgroundColor(Style->
Background) && oC_TGUI_SetTextStyle(Style->
TextStyle);
237 bool oC_TGUI_SaveAttributes(
void )
243 bool oC_TGUI_RestoreAttributes (
void )
280 if(Position.
Line < BottomRight.
Line)
323 bool success =
false;
326 if(oC_TGUI_Position_IsCorrect(StartPosition) && oC_TGUI_Position_IsCorrect(EndPosition))
331 position = StartPosition;
335 success = oC_TGUI_DrawAtPosition(position,oC_VT100_BORDER_LR);
342 position = StartPosition;
344 while(position.
Line < EndPosition.
Line && success)
346 success = oC_TGUI_DrawAtPosition(position,oC_VT100_BORDER_UD);
359 bool success =
false;
363 oC_TGUI_Position_IsCorrect(TopLeft) &&
364 oC_TGUI_Position_IsCorrect(BottomRight) )
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 ) &&
376 oC_TGUI_DrawAtPosition( bottomLeft, oC_VT100_BORDER_UR );
386 return oC_TGUI_SetCursorPosition(StartPosition) && oC_KPrint_WriteToStdOut(oC_IoFlags_Default , String , strlen(String)) == 0;
391 bool oC_TGUI_DrawAtPositionWithSize (
oC_TGUI_Position_t StartPosition ,
const char * String ,
int Size )
393 bool success =
false;
395 if(oC_TGUI_SetCursorPosition(StartPosition))
397 int len = strlen(String);
399 oC_TGUI_DrawNCharAtPosition(StartPosition,
' ',Size);
400 oC_TGUI_SetCursorPosition(StartPosition);
401 oC_KPrint_WriteToStdOut(oC_IoFlags_Default , String , oC_MIN(len,Size));
412 return oC_TGUI_SetCursorPosition(StartPosition) && oC_KPrint_WriteToStdOut(oC_IoFlags_Default , &C , 1) == oC_ErrorCode_None;
419 bool success = oC_TGUI_SetCursorPosition(StartPosition);
421 for(
int i = 0; i < N && success ; i++)
423 success = oC_KPrint_WriteToStdOut(oC_IoFlags_Default , &C , 1) == oC_ErrorCode_None;
433 bool success =
false;
435 if(oC_TGUI_Position_IsCorrect(StartPosition) && oC_TGUI_Position_IsCorrect(EndPosition) &&
436 StartPosition.
Line <= EndPosition.
Line &&
444 while(position.
Line <= EndPosition.
Line && success)
446 success = oC_TGUI_DrawNCharAtPosition(position,C,width);
470 bool success =
false;
472 if(oC_TGUI_Position_IsCorrect(StartPosition) && Width > 0 && Height > 0)
475 success = oC_TGUI_SetBackgroundColor(Color) &&
476 oC_TGUI_DrawFillBetween(StartPosition,endPosition,
' ');
487 bool success =
false;
489 if(oC_TGUI_Position_IsCorrect(StartPosition) && oC_TGUI_Position_IsCorrect(EndPosition) && isaddresscorrect(String))
491 int stringLength = strlen(String);
494 success = oC_TGUI_SetCursorPosition(position);
496 for(
int characterIndex = 0 ; success && characterIndex < stringLength && position.
Line <= EndPosition.
Line; characterIndex++)
498 if(String[characterIndex] ==
'\r')
502 else if(String[characterIndex] ==
'\t')
504 success = oC_KPrint_WriteToStdOut(oC_IoFlags_Default,
" ",2) == oC_ErrorCode_None;
508 else if( String[characterIndex] ==
'\n' || position.
Column > EndPosition.
Column )
512 success = oC_TGUI_SetCursorPosition(position);
513 if(String[characterIndex] !=
'\n')
520 success = oC_KPrint_WriteToStdOut(oC_IoFlags_Default, AsPassword ?
"*" : &String[characterIndex],1) == oC_ErrorCode_None;
531 bool oC_TGUI_DrawFormatAtPosition(
oC_TGUI_Position_t StartPosition ,
const char * Format , ... )
533 bool success =
false;
534 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
536 if(oC_TGUI_Position_IsCorrect(StartPosition))
538 if(oC_TGUI_SetCursorPosition(StartPosition))
540 va_list argumentList;
541 va_start(argumentList, Format);
542 errorCode = vprintf(Format,argumentList);
543 va_end(argumentList);
544 success = oC_ErrorOccur(errorCode) ==
false;
556 if(oC_TGUI_Position_IsCorrect(TopLeft) && isram(Position) && Width > 0 && Height > 0 && isaddresscorrect(String) && isram(outIndex))
560 uint32_t strLength = strlen(String);
561 uint32_t signIndex = 0;
563 for(signIndex = 0; signIndex < strLength && position.
Line < bottomRight.
Line ; signIndex++)
567 *outIndex = signIndex;
572 if(String[signIndex] ==
'\n')
580 else if(String[signIndex] ==
'\r')
600 *outIndex = signIndex;
613 static const char string[] =
"/-\\|";
614 if(outSpiner->SignIndex >= (
sizeof(
string)-1))
616 outSpiner->SignIndex = 0;
618 oC_KPrint_WriteToStdOut(oC_Process_GetIoFlags(getcurprocess()),&
string[outSpiner->SignIndex],1);
619 outSpiner->SignIndex++;
627 bool success =
false;
629 if( oC_TGUI_Position_IsCorrect(Position) && Width > 8 && MaximumValue > 0 && CurrentValue <= MaximumValue && isaddresscorrect(Style) )
636 double loadedRatio = ((double)CurrentValue) / ((double)MaximumValue);
641 char percentString[10];
642 char * stringReference = percentString;
644 bottomRight.
Line += 2;
645 bottomRight.
Column += Width;
647 barPosition.
Line = topLeft.
Line + 1;
650 endColumn = barPosition.
Column + Width - 1;
651 barWidth = Width - 2;
653 loadedEndColumn = barPosition.
Column + loadedBarWidth;
654 stringBarColumn = barPosition.
Column + (barWidth / 2);
656 oC_TGUI_SaveAttributes();
659 memset(percentString,0,
sizeof(percentString));
661 sprintf_s(percentString,
sizeof(percentString),
"%5.1f%%" , loadedRatio * ((
double)100));
663 stringBarColumn -= strlen(percentString) / 2;
664 stringBarEndColumn = stringBarColumn + strlen(percentString);
668 success = success && oC_TGUI_SetStyle(&Style->
BorderStyle) &&
669 oC_TGUI_DrawBorder(topLeft,bottomRight);
674 while(success && barPosition.
Column < endColumn)
676 if(barPosition.
Column >= loadedEndColumn)
683 success = oC_TGUI_SetBackgroundColor(Style->
ActiveColor) &&
688 if(barPosition.
Column >= stringBarColumn && barPosition.
Column < stringBarEndColumn)
690 c = *stringReference;
694 success = success && oC_TGUI_DrawCharAtPosition(barPosition,c);
699 oC_TGUI_RestoreAttributes();
709 bool success =
false;
711 if(isaddresscorrect(String) && isaddresscorrect(Style) && oC_TGUI_Position_IsCorrect(Position))
713 int stringLength = strlen(String);
714 int stringToPrintLength = 0;
721 oC_TGUI_SaveAttributes();
723 FixedWidth = (FixedWidth == 0) ? stringLength + 2 : FixedWidth;
724 stringToPrintLength = FixedWidth - 2;
726 topRight.
Column += FixedWidth;
727 bottomLeft.
Line += 2;
731 stringPosition.
Line = topLeft.
Line + 1;
738 oC_TGUI_DrawBorder(topLeft,bottomRight);
742 success = oC_TGUI_SetStyle(&Style->
TextStyle) &&
743 oC_TGUI_DrawAtPositionWithSize(stringPosition , String , stringToPrintLength );
746 oC_TGUI_RestoreAttributes();
772 bool success =
false;
775 isaddresscorrect(Style) &&
777 oC_TGUI_Position_IsCorrect(TopLeft))
788 bottomRight.
Column += Width - 2;
789 bottomRight.
Line += Height - 2;
791 stringPosition.
Column += (Width / 2) - (strlen(Title) / 2);
794 shadowRightStart.
Line = TopLeft.
Line + 1;
796 shadowRightEnd.
Line = bottomRight.
Line + 1;
799 shadowBottomStart.
Line = bottomRight.
Line + 1;
801 shadowBottomEnd.
Line = shadowBottomStart.
Line;
804 insideTopLeft.
Line = TopLeft.
Line + 1;
806 insideBottomRight.
Line = bottomRight.
Line - 1;
808 oC_TGUI_SaveAttributes();
814 success = success && oC_TGUI_SetStyle(&Style->
BorderStyle) &&
815 oC_TGUI_DrawBorder(TopLeft,bottomRight);
820 success = success && oC_TGUI_SetStyle(&Style->
TitleStyle) &&
821 oC_TGUI_DrawAtPosition(stringPosition,Title);
827 oC_TGUI_DrawFillBetween(shadowRightStart,shadowRightEnd,
' ') &&
828 oC_TGUI_DrawFillBetween(shadowBottomStart,shadowBottomEnd,
' ');
833 success = success && oC_TGUI_SetStyle(&Style->
InsideStyle) &&
834 oC_TGUI_DrawFillBetween(insideTopLeft,insideBottomRight,
' ');
836 if(isaddresscorrect(TextInside))
838 success = success && oC_TGUI_DrawMultiLineText(insideTopLeft,insideBottomRight,TextInside,
false);
842 oC_TGUI_RestoreAttributes();
852 bool success =
false;
855 isaddresscorrect(Config) &&
856 isaddresscorrect(Config->Style) &&
857 isaddresscorrect(Config->Properties) &&
858 oC_TGUI_Position_IsCorrect(Config->StartPosition) &&
859 Config->Height > 0 &&
861 Config->DescriptionWidth > 0 &&
862 Config->NumberOfProperties > 0 &&
863 Config->DescriptionWidth < Config->Width
874 for(position = Config->StartPosition , entryIndex = 0 ; position.
Line < bottomRight.
Line && success ; position.
Line++ , entryIndex++)
876 if(entryIndex < Config->NumberOfProperties)
879 if(Config->Style->DescriptionStyle.
DontDraw !=
true)
881 success = success && oC_TGUI_SetStyle(&Config->Style->DescriptionStyle) &&
882 oC_TGUI_DrawAtPositionWithSize(position,Config->Properties[entryIndex].Description,Config->DescriptionWidth);
885 if(Config->Style->ValueStyle.
DontDraw !=
true)
887 success = success &&oC_TGUI_SetStyle(&Config->Style->ValueStyle);
889 valuePosition = position;
890 valuePosition.
Column += Config->DescriptionWidth;
892 switch(Config->Properties[entryIndex].Type)
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;
904 oC_TGUI_DrawAtPositionWithSize(valuePosition,
"INCORRECT TYPE!",Config->Width - Config->DescriptionWidth);
911 oC_TGUI_SetStyle(&Config->Style->DescriptionStyle);
912 oC_TGUI_DrawNCharAtPosition(position,
' ', Config->Width);
945 if(oC_TGUI_Position_IsCorrect(TopLeft) && Width > 0 && Height > 0 && isaddresscorrect(MenuEntries) && NumberOfEntries > 0 && isaddresscorrect(Style))
952 success = success && oC_TGUI_SetStyle(&Style->
Border) &&
953 oC_TGUI_DrawBorder(TopLeft,bottomRight);
978 if(selectedIndex < lastIndex)
980 if( selectedIndex == displayedLastIndex
981 && numberOfEntriesOnScreen < NumberOfEntries
982 && displayedLastIndex < lastIndex
985 displayedStartIndex++;
986 displayedLastIndex++;
993 displayedStartIndex = 0;
994 displayedLastIndex = numberOfEntriesOnScreen;
999 if(selectedIndex > 0)
1001 if( selectedIndex == displayedStartIndex
1002 && numberOfEntriesOnScreen < NumberOfEntries
1003 && displayedStartIndex > 0
1006 displayedStartIndex--;
1007 displayedLastIndex--;
1013 selectedIndex = lastIndex;
1014 displayedLastIndex = lastIndex;
1015 displayedStartIndex = lastIndex - numberOfEntriesOnScreen + 1;
1020 if(selectedIndex >= 0 && selectedIndex < NumberOfEntries)
1022 if(isaddresscorrect(MenuEntries[selectedIndex].Handler))
1024 MenuEntries[selectedIndex].
Handler(MenuEntries[selectedIndex].Parameter);
1034 selectedIndex = NumberOfEntries;
1039 for(position = TopLeft , entryIndex = displayedStartIndex ; position.
Line <= bottomRight.
Line; position.
Line++ , entryIndex++)
1041 if(entryIndex < NumberOfEntries)
1043 if(entryIndex == selectedIndex)
1047 if(isaddresscorrect(MenuEntries[entryIndex].OnHoverHandler))
1049 MenuEntries[selectedIndex].
OnHoverHandler(MenuEntries[selectedIndex].OnHoverParameter);
1057 oC_TGUI_DrawAtPositionWithSize(position,MenuEntries[entryIndex].Title,Width);
1062 oC_TGUI_DrawNCharAtPosition(position,
' ',Width);
1066 while(oC_TGUI_WaitForKeyPress(&key));
1070 return selectedIndex;
1077 bool success =
false;
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)
1097 uint32_t elementsCount = oC_List_Count(Config->List);
1102 uint32_t onScreenCount = 0;
1108 success = success && oC_TGUI_SetStyle(&Config->Style->
Border) &&
1109 oC_TGUI_DrawBorder(topLeft,bottomRight);
1118 onScreenCount = height;
1120 if(onScreenCount < elementsCount)
1122 lastToDisplay = List_ElementOfIndex(Config->List,onScreenCount - 1);
1131 if(selected != first)
1134 selected == firstToDisplay &&
1135 elementsCount > onScreenCount &&
1136 firstToDisplay != first
1139 firstToDisplay = oC_List_ElementHandle_Previous(firstToDisplay);
1140 lastToDisplay = oC_List_ElementHandle_Previous(lastToDisplay);
1142 selected = oC_List_ElementHandle_Previous(selected);
1147 while(lastToDisplay != last && lastToDisplay !=
NULL)
1149 lastToDisplay = oC_List_ElementHandle_Next(lastToDisplay);
1150 firstToDisplay = oC_List_ElementHandle_Next(firstToDisplay);
1156 if(selected != last)
1159 selected == lastToDisplay &&
1160 elementsCount > onScreenCount &&
1161 lastToDisplay != last
1164 firstToDisplay = oC_List_ElementHandle_Next(firstToDisplay);
1165 lastToDisplay = oC_List_ElementHandle_Next(lastToDisplay);
1167 selected = oC_List_ElementHandle_Next(selected);
1172 while(firstToDisplay != first && firstToDisplay !=
NULL)
1174 lastToDisplay = oC_List_ElementHandle_Previous(lastToDisplay);
1175 firstToDisplay = oC_List_ElementHandle_Previous(firstToDisplay);
1181 if(isaddresscorrect(Config->SelectHandler))
1183 Config->SelectHandler(selected);
1192 for(element = firstToDisplay , position = topLeft; position.
Line <= bottomRight.
Line ; position.
Line++)
1196 if(element == selected)
1205 oC_TGUI_DrawNCharAtPosition(position,
' ',width);
1206 oC_TGUI_SetCursorPosition(position);
1207 Config->DrawHandler(position,element,width);
1209 element = oC_List_ElementHandle_Next(element);
1214 oC_TGUI_DrawNCharAtPosition(position,
' ',width);
1217 }
while(oC_TGUI_WaitForKeyPress(&key));
1229 bool success =
false;
1231 if(oC_TGUI_Position_IsCorrect(Position) && Width > 0 && Height > 0 && isaddresscorrect(PushButton) && isaddresscorrect(PushButton->Text) && isaddresscorrect(PushButton->Style))
1235 uint32_t textLength = strlen(PushButton->Text);
1241 if(PushButton->Style->ActiveBorder.
DontDraw !=
true)
1243 success = success && oC_TGUI_SetStyle(&PushButton->Style->ActiveBorder) &&
1244 oC_TGUI_DrawBorder(topLeft,bottomRight);
1253 textPosition.
Column = topLeft.
Column + (Width/2) - (textLength/2);
1259 success = success && oC_TGUI_SetStyle(&PushButton->Style->Active);
1263 success = success && oC_TGUI_SetStyle(&PushButton->Style->NotActive);
1266 success = success && oC_TGUI_DrawNCharAtPosition(topLeft,
' ',Width) &&
1267 oC_TGUI_DrawAtPosition(textPosition,PushButton->Text);
1271 while(oC_TGUI_WaitForKeyPress(&key))
1275 if(isaddresscorrect(PushButton->PressHandler))
1277 if(PushButton->PressHandler(PushButton->PressParameter))
1311 if(oC_TGUI_Position_IsCorrect(Position) && Width >= 3 && Height > 0 &&
1312 isaddresscorrect(EditBox) && isram(EditBox->Buffer) && EditBox->BufferSize > 0 &&
1313 isaddresscorrect(EditBox->Style))
1322 uint32_t signIndex = strlen(EditBox->Buffer);
1323 uint32_t maxStringLength = EditBox->BufferSize - 1;
1327 if((EditBox->Style->NotActiveBorder.
DontDraw !=
true && Active ==
false) ||
1328 (EditBox->Style->ActiveBorder.
DontDraw !=
true && Active ==
true ) )
1330 oC_TGUI_SetStyle(Active ? &EditBox->Style->ActiveBorder : &EditBox->Style->NotActiveBorder);
1331 oC_TGUI_DrawBorder(borderTopLeft,borderBottomRight);
1337 insideTopLeft = topLeft;
1338 insideBottomRight = bottomRight;
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));
1348 bool activated =
false;
1352 if(activated ==
false)
1369 if(activated ==
true)
1373 if(isaddresscorrect(EditBox->SaveHandler))
1375 EditBox->SaveHandler(EditBox->Buffer,EditBox->BufferSize,EditBox->SaveParameter);
1381 if(cursorPosition.
Line > insideTopLeft.
Line)
1383 cursorPosition.
Line--;
1384 signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,EditBox->Buffer);
1385 cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,EditBox->Buffer,signIndex);
1390 if(cursorPosition.
Line < insideBottomRight.
Line)
1392 cursorPosition.
Line++;
1393 signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,EditBox->Buffer);
1394 cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,EditBox->Buffer,signIndex);
1402 signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,EditBox->Buffer);
1403 cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,EditBox->Buffer,signIndex);
1411 signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,EditBox->Buffer);
1412 cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,EditBox->Buffer,signIndex);
1417 signIndex = string_backspace(EditBox->Buffer,signIndex);
1418 cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,EditBox->Buffer,signIndex);
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);
1429 else if(isprint((
int)key) && signIndex < maxStringLength && (cursorPosition.
Line < insideBottomRight.
Line || cursorPosition.
Column < insideBottomRight.
Column))
1434 (
oC_Bits_AreBitsSetU32(EditBox->InputType,oC_TGUI_InputType_SpecialChars) && (isgraph((
int)key) || isspace((
int)key)))
1437 signIndex = put_to_string(EditBox->Buffer,EditBox->BufferSize,signIndex,(
char)key);
1438 cursorPosition = oC_TGUI_Position_Increment(insideTopLeft,insideBottomRight,cursorPosition);
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);
1447 }
while(oC_TGUI_WaitForKeyPress(&key));
1461 if(oC_TGUI_Position_IsCorrect(Position) && Width > 0 && isram(QuickEditBox) && isram(QuickEditBox->Buffer) && QuickEditBox->BufferSize > 0 && isaddresscorrect(QuickEditBox->Style))
1472 if((QuickEditBox->Style->NotActiveBorder.
DontDraw !=
true && Active ==
false) ||
1473 (QuickEditBox->Style->ActiveBorder.
DontDraw !=
true && Active ==
true ) )
1475 oC_TGUI_SetStyle(Active ? &QuickEditBox->Style->ActiveBorder : &QuickEditBox->Style->NotActiveBorder);
1476 oC_TGUI_DrawBorder(borderTopLeft,borderBottomRight);
1479 insideBottomRight.
Column--;
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));
1489 uint32_t maxStringLength = QuickEditBox->BufferSize - 1;
1490 uint32_t signIndex = strlen(QuickEditBox->Buffer);
1492 cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,QuickEditBox->Buffer,signIndex);
1505 if(isaddresscorrect(QuickEditBox->SaveHandler))
1507 QuickEditBox->SaveHandler(QuickEditBox->Buffer,QuickEditBox->BufferSize,QuickEditBox->SaveParameter);
1516 if(cursorPosition.
Column < insideBottomRight.
Column && signIndex < strlen(QuickEditBox->Buffer))
1519 signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,QuickEditBox->Buffer);
1520 cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,QuickEditBox->Buffer,signIndex);
1532 signIndex = GetIndexFromPosition(insideTopLeft,insideBottomRight,cursorPosition,QuickEditBox->Buffer);
1533 cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,QuickEditBox->Buffer,signIndex);
1542 signIndex = string_backspace(QuickEditBox->Buffer,signIndex);
1543 cursorPosition = GetPositionFromIndex(insideTopLeft,insideBottomRight,QuickEditBox->Buffer,signIndex);
1545 else if(isprint((
int)key) && signIndex < maxStringLength && (cursorPosition.
Line < insideBottomRight.
Line || cursorPosition.
Column < insideBottomRight.
Column))
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)))
1553 signIndex = put_to_string(QuickEditBox->Buffer,QuickEditBox->BufferSize,signIndex,(
char)key);
1554 cursorPosition = oC_TGUI_Position_Increment(insideTopLeft,insideBottomRight,cursorPosition);
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));
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)
1587 oC_TGUI_SetStyle(&SelectionBox->Style->NotActive);
1588 oC_TGUI_DrawAtPositionWithSize(Position,SelectionBox->Options[*SelectionBox->SelectedIndex],Width);
1600 uint32_t selected = *SelectionBox->SelectedIndex;
1603 *SelectionBox->SelectedIndex = selected - 1;
1608 uint32_t selected = *SelectionBox->SelectedIndex;
1609 if( selected < (SelectionBox->NumberOfOptions - 1) )
1611 *SelectionBox->SelectedIndex = selected + 1;
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));
1644 if(isaddresscorrect(ActiveObject) && ActiveObject->Width > 0 && oC_TGUI_Position_IsCorrect(ActiveObject->Position))
1646 if(isaddresscorrect(ActiveObject->LabelStyle) && ActiveObject->LabelStyle->
DontDraw !=
true)
1648 oC_TGUI_SetStyle(ActiveObject->LabelStyle);
1649 oC_TGUI_DrawAtPositionWithSize(ActiveObject->LabelPosition,ActiveObject->LabelText,ActiveObject->LabelWidth);
1651 switch(ActiveObject->Type)
1653 case oC_TGUI_ActiveObjecType_PushButton:
1654 key = oC_TGUI_DrawPushButton(ActiveObject->Position,ActiveObject->Width,ActiveObject->Height,&ActiveObject->PushButton,Active);
1656 case oC_TGUI_ActiveObjecType_EditBox:
1657 key = oC_TGUI_DrawEditBox(ActiveObject->Position,ActiveObject->Width,ActiveObject->Height,&ActiveObject->EditBox,Active);
1659 case oC_TGUI_ActiveObjecType_QuickEdit:
1660 key = oC_TGUI_DrawQuickEditBox(ActiveObject->Position,ActiveObject->Width,&ActiveObject->QuickEdit,Active);
1662 case oC_TGUI_ActiveObjecType_SelectionBox:
1663 key = oC_TGUI_DrawSelectionBox(ActiveObject->Position,ActiveObject->Width,&ActiveObject->SelectionBox,Active);
1686 bool success =
false;
1688 if(isaddresscorrect(ActiveObjects) && NumberOfObjects > 0)
1696 for(uint32_t i = 0 ; i < NumberOfObjects ; i++)
1698 oC_TGUI_DrawActiveObject(&ActiveObjects[i],
false);
1701 key = oC_TGUI_DrawActiveObject(activeObject,
true);
1705 activeObject = GetActiveObjectOnUp(ActiveObjects,NumberOfObjects,activeObject);
1709 activeObject = GetActiveObjectOnDown(ActiveObjects,NumberOfObjects,activeObject);
1713 activeObject = GetActiveObjectOnLeft(ActiveObjects,NumberOfObjects,activeObject);
1717 activeObject = GetActiveObjectOnRight(ActiveObjects,NumberOfObjects,activeObject);
1721 currentObject = GetActiveObjectOnRight(ActiveObjects,NumberOfObjects,activeObject);
1723 if(currentObject == activeObject)
1725 currentObject = GetActiveObjectOnDown(ActiveObjects,NumberOfObjects,activeObject);
1727 if(currentObject == activeObject)
1729 currentObject = &ActiveObjects[0];
1731 activeObject = currentObject;
1749 bool pressed =
false;
1751 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1753 memset(buffer,0,
sizeof(buffer));
1755 if(oC_AssignErrorCode(&errorCode,oC_KPrint_ReadFromStdIn(oC_IoFlags_NoTimeout | oC_IoFlags_SleepWhileWaiting | oC_IoFlags_WaitForSomeElements , buffer ,
sizeof(buffer))))
1765 else if(buffer[0] == 127)
1769 else if(buffer[0] == 9)
1773 else if(buffer[0] ==
'\033')
1796 bool pressed =
false;
1798 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1800 memset(buffer,0,
sizeof(buffer));
1802 if(oC_AssignErrorCode(&errorCode,oC_KPrint_ReadFromStdIn(oC_IoFlags_WaitForSomeElements | oC_IoFlags_0sTimeout , buffer ,
sizeof(buffer))))
1812 else if(buffer[0] == 127)
1816 else if(buffer[0] == 9)
1820 else if(buffer[0] ==
'\033')
1839 #undef _________________________________________FUNCTIONS_SECTION__________________________________________________________________________ 1846 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 1853 uint32_t strLength = strlen(Buffer);
1856 for(index = 0 ; index < strLength && oC_TGUI_Position_IsSmaller(currentPosition,BottomRight); index++)
1858 if(oC_TGUI_Position_Compare(currentPosition,Position) >= 0 && isprint((
int)Buffer[index]) )
1862 else if(Buffer[index] ==
'\n')
1864 currentPosition.
Line++;
1866 else if(Buffer[index] ==
'\r')
1872 currentPosition = oC_TGUI_Position_Increment(TopLeft,BottomRight,currentPosition);
1884 uint32_t bufferLength = strlen(Buffer);
1886 for(uint32_t i = 0 ; i < bufferLength && oC_TGUI_Position_IsSmaller(currentPosition,BottomRight) ; i++ )
1892 else if(Buffer[i] ==
'\n')
1894 currentPosition.
Line++;
1896 else if(Buffer[i] ==
'\r')
1902 currentPosition = oC_TGUI_Position_Increment(TopLeft,BottomRight,currentPosition);
1906 return currentPosition;
1915 for(uint32_t i = 0; i < Size ;i++)
1917 if(Array[i].Position.
Line == activeObject->Position.
Line && Array[i].Position.
Column > ActiveObject->Position.
Column)
1919 if(activeObject == ActiveObject || Array[i].Position.
Column < activeObject->Position.
Column)
1921 activeObject = &Array[i];
1926 return activeObject;
1935 for(uint32_t i = 0; i < Size ;i++)
1937 if(Array[i].Position.
Line == activeObject->Position.
Line && Array[i].Position.
Column < ActiveObject->Position.
Column)
1939 if(activeObject == ActiveObject || Array[i].Position.
Column > activeObject->Position.
Column)
1941 activeObject = &Array[i];
1946 return activeObject;
1955 for(uint32_t i = 0; i < Size ;i++)
1957 if(oC_TGUI_Position_IsLower(Array[i].Position,OldObject->Position))
1959 if(oC_TGUI_Position_IsLower(selectedObject->Position,OldObject->Position))
1961 if(oC_TGUI_Position_IsHigher(Array[i].Position,selectedObject->Position))
1963 selectedObject = &Array[i];
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))
1967 selectedObject = &Array[i];
1972 selectedObject = &Array[i];
1977 return selectedObject;
1986 for(uint32_t i = 0; i < Size ;i++)
1988 if(oC_TGUI_Position_IsHigher(Array[i].Position,OldObject->Position))
1990 if(oC_TGUI_Position_IsHigher(selectedObject->Position,OldObject->Position))
1992 if(oC_TGUI_Position_IsLower(Array[i].Position,selectedObject->Position))
1994 selectedObject = &Array[i];
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))
1998 selectedObject = &Array[i];
2003 selectedObject = &Array[i];
2008 return selectedObject;
2012 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ oC_TGUI_Color_t NonActiveColor
Color of the not filled part of progress bar.
static bool oC_Bits_AreBitsSetU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if all bits in field are set
oC_TGUI_Style_t TextStyle
Style of the text inside the box.
Default style for a text.
oC_TGUI_Line_t Line
Number of line.
bool oC_TGUI_DrawActiveObjects(oC_TGUI_ActiveObject_t *ActiveObjects, uint32_t NumberOfObjects)
draws array of active objects and handles it
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
Special value - minimum ID for special keys.
#define oC_VT100_ERASE_SCREEN
oC_TGUI_Style_t InsideStyle
Style of text inside.
oC_TGUI_Style_t BorderStyle
Style of the border.
Foreground and background will be lighter.
#define oC_VT100_RESET_DEVICE
Resets terminal.
bool DontDraw
Additional field for TGUI functions.
oC_TGUI_Color_t Background
Color of the background.
oC_TGUI_Style_t BorderStyle
Style of the border (set DontDraw to true if you do not want it)
oC_TGUI_Style_t ShadowStyle
Shadow (right down and right bottom)
oC_TGUI_Color_t
stores terminal colors
oC_TGUI_TextStyle_t
text attributes
Invert foreground with background colors.
oC_TGUI_Color_t ActiveColor
Color of the filled part of progress bar.
oC_TGUI_Color_t Foreground
Color of the foreground.
The file with interface for the GPIO driver.
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
uint32_t oC_ObjectControl_t
stores object control value
The file with interface for kernel print operations.
oC_TGUI_Style_t BorderStyle
Style of the box border.
oC_TGUI_TextStyle_t TextStyle
Text attributes (bold/underline,etc)
#define oC_VT100_SAVE_CURSOR_AND_ATTRS
#define oC_VT100_BORDER_LU
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
The file with interface for TGUI.
int32_t oC_TGUI_EntryIndex_t
stores index for menu
The file with interface for process mechanism.
The file with interface for string library.
#define oC_VT100_RESTORE_CURSOR_AND_ATTRS
Definition of the null pointer.
oC_TGUI_Style_t TitleStyle
Title style.
bool oC_TGUI_ResetDevice(void)
function for reseting a terminal
uint16_t oC_TGUI_Column_t
stores column or width of terminal cursor position
oC_TGUI_Key_t
stores pressed key
#define oC_VT100_SET_CURSOR_HOME(ROW, COLUMN)
oC_TGUI_Column_t Column
Number of column.
uint16_t oC_TGUI_Line_t
stores line or height of terminal cursor position
The file with standard input/output operations.
#define NULL
pointer to a zero