|  | 
|  | 1 | +#include <iostream> | 
|  | 2 | +#include <string> | 
|  | 3 | + | 
|  | 4 | +#include <raylib.h> | 
|  | 5 | + | 
|  | 6 | +#include "./include/erebus.hpp" | 
|  | 7 | + | 
|  | 8 | +#define MAX_INPUT_CHARS 50 | 
|  | 9 | + | 
|  | 10 | +bool IsValidCharacter(int key) | 
|  | 11 | +{ | 
|  | 12 | +  return (key >= '0' && key <= '9') || // Numeric digits | 
|  | 13 | +         key == '/' || key == '-'; | 
|  | 14 | +} | 
|  | 15 | + | 
|  | 16 | +bool IsValidShiftCharacter(int key) | 
|  | 17 | +{ | 
|  | 18 | +  return key == '=' || key == '9' || key == '0' || key == '8' || key == '6'; | 
|  | 19 | +} | 
|  | 20 | + | 
|  | 21 | +int main() | 
|  | 22 | +{ | 
|  | 23 | +  const int screenWidth = 800; | 
|  | 24 | +  const int screenHeight = 450; | 
|  | 25 | + | 
|  | 26 | +  char buffer[MAX_INPUT_CHARS + 1] = "\0"; // Initialize name buffer | 
|  | 27 | +  int letterCount = 0; | 
|  | 28 | +  auto solver = Rori::Math::MathSolver(); | 
|  | 29 | + | 
|  | 30 | +  InitWindow(screenWidth, screenHeight, "Project Erebus"); | 
|  | 31 | + | 
|  | 32 | +  SetTargetFPS(60); | 
|  | 33 | + | 
|  | 34 | +  f64 result = 0; | 
|  | 35 | +  while (!WindowShouldClose()) | 
|  | 36 | +  { | 
|  | 37 | +    if (IsKeyPressed(KEY_BACKSPACE) && letterCount > 0) | 
|  | 38 | +    { | 
|  | 39 | +      letterCount--; | 
|  | 40 | +      buffer[letterCount] = '\0'; | 
|  | 41 | +    } | 
|  | 42 | +    else if (letterCount < MAX_INPUT_CHARS) | 
|  | 43 | +    { | 
|  | 44 | +      int key = GetKeyPressed(); | 
|  | 45 | +      if (IsValidShiftCharacter(key) && (IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT))) | 
|  | 46 | +      { | 
|  | 47 | +        std::cout << key << IsKeyDown(KEY_LEFT_SHIFT) << std::endl; | 
|  | 48 | +        if (key == '=') | 
|  | 49 | +        { | 
|  | 50 | +          buffer[letterCount] = '+'; | 
|  | 51 | +          letterCount++; | 
|  | 52 | +        } | 
|  | 53 | +        else if (key == '9') | 
|  | 54 | +        { | 
|  | 55 | +          buffer[letterCount] = '('; | 
|  | 56 | +          letterCount++; | 
|  | 57 | +        } | 
|  | 58 | +        else if (key == '0') | 
|  | 59 | +        { | 
|  | 60 | +          buffer[letterCount] = ')'; | 
|  | 61 | +          letterCount++; | 
|  | 62 | +        } | 
|  | 63 | +        else if (key == '8') | 
|  | 64 | +        { | 
|  | 65 | +          buffer[letterCount] = '*'; | 
|  | 66 | +          letterCount++; | 
|  | 67 | +        } | 
|  | 68 | +        else if (key == '6') | 
|  | 69 | +        { | 
|  | 70 | +          buffer[letterCount] = '^'; | 
|  | 71 | +          letterCount++; | 
|  | 72 | +        } | 
|  | 73 | +      } | 
|  | 74 | +      else if (IsValidCharacter(key)) | 
|  | 75 | +      { // Check if a valid key is pressed | 
|  | 76 | +        buffer[letterCount] = (char)key; | 
|  | 77 | +        letterCount++; | 
|  | 78 | +      } | 
|  | 79 | +      else if (IsKeyPressed(KEY_ENTER)) | 
|  | 80 | +      { | 
|  | 81 | +        std::cout << buffer << std::endl; | 
|  | 82 | +        auto [temp, err] = solver.evaluate(buffer); | 
|  | 83 | +        result = temp; | 
|  | 84 | +      } | 
|  | 85 | +    } | 
|  | 86 | + | 
|  | 87 | +    // Ensure text fits within the input box | 
|  | 88 | +    if (MeasureText(buffer, 20) > 760) | 
|  | 89 | +    { | 
|  | 90 | +      buffer[letterCount - 1] = '\0'; | 
|  | 91 | +      letterCount--; | 
|  | 92 | +    } | 
|  | 93 | + | 
|  | 94 | +    BeginDrawing(); | 
|  | 95 | + | 
|  | 96 | +    ClearBackground(RAYWHITE); | 
|  | 97 | + | 
|  | 98 | +    // Center the input box | 
|  | 99 | +    int boxWidth = 760;                        // Width of the input box | 
|  | 100 | +    int boxHeight = 30;                        // Height of the input box | 
|  | 101 | +    int boxX = (screenWidth - boxWidth) / 2;   // X coordinate to center the input box | 
|  | 102 | +    int boxY = (screenHeight - boxHeight) / 2; // Y coordinate to center the input box | 
|  | 103 | + | 
|  | 104 | +    DrawText("Enter Math Expression:", boxX, boxY - 40, 20, DARKGRAY); | 
|  | 105 | +    DrawRectangle(boxX, boxY, boxWidth, boxHeight, LIGHTGRAY); | 
|  | 106 | +    DrawRectangleLines(boxX, boxY, boxWidth, boxHeight, DARKGRAY); | 
|  | 107 | +    DrawText(TextSubtext(buffer, 0, MAX_INPUT_CHARS), boxX + 10, boxY + 10, 20, MAROON); | 
|  | 108 | + | 
|  | 109 | +    DrawText("Result:", boxX, boxY - 100, 20, DARKGRAY); | 
|  | 110 | +    std::string result2 = std::to_string(result); | 
|  | 111 | +    DrawText(result2.c_str(), boxX, boxY - 140, 20, DARKGRAY); | 
|  | 112 | + | 
|  | 113 | +    EndDrawing(); | 
|  | 114 | +  } | 
|  | 115 | + | 
|  | 116 | +  CloseWindow(); | 
|  | 117 | +} | 
0 commit comments