Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions public/usage-examples/interface/button-1-example-oop.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
45 changes: 45 additions & 0 deletions public/usage-examples/interface/button-1-example-top-level.cs
Original file line number Diff line number Diff line change
@@ -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();
49 changes: 49 additions & 0 deletions public/usage-examples/interface/button-1-example.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions public/usage-examples/interface/button-1-example.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions public/usage-examples/interface/button-1-example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Button Click Counter
23 changes: 23 additions & 0 deletions scripts/json-files/usage-example-references.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down