diff --git a/public/usage-examples/timers/stop_timer-1-example-oop.cs b/public/usage-examples/timers/stop_timer-1-example-oop.cs new file mode 100644 index 000000000..23b867a1a --- /dev/null +++ b/public/usage-examples/timers/stop_timer-1-example-oop.cs @@ -0,0 +1,38 @@ +using SplashKitSDK; + +namespace StopTimerExample +{ + public class Program + { + public static void Main() + { + SplashKit.OpenWindow("Press S to Stop Timer", 700, 220); + + SplashKit.CreateTimer("demo"); + SplashKit.StartTimer("demo"); + + while (!SplashKit.QuitRequested()) + { + SplashKit.ProcessEvents(); + + if (SplashKit.KeyTyped(KeyCode.SKey) && SplashKit.TimerStarted("demo")) + { + SplashKit.StopTimer("demo"); + } + + string status = SplashKit.TimerStarted("demo") ? "Running" : "Stopped"; + uint ticks = SplashKit.TimerTicks("demo"); + + SplashKit.ClearScreen(Color.White); + + SplashKit.DrawText("Press S to stop the timer", Color.Black, 20, 20); + SplashKit.DrawText("Status: " + status, Color.Blue, 20, 70); + SplashKit.DrawText("Ticks: " + ticks, Color.Red, 20, 110); + + SplashKit.RefreshScreen(60); + } + + SplashKit.CloseAllWindows(); + } + } +} \ No newline at end of file diff --git a/public/usage-examples/timers/stop_timer-1-example-top-level.cs b/public/usage-examples/timers/stop_timer-1-example-top-level.cs new file mode 100644 index 000000000..4c10c6045 --- /dev/null +++ b/public/usage-examples/timers/stop_timer-1-example-top-level.cs @@ -0,0 +1,30 @@ +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +OpenWindow("Press S to Stop Timer", 700, 220); + +CreateTimer("demo"); +StartTimer("demo"); + +while (!QuitRequested()) +{ + ProcessEvents(); + + if (KeyTyped(KeyCode.SKey) && TimerStarted("demo")) + { + StopTimer("demo"); + } + + string status = TimerStarted("demo") ? "Running" : "Stopped"; + uint ticks = TimerTicks("demo"); + + ClearScreen(ColorWhite()); + + DrawText("Press S to stop the timer", ColorBlack(), 20, 20); + DrawText($"Status: {status}", ColorBlue(), 20, 70); + DrawText($"Ticks: {ticks}", ColorRed(), 20, 110); + + RefreshScreen(60); +} + +CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/timers/stop_timer-1-example.cpp b/public/usage-examples/timers/stop_timer-1-example.cpp new file mode 100644 index 000000000..883486c81 --- /dev/null +++ b/public/usage-examples/timers/stop_timer-1-example.cpp @@ -0,0 +1,36 @@ +#include "splashkit.h" +#include + +using namespace std; + +int main() +{ + open_window("Press S to Stop Timer", 700, 220); + + create_timer("demo"); + start_timer("demo"); + + while (!quit_requested()) + { + process_events(); + + if (key_typed(S_KEY) && timer_started("demo")) + { + stop_timer("demo"); + } + + string status = timer_started("demo") ? "Running" : "Stopped"; + unsigned int ticks = timer_ticks("demo"); + + clear_screen(COLOR_WHITE); + + draw_text("Press S to stop the timer", COLOR_BLACK, 20, 20); + draw_text("Status: " + status, COLOR_BLUE, 20, 70); + draw_text("Ticks: " + to_string((int)ticks), COLOR_RED, 20, 110); + + refresh_screen(60); + } + + close_all_windows(); + return 0; +} \ No newline at end of file diff --git a/public/usage-examples/timers/stop_timer-1-example.gif b/public/usage-examples/timers/stop_timer-1-example.gif new file mode 100644 index 000000000..4786d718d Binary files /dev/null and b/public/usage-examples/timers/stop_timer-1-example.gif differ diff --git a/public/usage-examples/timers/stop_timer-1-example.py b/public/usage-examples/timers/stop_timer-1-example.py new file mode 100644 index 000000000..b7ac457b4 --- /dev/null +++ b/public/usage-examples/timers/stop_timer-1-example.py @@ -0,0 +1,25 @@ +from splashkit import * + +open_window("Press S to Stop Timer", 700, 220) + +create_timer("demo") +start_timer_named("demo") + +while not quit_requested(): + process_events() + + if key_typed(KeyCode.s_key) and timer_started_named("demo"): + stop_timer_named("demo") + + status = "Running" if timer_started_named("demo") else "Stopped" + ticks = timer_ticks_named("demo") + + clear_screen(color_white()) + + draw_text_no_font_no_size("Press S to stop the timer", color_black(), 20, 20) + draw_text_no_font_no_size(f"Status: {status}", color_blue(), 20, 70) + draw_text_no_font_no_size(f"Ticks: {ticks}", color_red(), 20, 110) + + refresh_screen() + +close_all_windows() \ No newline at end of file diff --git a/public/usage-examples/timers/stop_timer-1-example.txt b/public/usage-examples/timers/stop_timer-1-example.txt new file mode 100644 index 000000000..548e37a67 --- /dev/null +++ b/public/usage-examples/timers/stop_timer-1-example.txt @@ -0,0 +1,3 @@ +Press S to Stop Timer + +Press S to stop the timer and reset its ticks to 0. \ No newline at end of file