aboutsummaryrefslogtreecommitdiff
path: root/src/main.odin
diff options
context:
space:
mode:
authorSan Jacobs2023-05-21 02:17:58 +0200
committerSan Jacobs2023-05-21 02:17:58 +0200
commit552c805955200e0efcb4ad67f6275e5a45e8cd94 (patch)
tree1a913070f557fc27b42baa2e36654b684bfa6756 /src/main.odin
parentaa30ad678345e28afc7b7a5431844bd60424ef7e (diff)
downloadsatscalc-552c805955200e0efcb4ad67f6275e5a45e8cd94.tar.gz
satscalc-552c805955200e0efcb4ad67f6275e5a45e8cd94.tar.bz2
satscalc-552c805955200e0efcb4ad67f6275e5a45e8cd94.zip
🪟 GUI WORK HAS STARTED 🪟
We have a window, and it displays some information!
Diffstat (limited to 'src/main.odin')
-rw-r--r--src/main.odin172
1 files changed, 102 insertions, 70 deletions
diff --git a/src/main.odin b/src/main.odin
index fc7b7b8..6c7753d 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -1,80 +1,112 @@
package main
import "core:fmt"
+import "core:math"
+import "core:strings"
+import rl "vendor:raylib"
main :: proc() {
- //test()
- workday: = new_workday({10, 22, 4, 5, 2023},
+
+ workdays: [dynamic]^Workday
+
+ default_workday: = new_workday({10, 22, 4, 5, 2023},
{00, 08, 5, 5, 2023},
- {00, 05, 6, 5, 2023},
+ {00, 22, 6, 5, 2023},
{30, 21, 5, 5, 2023})
- //lunch(&workday, {00, 16, 5, 5, 2023}, {00, 17, 5, 5, 2023})
- lunch(&workday, {00, 12, 5, 5, 2023}, {45, 22, 5, 5, 2023})
- //lunch(&workday, {00, 12, 5, 5, 2023}, {30, 12, 5, 5, 2023})
- //lunch(&workday, {30, 16, 5, 5, 2023}, {30, 17, 5, 5, 2023})
- //lunch(&workday, {30, 19, 5, 5, 2023}, {30, 22, 5, 5, 2023})
- for each_block, i in workday.blocks {
- fmt.printf("Block %2i: %s $f: %i%% %s\n", i+1, toString(each_block), int((each_block.value-1)*100), each_block.reason)
+
+ append(&workdays, &default_workday)
+ append(&workdays, &default_workday)
+ append(&workdays, &default_workday)
+ append(&workdays, &default_workday)
+
+ call_text: cstring = "noffin"
+ wrap_text: cstring = "noffin"
+ total_sum: cstring = "3500 NOK + 26%"
+ inc_soc: cstring = "4276 NOK"
+ text_height: f32
+
+
+ using rl
+ width: i32 = 500
+ height: i32 = 400
+ InitWindow(width, height, "satscalc")
+ SetTargetFPS(60)
+ SetWindowState({.WINDOW_RESIZABLE})
+ SetWindowMinSize(width, height)
+
+ font_size :: 18
+ font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", font_size, nil, 0)
+
+ small_font_size :: 14
+ small_font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", small_font_size, nil, 0)
+
+ big_font_size :: 24
+ big_font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", big_font_size, nil, 0)
+
+ for !WindowShouldClose() {
+
+ if IsWindowResized() {
+ height = GetScreenHeight()
+ width = GetScreenWidth()
+ fmt.println("Resized to:", width, 'x', height)
+ }
+
+
+ // TODO: Find a good way to calculate the size and location
+ // of all the timeblocks in every day.
+ //
+ // I know I want them to scale with the window, and
+ // that the width of them should be normalized.
+ // If you add a day that lasts until 4 AM the morning
+ // after, all the other days should scale down to keep
+ // the vertical alignment of time accurate
+ //
+ // TODO: Hovering over a timeblock should put a white border
+ // around the timeblock's timeline square, and display
+ // information about the block in the bottom left of
+ // the screen.
+
+
+ // DRAW
+ // ------------------------------------------
+ BeginDrawing()
+ ClearBackground(BGCOLOR)
+ //DrawTextEx(font, "Test text", {20, 20}, 18, 0, RAYWHITE);
+
+ for day, i in workdays {
+
+ DrawRectangle(10, DAY_HEIGHT*i32(i+1)-4, width-20, DAY_HEIGHT-1, PBGCOLOR)
+ for block in day.blocks {
+ DrawRectangle(80,
+ DAY_HEIGHT*i32(i+1)-4, width-170, DAY_HEIGHT-1, BLUE)
+ }
+
+ call_text = strings.clone_to_cstring(clockprint(day.call))
+ wrap_text = strings.clone_to_cstring(clockprint(day.wrap))
+ text_height = math.round(f32(i+1)*DAY_HEIGHT+(DAY_HEIGHT-font_size)*0.25)
+
+ DrawTextEx(font, call_text, {20, text_height}, font_size, 0, RAYWHITE);
+ DrawTextEx(font, wrap_text, {f32(width)-70, text_height}, font_size, 0, RAYWHITE);
+
+ if i == len(workdays)-1 {
+ DrawTextEx(big_font, "+", {20, DAY_HEIGHT*f32(i+2)}, big_font_size, 0, RAYWHITE)
+ }
+ }
+
+ DrawRectangle(0, height-50, width+10, 60, PBGCOLOR)
+
+ DrawTextEx(small_font, total_sum, {f32(width)-120, f32(height)-42}, small_font_size, 0, RAYWHITE);
+ DrawTextEx(big_font, inc_soc, {f32(width)-120, f32(height)-28}, big_font_size, 0, RAYWHITE);
+
+ EndDrawing()
}
+ UnloadFont(font)
+ UnloadFont(small_font)
+ UnloadFont(big_font)
+ CloseWindow()
}
-// TODO: Separate tests into different procedures
-// TODO: Write dedicated tests for lunch
-
-test :: proc() {
-
- fmt.println("\n--- TESTING PRINT STUFFS ---")
-
- test_delta: Delta = {1, 1, 1}
- fmt.println(toString(test_delta))
- test_delta = {0, 0, 0}
- fmt.println(toString(test_delta))
- test_delta = {0, 12, 2}
- fmt.printf("I've been waiting for %s! That's a long time!\n", toString(test_delta))
-
- start: Moment = {45, 8, 20, 4, 2023}
- end: Moment = add(start, test_delta)
- block: Timeblock = {start, end, 0, ""}
- fmt.println(toString(block))
-
- fmt.println(clockprint(block))
-
-
-
- fmt.println("\n--- TESTING WINDING ---")
-
- test_moment: Moment = {45, 8, 30, 12, 2023}
- fmt.println(toString(test_moment))
- test_delta = {30, 1, 2}
- fmt.printf("Winding forward by %s\n", toString(test_delta))
- wind(&test_moment, 30, 1, 2)
- fmt.println(toString(test_moment))
-
-
-
- fmt.println("\n--- TESTING OPERATIONS ---")
-
- fmt.printf("So far test_moment, holds: %s.\n", toString(test_moment))
- fmt.printf("Using add(), that is: %s ephemerally,\n", toString(add(test_moment, test_delta)))
- fmt.printf("but test_moment, is still: %s.\n", toString(test_moment))
- fmt.printf("Using sub(), that is: %s ephemerally,\n", toString(sub(test_moment, test_delta)))
- fmt.printf("but test_moment, is still: %s.\n", toString(test_moment))
-
-
-
- fmt.println("\n--- TESTING DELTA & SORTABLE ---")
-
- fmt.printf("The sortable() version of %s is %i.\n", toString(test_moment), sortable(test_moment))
- fmt.printf("The sortable() version of %s is %i.\n", toString(test_delta), sortable(test_delta))
-
- fmt.printf("The diff() between %s and %s is %s.\n",
- toString(test_moment),
- toString(add(test_moment, test_delta)),
- toString(diff(test_moment, add(test_moment, test_delta))))
-
-
- //for i: int=1; i < 14; i += 1 {
- // fmt.println(days_in(i, 2023))
- //}
- fmt.println("")
-} \ No newline at end of file
+BGCOLOR : rl.Color : {30, 30, 30, 255}
+PBGCOLOR : rl.Color : {40, 40, 40, 255}
+
+DAY_HEIGHT :: 35