void ConvolutionFilterCodeDialog::__TextBox_CaretPosition( TextBox& sender, int oldPos, int newPos ) { if ( sender == FilterCode_TextBox ) { String t = FilterCode_TextBox.Text(); line = 1; column = 1; for ( String::iterator i = t.Begin(); i < t.At( newPos ); i++ ) { if( *i == '\n') { ++line; column = 0; } ++column; } LineCol_Label.SetText( String().Format( "Line: %d Col: %d", line , column ) ); } }
String Scheduler::convertFromDayHourMinInDecimal(String timeDate) { // convert the timeDate from DayHourMin-Format into Decimal-Format // DAY : MON = 1, TUE = 2, WED = 3, THU = 4, FRI = 5, SAT = 6, SUN = 6 // HOUR : 00..23 // MIN : 00..60 // WED 10:27 -----> 31027 bool statusOk = true; String value; // Analyze the day if (timeDate.CompareN("MON", 3, 0) == 0) { value.Append("1"); } else if (timeDate.CompareN("TUE", 3, 0) == 0) { value.Append("2"); } else if (timeDate.CompareN("WED", 3, 0) == 0) { value.Append("3"); } else if (timeDate.CompareN("THU", 3, 0) == 0) { value.Append("4"); } else if (timeDate.CompareN("FRI", 3, 0) == 0) { value.Append("5"); } else if (timeDate.CompareN("SAT", 3, 0) == 0) { value.Append("6"); } else if (timeDate.CompareN("SUN", 3, 0) == 0) { value.Append("7"); } else { statusOk = false; } // Analyze the hour if (statusOk) { char td4 = timeDate.At(4), td5 = timeDate.At(5); if (isdigit(td4) && isdigit(td5)) { long val = (td4 - '0') * 10 + (td5 - '0'); if (val < 24) { value.Append(timeDate.SubString(4, 2)); } else { statusOk = false; } } else { statusOk = false; } } // Analyze the minutes if (statusOk) { char td7 = timeDate.At(7), td8 = timeDate.At(8); if (isdigit(td7) && isdigit(td8)) { long val = (td7 - '0') * 10 + (td8 - '0'); if (val < 60) { value.Append(timeDate.SubString(7, 2)); } else { statusOk = false; } } else { statusOk = false; } } if (statusOk) { return value; } else { return ""; } }
/// Loads from target file, using given root as root-element in the UI-hierarchy. bool UserInterface::LoadFromFile(String filePath, UIElement * root) { String fromFile = filePath; if (!fromFile.Contains(rootUIDir)){ fromFile = rootUIDir + fromFile; } char * data; int fileSize; std::fstream file; file.open(fromFile.c_str(), std::ios_base::in); // assert(file.is_open() && "Unable to open file in AppState::LoadUI"); if (!file.is_open()){ std::cout<<"\nUserInterface::LoadFromFile: Unable to open file: "<<fromFile; return false; } root->source = filePath; // Get size by seeking to end of file int start = (int) file.tellg(); file.seekg( 0, std::ios::end ); fileSize = (int) file.tellg(); // Allocate data array to required length data = new char [fileSize+5]; memset(data, 0, fileSize+5); // Go to beginning of file and read the data file.seekg( 0, std::ios::beg); file.read((char*) data, fileSize); // Close file stream file.close(); assert(!file.bad()); std::cout<<"\n====================================="; std::cout<<"\nBeginning parsing file "<<fromFile; // Dump data into handable format. String contents; contents = data; // Delete data delete[] data; data = NULL; List<String> lines = contents.GetLines(); for (int i = 0; i < lines.Size(); ++i) { ;// std::cout<<"\nLine "<<i<<lines[i]; } String str; UIElement * element = NULL; enum parsingState { NULL_STATE, MID_COMMENT, // For /* */ }; int parsingState = NULL_STATE; /// Default values that can be set when parsing int defaultAlignment = UIElement::NULL_ALIGNMENT; String defaultTexture = "default.png"; String defaultParent = "root"; String defaultRootFolder = ""; bool defaultScalability = true; bool defaultVisibility = true; bool defaultExitability = true; Vector4f defaultTextColor = Vector4f(0,0,0,1); float defaultSizeRatioY = 1.0f; float defaultSizeRatioX = 1.0f; float defaultPadding = 0.0f; float defaultTextSize = 1.0f; String defaultOnTrigger = ""; Vector2f defaultDivider = Vector2f(0.5f,0.5f); int defaultTextAlignment = UIElement::LEFT; #define ENSURE_NEXT_TOKEN if(tokens.Size() < 2){ assert(false && "argument token missing"); continue; }; #define NEXT_TOKEN (tokens[1]) #define SET_DEFAULTS {element->alignment = defaultAlignment;\ element->textureSource = defaultTexture;\ element->scalable = defaultScalability;\ element->text.color = defaultTextColor;\ element->sizeRatioY = defaultSizeRatioY;\ element->sizeRatioX = defaultSizeRatioX;\ element->padding = defaultPadding;\ element->textSizeRatio = defaultTextSize;\ element->onTrigger = defaultOnTrigger;\ element->fontSource = TextFont::defaultFontSource;\ element->visible = defaultVisibility;\ element->divider = defaultDivider;\ element->textAlignment = defaultTextAlignment;\ element->exitable = defaultExitability; \ } #define ADD_PREVIOUS_TO_UI_IF_NEEDED {\ if (element && element != root){\ bool addedOK = root->AddToParent(defaultParent, element);\ if (!addedOK)\ delete element;\ else\ element->CreateChildren();\ }\ element = NULL;\ } /// Read until done or too many errors! bool wasLastLine = false; std::cout<<"\nLines to parse: "<<lines.Size(); for (int i = 0; i < lines.Size(); ++i){ String line = lines[i]; // return true; if (i == 59){ std::cout<<"Shouga die gooha."; } // str = line; if (line.Length() < 1) continue; /// Manually parse the line using a few identifiers that can be relevant. List<String> tokens; int lastEvaluatedIndex = 0; List<char> stack; char last; char cChar; for (int l = 0; l < line.Length(); ++l){ cChar = line.At(l); // std::cout<<"\nChar at "<<l<<": int("<<(int)cChar<<") char: "<<cChar; switch(cChar) { // If not in a current stack, save as a separate word. case ' ': case '\t': case '\n': case '\r': case '\f': if (!stack.Size()){ // Add it. String t; for (int j = lastEvaluatedIndex; j < l; j++){ t += line.At(j); } t.RemoveInitialWhitespaces(); if (t.Length()) tokens.Add(t); lastEvaluatedIndex = l; } break; case '(': stack.Add(cChar); break; case ')': last = stack.Last(); assert(last == '('); stack.RemoveIndex(stack.Size()-1); break; default: ; } } // Add final word as needed. String tok; for (int j = lastEvaluatedIndex; j < line.Length(); j++){ tok += line.At(j); } tok.RemoveInitialWhitespaces(); if (tok.Length()) tokens.Add(tok); List<String> newTokens = TokenizeIgnore(line, " \n\r\t", "\""); List<String> strings = line.Tokenize("\""); String firstQuote, secondQuote, thirdQuote; if (strings.Size() >= 2) firstQuote = strings[1]; else if (tokens.Size() >= 2) firstQuote = tokens[1]; if (strings.Size() >= 3) secondQuote = strings[2]; else if (tokens.Size() >= 3) secondQuote = tokens[2]; if (strings.Size() >= 4) thirdQuote = strings[3]; if (tokens.Size() >= 4) thirdQuote = tokens[3]; // Print em for debug /* std::cout<<"\n"; for (int t = 0; t < tokens.Size(); ++t) std::cout<<"\nToken "<<t<<": "<<tokens[t] <<" "; */ // Old one using a regular tokenizer. // List<String> tokens = line.Tokenize(" \n\r\t\v\f"); if (tokens.Size() < 1) continue; String value; if (tokens.Size() > 1) value = tokens[1]; /* /// If we've got quotation marks on the line, try and parse them straight away into the second token. if (line.Contains("\"")){ List<String> tokens2 = line.Tokenize("\""); tokens[1] = tokens2[1]; } */ if (printDebug){ // std::cout<<"\nLine "<<std::setw(3)<<i<<": "<<line;; // std::cout<<"\n\tTokens: "<<tokens.Size(); } for (int t = 0; t < tokens.Size(); ++t){ String token = tokens[t]; token.SetComparisonMode(String::NOT_CASE_SENSITIVE); // for (int i = 0; i < token.Length(); ++i) // std::cout<<"\n"<<i<<": (int)"<<(int)token.c_str()[i]<<" (char)"<<token.c_str()[i]; if (token.Contains("\r")){ // std::cout<<"Token '\\r'! Skipping o-o"; continue; } // Evaluate some things first depending on the current parsing state else if (parsingState == MID_COMMENT){ if (token.Contains("*/")){ parsingState = NULL_STATE; continue; } continue; } // Regular parses else if (token.Contains("//")){ // Skip the rest of the line // Done by default at the end of these if-elseif-clauses break; } else if (token.Contains("/*")){ parsingState = MID_COMMENT; continue; } else if (token == "defaultAlignment"){ ENSURE_NEXT_TOKEN defaultAlignment = UIElement::GetAlignment(NEXT_TOKEN); } else if (token == "defaultTextAlignment") { ENSURE_NEXT_TOKEN defaultTextAlignment = UIElement::GetAlignment(value); } else if (token == "defaultTexture"){ ENSURE_NEXT_TOKEN String param = tokens[1]; param.SetComparisonMode(String::NOT_CASE_SENSITIVE); if (param == "NULL") defaultTexture = String(); else defaultTexture = param; } else if (token == "defaultOnTrigger"){ ENSURE_NEXT_TOKEN defaultOnTrigger = NEXT_TOKEN; } else if (token == "defaultParent" || token == "parent") { ADD_PREVIOUS_TO_UI_IF_NEEDED ENSURE_NEXT_TOKEN defaultParent = NEXT_TOKEN; } else if (token == "defaultScalability"){ ENSURE_NEXT_TOKEN defaultScalability = NEXT_TOKEN.ParseBool(); } else if (token == "defaultExitability") { defaultExitability = value.ParseBool(); } else if (token == "defaultDividerX") { ENSURE_NEXT_TOKEN defaultDivider.x = NEXT_TOKEN.ParseFloat(); } else if (token == "defaultVisibility"){ ENSURE_NEXT_TOKEN defaultVisibility = NEXT_TOKEN.ParseBool(); } else if (token == "defaultSizeRatioXY" || token == "defaultSizeRatio" || token == "defaultSizeXY" || token == "defaultSize") { if (tokens.Size() == 2){ defaultSizeRatioX = defaultSizeRatioY = tokens[1].ParseFloat(); } else if (tokens.Size() >= 3){ defaultSizeRatioX = tokens[1].ParseFloat(); defaultSizeRatioY = tokens[2].ParseFloat(); } } else if (token == "defaultSizeRatioY"){ ENSURE_NEXT_TOKEN defaultSizeRatioY = NEXT_TOKEN.ParseFloat(); } else if (token == "defaultSizeRatioX"){ ENSURE_NEXT_TOKEN defaultSizeRatioX = NEXT_TOKEN.ParseFloat(); } else if (token == "defaultPadding"){ ENSURE_NEXT_TOKEN defaultPadding = NEXT_TOKEN.ParseFloat(); } else if (token == "defaultTextSize"){ ENSURE_NEXT_TOKEN defaultTextSize = NEXT_TOKEN.ParseFloat(); } else if (token == "defaultTextColor") { // Hex detected! if (line.Contains("0x")) { defaultTextColor = Color::ColorByHexName(NEXT_TOKEN); } else { switch(tokens.Size()-1) { case 1: // Assume it's alpha and keep the other colors as usual defaultTextColor[3] = NEXT_TOKEN.ParseFloat(); break; case 4: defaultTextColor[3] = tokens[4].ParseFloat(); case 3: // Assume it's RGB defaultTextColor[0] = tokens[1].ParseFloat(); defaultTextColor[1] = tokens[2].ParseFloat(); defaultTextColor[2] = tokens[3].ParseFloat(); break; case 2: case 0: assert(false && "Irregular amount of tokens following \"defaultTextColor\"; 1 for alpha, 3 for RGB and 4 for RGBA."); break; } } } else if (token == "defaultRootFolder"){ ENSURE_NEXT_TOKEN defaultRootFolder = NEXT_TOKEN + "/"; if (NEXT_TOKEN == "NULL") defaultRootFolder = ""; } else if (token == "root"){ element = root; if (tokens.Size() > 1) element->name = firstQuote; } else if (token == "element" || token == "div"){ ADD_PREVIOUS_TO_UI_IF_NEEDED element = new UIElement(); if (tokens.Size() > 1) element->name = firstQuote; SET_DEFAULTS } else if (token == "Button"){ ADD_PREVIOUS_TO_UI_IF_NEEDED element = new UIButton(); if (tokens.Size() > 1){ element->name = firstQuote; /// Set the elements text and message default to it's name too, yo. element->activationMessage = element->text = element->name; } SET_DEFAULTS }
String Scheduler::CurrTimeDateInDecimal() { // CTimeDate = "Wed Apr 07 17:27:04 1999 // decimal = "199904071727" time_t now; time(&now); struct tm result; String cTimeDate; system::LocalTime(&now, &result); system::AscTime(&result, cTimeDate); bool statusOk = true; String value; // Analyze the year char td20 = cTimeDate.At(20), td21 = cTimeDate.At(21), td22 = cTimeDate.At(22), td23 = cTimeDate.At(23); if (isdigit(td20) && isdigit(td21) && isdigit(td22) && isdigit(td23)) { value.Append(cTimeDate.SubString(20, 4)); } else { statusOk = false; } // Analyze the month if (statusOk) { cTimeDate.ToUpper(); ; if (cTimeDate.CompareN("JAN", 3, 4) == 0) { value.Append("01"); } else if (cTimeDate.CompareN("FEB", 3, 4) == 0) { value.Append("02"); } else if (cTimeDate.CompareN("MAR", 3, 4) == 0) { value.Append("03"); } else if (cTimeDate.CompareN("APR", 3, 4) == 0) { value.Append("04"); } else if (cTimeDate.CompareN("MAY", 3, 4) == 0) { value.Append("05"); } else if (cTimeDate.CompareN("JUN", 3, 4) == 0) { value.Append("06"); } else if (cTimeDate.CompareN("JUL", 3, 4) == 0) { value.Append("07"); } else if (cTimeDate.CompareN("AUG", 3, 4) == 0) { value.Append("08"); } else if (cTimeDate.CompareN("SEP", 3, 4) == 0) { value.Append("09"); } else if (cTimeDate.CompareN("OCT", 3, 4) == 0) { value.Append("10"); } else if (cTimeDate.CompareN("NOV", 3, 4) == 0) { value.Append("11"); } else if (cTimeDate.CompareN("DEC", 3, 4) == 0) { value.Append("12"); } else { statusOk = false; } } // Analyze the day if (statusOk) { char td8 = cTimeDate.At(8), td9 = cTimeDate.At(9); if (isdigit(td8) && isdigit(td9)) { long val = (td8 - '0') * 10 + (td9 - '0'); if (val <= 31) { value.Append(cTimeDate.SubString(8, 2)); } else { statusOk = false; } } else { statusOk = false; } } // Analyze the hour if (statusOk) { char td11 = cTimeDate.At(11), td12 = cTimeDate.At(12); if (isdigit(td11) && isdigit(td12)) { long val = (td11 - '0') * 10 + (td12 - '0'); if (val < 24) { value.Append(cTimeDate.SubString(11, 2)); } else { statusOk = false; } } else { statusOk = false; } } // Analyze the min if (statusOk) { char td14 = cTimeDate.At(14), td15 = cTimeDate.At(15); if (isdigit(td14) && isdigit(td15)) { long val = (td14 - '0') * 10 + (td15 - '0'); if (val < 60) { value.Append(cTimeDate.SubString(14, 2)); } else { statusOk = false; } } else { statusOk = false; } } if (statusOk) { return value; } else { return ""; } }