diff --git a/public/usage-examples/interface/button-1-example-oop.cs b/public/usage-examples/interface/button-1-example-oop.cs new file mode 100644 index 000000000..acb5efcd9 --- /dev/null +++ b/public/usage-examples/interface/button-1-example-oop.cs @@ -0,0 +1,54 @@ +using SplashKitSDK; + +namespace ButtonExample +{ + public class Program + { + public static void Main() + { + SplashKit.OpenWindow("Button Click Counter", 800, 600); + + // Track click counts for each button + int redCount = 0; + int blueCount = 0; + int greenCount = 0; + + while (!SplashKit.QuitRequested()) + { + SplashKit.ProcessEvents(); + SplashKit.ClearScreen(Color.White); + + // Show instructions for the user + SplashKit.DrawText("Click the buttons to increment counters", Color.Black, 10, 10); + + // Create a panel with three buttons + if (SplashKit.StartPanel("Click Counter", SplashKit.RectangleFrom(50, 50, 200, 200))) + { + // Check if each button is clicked and update counts + if (SplashKit.Button("Red")) + { + redCount++; + } + if (SplashKit.Button("Blue")) + { + blueCount++; + } + if (SplashKit.Button("Green")) + { + greenCount++; + } + SplashKit.EndPanel("Click Counter"); + } + + // Display each button's click count on the window + SplashKit.DrawText("Red clicks: " + redCount.ToString(), Color.Red, 300, 100); + SplashKit.DrawText("Blue clicks: " + blueCount.ToString(), Color.Blue, 300, 130); + SplashKit.DrawText("Green clicks: " + greenCount.ToString(), Color.Green, 300, 160); + + SplashKit.RefreshScreen(60); + } + + SplashKit.CloseAllWindows(); + } + } +} diff --git a/public/usage-examples/interface/button-1-example-top-level.cs b/public/usage-examples/interface/button-1-example-top-level.cs new file mode 100644 index 000000000..782f54ded --- /dev/null +++ b/public/usage-examples/interface/button-1-example-top-level.cs @@ -0,0 +1,45 @@ +using static SplashKitSDK.SplashKit; + +OpenWindow("Button Click Counter", 800, 600); + +// Track click counts for each button +int redCount = 0; +int blueCount = 0; +int greenCount = 0; + +while (!QuitRequested()) +{ + ProcessEvents(); + ClearScreen(ColorWhite()); + + // Show instructions for the user + DrawText("Click the buttons to increment counters", ColorBlack(), 10, 10); + + // Create a panel with three buttons + if (StartPanel("Click Counter", RectangleFrom(50, 50, 200, 200))) + { + // Check if each button is clicked and update counts + if (Button("Red")) + { + redCount++; + } + if (Button("Blue")) + { + blueCount++; + } + if (Button("Green")) + { + greenCount++; + } + EndPanel("Click Counter"); + } + + // Display each button's click count on the window + DrawText("Red clicks: " + redCount.ToString(), ColorRed(), 300, 100); + DrawText("Blue clicks: " + blueCount.ToString(), ColorBlue(), 300, 130); + DrawText("Green clicks: " + greenCount.ToString(), ColorGreen(), 300, 160); + + RefreshScreen(60); +} + +CloseAllWindows(); diff --git a/public/usage-examples/interface/button-1-example.cpp b/public/usage-examples/interface/button-1-example.cpp new file mode 100644 index 000000000..ca64a1671 --- /dev/null +++ b/public/usage-examples/interface/button-1-example.cpp @@ -0,0 +1,49 @@ +#include "splashkit.h" + +int main() +{ + open_window("Button Click Counter", 800, 600); + + // Track click counts for each button + int red_count = 0; + int blue_count = 0; + int green_count = 0; + + while (!quit_requested()) + { + process_events(); + clear_screen(COLOR_WHITE); + + // Show instructions for the user + draw_text("Click the buttons to increment counters", COLOR_BLACK, 10, 10); + + // Create a panel with three buttons + if (start_panel("Click Counter", rectangle_from(50, 50, 200, 200))) + { + // Check if each button is clicked and update counts + if (button("Red")) + { + red_count++; + } + if (button("Blue")) + { + blue_count++; + } + if (button("Green")) + { + green_count++; + } + end_panel("Click Counter"); + } + + // Display each button's click count on the window + draw_text("Red clicks: " + std::to_string(red_count), COLOR_RED, 300, 100); + draw_text("Blue clicks: " + std::to_string(blue_count), COLOR_BLUE, 300, 130); + draw_text("Green clicks: " + std::to_string(green_count), COLOR_GREEN, 300, 160); + + refresh_screen(60); + } + + close_all_windows(); + return 0; +} diff --git a/public/usage-examples/interface/button-1-example.gif b/public/usage-examples/interface/button-1-example.gif new file mode 100644 index 000000000..06ad3c0a2 Binary files /dev/null and b/public/usage-examples/interface/button-1-example.gif differ diff --git a/public/usage-examples/interface/button-1-example.py b/public/usage-examples/interface/button-1-example.py new file mode 100644 index 000000000..488629082 --- /dev/null +++ b/public/usage-examples/interface/button-1-example.py @@ -0,0 +1,35 @@ +from splashkit import * + +open_window("Button Click Counter", 800, 600) + +# Track click counts for each button +red_count = 0 +blue_count = 0 +green_count = 0 + +while not quit_requested(): + process_events() + clear_screen_to_white() + + # Show instructions for the user + draw_text_no_font_no_size("Click the buttons to increment counters", color_black(), 10, 10) + + # Create a panel with three buttons + if start_panel("Click Counter", rectangle_from(50, 50, 200, 200)): + # Check if each button is clicked and update counts + if button("Red"): + red_count += 1 + if button("Blue"): + blue_count += 1 + if button("Green"): + green_count += 1 + end_panel("Click Counter") + + # Display each button's click count on the window + draw_text_no_font_no_size("Red clicks: " + str(red_count), color_red(), 300, 100) + draw_text_no_font_no_size("Blue clicks: " + str(blue_count), color_blue(), 300, 130) + draw_text_no_font_no_size("Green clicks: " + str(green_count), color_green(), 300, 160) + + refresh_screen_with_target_fps(60) + +close_all_windows() diff --git a/public/usage-examples/interface/button-1-example.txt b/public/usage-examples/interface/button-1-example.txt new file mode 100644 index 000000000..89d60f497 --- /dev/null +++ b/public/usage-examples/interface/button-1-example.txt @@ -0,0 +1 @@ +Button Click Counter diff --git a/scripts/json-files/usage-example-references.json b/scripts/json-files/usage-example-references.json index c41688ec6..92b060ad0 100644 --- a/scripts/json-files/usage-example-references.json +++ b/scripts/json-files/usage-example-references.json @@ -1259,6 +1259,29 @@ ] } ], + "interface": [ + { + "funcKey": "button", + "title": "Button Click Counter", + "url": "/api/interface/#button", + "functions": [ + "open_window", + "quit_requested", + "process_events", + "clear_screen_to_white", + "draw_text_no_font_no_size", + "color_black", + "start_panel", + "rectangle_from", + "end_panel", + "color_red", + "color_blue", + "color_green", + "refresh_screen_with_target_fps", + "close_all_windows" + ] + } + ], "networking": [ { "funcKey": "dec_to_hex",