Skip to content

Commit

Permalink
Merge branch 'usage-examples' of https://github.com/thoth-tech/splash…
Browse files Browse the repository at this point in the history
  • Loading branch information
omckeon committed Jan 30, 2025
2 parents df2d67c + 0376760 commit fbf5763
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 0 deletions.
34 changes: 34 additions & 0 deletions public/usage-examples/geometry/point_on_line-1-example-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using SplashKitSDK;

namespace PointOnLineExample
{
public class Program
{
public static void Main()
{
// Variable Declarations
Line line = SplashKit.LineFrom(100, 300, 500, 300);

// Create window
Window window = new Window("Select Point", 600, 600);

while (!SplashKit.QuitRequested())
{
// Display line
window.Clear(Color.White);
window.DrawLine(Color.Black, line);

// Draw text if cursor is on line
if (SplashKit.PointOnLine(SplashKit.MousePosition(), line))
{
window.DrawText("Point on line: " + SplashKit.PointToString(SplashKit.MousePosition()), Color.Black, 200, 450);
}

window.Refresh();
SplashKit.ProcessEvents();
}

window.Close();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

// Variable Declarations
Line line = LineFrom(100, 300, 500, 300);

// Create window
Window window = OpenWindow("Select Point", 600, 600);

while (!QuitRequested())
{
// Display line
ClearScreen(ColorWhite());
DrawLine(ColorBlack(), line);

// Draw text if cursor is on line
if (PointOnLine(MousePosition(), line))
{
DrawText("Point on line: " + PointToString(MousePosition()), ColorBlack(), 200, 450);
}

RefreshScreen();
ProcessEvents();
}
CloseWindow(window);
29 changes: 29 additions & 0 deletions public/usage-examples/geometry/point_on_line-1-example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "splashkit.h"

int main()
{
// Variable Declarations
line line = line_from(100, 300, 500, 300);

// Create window
window window = open_window("Select Point", 600, 600);

while (!quit_requested())
{
// Display line
clear_screen(color_white());
draw_line(color_black(), line);

// Draw text if cursor is on line
if (point_on_line(mouse_position(), line))
{
draw_text("Point on line: " + point_to_string(mouse_position()), color_black(), 200, 450);
}

refresh_screen();
process_events();
}
close_window(window);

return 0;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions public/usage-examples/geometry/point_on_line-1-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from splashkit import *

# Variable Declarations
line = line_from(100, 300, 500, 300)

# Create window
window = open_window("Select Point", 600, 600)

while not quit_requested():
# Display line
clear_screen(color_white())
draw_line_record(color_black(), line)

if point_on_line(mouse_position(), line):
# Draw text if cursor is on line
draw_text_no_font_no_size("Point on line: " + point_to_string(mouse_position()), color_black(), 200, 450)

refresh_screen()
process_events()

close_window(window)
1 change: 1 addition & 0 deletions public/usage-examples/geometry/point_on_line-1-example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mouse Point On Line?
52 changes: 52 additions & 0 deletions public/usage-examples/geometry/point_on_line-2-example-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using SplashKitSDK;

namespace PointOnLineExample
{
public class Program
{
public static void Main()
{
// Variable Declarations
double barX = 100;
Line slider = SplashKit.LineFrom(100, 300, 500, 300);
Line bar = SplashKit.LineFrom(barX, 310, barX, 290);
int percent = 0;
bool barSelected = false;

Window window = new Window("Volume Slider", 600, 600);

while (!SplashKit.QuitRequested())
{
SplashKit.ProcessEvents();

// Check if user has clicked on the bar Line
if (SplashKit.MouseDown(MouseButton.LeftButton) && SplashKit.PointOnLine(SplashKit.MousePosition(), bar))
{
barSelected = true;
}

// Check if user has released mouse button
if (SplashKit.MouseUp(MouseButton.LeftButton))
{
barSelected = false;
}

// Update bar location
if (barSelected && SplashKit.MouseX() >= 100 && SplashKit.MouseX() <= 500)
{
barX = SplashKit.MouseX(); // sets barX value to mouse X value
percent = (int)((barX - 100) / (500 - 100) * 100); // convert barX position to percent value
bar = SplashKit.LineFrom(barX, 310, barX, 290);
}

// Draw Lines and volume text
window.Clear(Color.White);
window.DrawLine(Color.Black, bar);
window.DrawLine(Color.Black, slider);
window.DrawText($"Volume: {percent} %", Color.Black, 200, 450);
window.Refresh();
}
window.Close();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

// Variable Declarations
double barX = 100;
Line slider = LineFrom(100, 300, 500, 300);
Line bar = LineFrom(barX, 310, barX, 290);
int percent = 0;
bool barSelected = false;

Window window = OpenWindow("Volume Slider", 600, 600);

while (!QuitRequested())
{
ProcessEvents();

// Check if user has clicked on the bar Line
if (MouseDown(MouseButton.LeftButton) && PointOnLine(MousePosition(), bar))
{
barSelected = true;
}

// Check if user has released mouse button
if (MouseUp(MouseButton.LeftButton))
{
barSelected = false;
}

// Update bar location
if (barSelected && MouseX() >= 100 && MouseX() <= 500)
{
barX = MouseX(); // sets barX value to mouse X value
percent = (int)((barX - 100) / (500 - 100) * 100); // convert barX position to percent value
bar = LineFrom(barX, 310, barX, 290);
}

// Draw Lines and volume text
ClearScreen(ColorWhite());
DrawLine(ColorBlack(), bar);
DrawLine(ColorBlack(), slider);
DrawText($"Volume: {percent}", ColorBlack(), 200, 450);
RefreshScreen();
}
CloseWindow(window);
48 changes: 48 additions & 0 deletions public/usage-examples/geometry/point_on_line-2-example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "splashkit.h"

int main()
{
// Variable Declarations
double bar_x = 100;
line slider = line_from(100, 300, 500, 300);
line bar = line_from(bar_x, 310, bar_x, 290);
int percent = 0;
bool bar_selected = false;

window window = open_window("Volume Slider", 600, 600);

while (!quit_requested())
{
process_events();

// Check if user has clicked on the bar Line
if (mouse_down(LEFT_BUTTON) && point_on_line(mouse_position(), bar))
{
bar_selected = true;
}

// Check if user has released mouse button
if (mouse_up(LEFT_BUTTON))
{
bar_selected = false;
}

// Update bar location
if (bar_selected && mouse_x() >= 100 && mouse_x() <= 500)
{
bar_x = mouse_x(); // sets bar_x value to mouse x value
percent = int((bar_x - 100) / (500 - 100) * 100); // convert bar_x position to percent value
bar = line_from(bar_x, 310, bar_x, 290);
}

// Draw lines and volume text
clear_screen(color_white());
draw_line(color_black(), bar);
draw_line(color_black(), slider);
draw_text("Volume: " + std::to_string(percent), color_black(), 200, 450);
refresh_screen();
}
close_window(window);

return 0;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions public/usage-examples/geometry/point_on_line-2-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from splashkit import *

# Variable Declarations
bar_x = 100
slider = line_from(100, 300, 500, 300)
bar = line_from(bar_x, 310, bar_x, 290)
percent = 0
bar_selected = False

window = open_window("Volume Slider", 600, 600)

while not quit_requested():
process_events()

# Check if user has clicked on the bar Line
if (mouse_down(MouseButton.left_button) and point_on_line(mouse_position(), bar)):
bar_selected = True

# Check if user has released mouse button
if (mouse_up(MouseButton.left_button)):
bar_selected = False

# Update bar location
if (bar_selected and mouse_x() >= 100 and mouse_x() <= 500):
bar_x = mouse_x() # sets bar_x value to mouse x value
percent = int((bar_x - 100) / (500 - 100) * 100) # convert bar_x position to percent value
bar = line_from(bar_x, 310, bar_x, 290)

# Draw lines and volume text
clear_screen(color_white())
draw_line_record(color_black(), bar)
draw_line_record(color_black(), slider)
draw_text_no_font_no_size("Volume: " + str(percent), color_black(), 200, 450)
refresh_screen()

close_window(window)
1 change: 1 addition & 0 deletions public/usage-examples/geometry/point_on_line-2-example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Volume Slider Simulation

0 comments on commit fbf5763

Please sign in to comment.