diff --git a/public/usage-examples/input/key_typed-1-example-oop.cs b/public/usage-examples/input/key_typed-1-example-oop.cs new file mode 100644 index 000000000..dba4a5d1d --- /dev/null +++ b/public/usage-examples/input/key_typed-1-example-oop.cs @@ -0,0 +1,49 @@ +using SplashKitSDK; + +namespace KeyTypedExample +{ + public class Program + { + public static void Main() + { + KeyCode[] trackedKeys = + { + KeyCode.AKey, KeyCode.BKey, KeyCode.CKey, KeyCode.DKey, KeyCode.EKey, + KeyCode.FKey, KeyCode.GKey, KeyCode.HKey, KeyCode.IKey, KeyCode.JKey, + KeyCode.KKey, KeyCode.LKey, KeyCode.MKey, KeyCode.NKey, KeyCode.OKey, + KeyCode.PKey, KeyCode.QKey, KeyCode.RKey, KeyCode.SKey, KeyCode.TKey, + KeyCode.UKey, KeyCode.VKey, KeyCode.WKey, KeyCode.XKey, KeyCode.YKey, KeyCode.ZKey, + KeyCode.Num0Key, KeyCode.Num1Key, KeyCode.Num2Key, KeyCode.Num3Key, KeyCode.Num4Key, + KeyCode.Num5Key, KeyCode.Num6Key, KeyCode.Num7Key, KeyCode.Num8Key, KeyCode.Num9Key, + KeyCode.SpaceKey, KeyCode.EscapeKey + }; + + string lastKey = "None"; + + SplashKit.OpenWindow("Last Typed Key", 800, 600); + + while (!SplashKit.QuitRequested()) + { + SplashKit.ProcessEvents(); + + // Update the text when a supported key is typed + foreach (KeyCode key in trackedKeys) + { + if (SplashKit.KeyTyped(key)) + { + lastKey = SplashKit.KeyName(key); + } + } + + SplashKit.ClearScreen(Color.White); + + SplashKit.DrawText("Press a supported key", Color.Black, 20, 20); + SplashKit.DrawText("Last typed: " + lastKey, Color.Blue, 20, 80); + + SplashKit.RefreshScreen(); + } + + SplashKit.CloseAllWindows(); + } + } +} \ No newline at end of file diff --git a/public/usage-examples/input/key_typed-1-example-top-level.cs b/public/usage-examples/input/key_typed-1-example-top-level.cs new file mode 100644 index 000000000..76bc896c6 --- /dev/null +++ b/public/usage-examples/input/key_typed-1-example-top-level.cs @@ -0,0 +1,41 @@ +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +KeyCode[] trackedKeys = +{ + KeyCode.AKey, KeyCode.BKey, KeyCode.CKey, KeyCode.DKey, KeyCode.EKey, + KeyCode.FKey, KeyCode.GKey, KeyCode.HKey, KeyCode.IKey, KeyCode.JKey, + KeyCode.KKey, KeyCode.LKey, KeyCode.MKey, KeyCode.NKey, KeyCode.OKey, + KeyCode.PKey, KeyCode.QKey, KeyCode.RKey, KeyCode.SKey, KeyCode.TKey, + KeyCode.UKey, KeyCode.VKey, KeyCode.WKey, KeyCode.XKey, KeyCode.YKey, KeyCode.ZKey, + KeyCode.Num0Key, KeyCode.Num1Key, KeyCode.Num2Key, KeyCode.Num3Key, KeyCode.Num4Key, + KeyCode.Num5Key, KeyCode.Num6Key, KeyCode.Num7Key, KeyCode.Num8Key, KeyCode.Num9Key, + KeyCode.SpaceKey, KeyCode.EscapeKey +}; + +string lastKey = "None"; + +OpenWindow("Last Typed Key", 800, 600); + +while (!QuitRequested()) +{ + ProcessEvents(); + + // Update the text when a supported key is typed + foreach (KeyCode key in trackedKeys) + { + if (KeyTyped(key)) + { + lastKey = KeyName(key); + } + } + + ClearScreen(ColorWhite()); + + DrawText("Press a supported key", ColorBlack(), 20, 20); + DrawText($"Last typed: {lastKey}", ColorBlue(), 20, 80); + + RefreshScreen(); +} + +CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/input/key_typed-1-example.cpp b/public/usage-examples/input/key_typed-1-example.cpp new file mode 100644 index 000000000..d40e6a392 --- /dev/null +++ b/public/usage-examples/input/key_typed-1-example.cpp @@ -0,0 +1,45 @@ +#include "splashkit.h" +#include +#include + +using namespace std; + +int main() +{ + open_window("Last Typed Key", 800, 600); + + vector tracked_keys = { + A_KEY, B_KEY, C_KEY, D_KEY, E_KEY, F_KEY, G_KEY, H_KEY, I_KEY, J_KEY, + K_KEY, L_KEY, M_KEY, N_KEY, O_KEY, P_KEY, Q_KEY, R_KEY, S_KEY, T_KEY, + U_KEY, V_KEY, W_KEY, X_KEY, Y_KEY, Z_KEY, + NUM_0_KEY, NUM_1_KEY, NUM_2_KEY, NUM_3_KEY, NUM_4_KEY, + NUM_5_KEY, NUM_6_KEY, NUM_7_KEY, NUM_8_KEY, NUM_9_KEY, + SPACE_KEY, ESCAPE_KEY + }; + + string last_key = "None"; + + while (!quit_requested()) + { + process_events(); + + // Update the text when a supported key is typed + for (key_code key : tracked_keys) + { + if (key_typed(key)) + { + last_key = key_name(key); + } + } + + clear_screen(COLOR_WHITE); + + draw_text("Press a supported key", COLOR_BLACK, 20, 20); + draw_text("Last typed: " + last_key, COLOR_BLUE, 20, 80); + + refresh_screen(60); + } + + close_all_windows(); + return 0; +} \ No newline at end of file diff --git a/public/usage-examples/input/key_typed-1-example.gif b/public/usage-examples/input/key_typed-1-example.gif new file mode 100644 index 000000000..4f107f4aa Binary files /dev/null and b/public/usage-examples/input/key_typed-1-example.gif differ diff --git a/public/usage-examples/input/key_typed-1-example.py b/public/usage-examples/input/key_typed-1-example.py new file mode 100644 index 000000000..6e76a7b08 --- /dev/null +++ b/public/usage-examples/input/key_typed-1-example.py @@ -0,0 +1,33 @@ +from splashkit import * + +tracked_keys = [ + KeyCode.a_key, KeyCode.b_key, KeyCode.c_key, KeyCode.d_key, KeyCode.e_key, + KeyCode.f_key, KeyCode.g_key, KeyCode.h_key, KeyCode.i_key, KeyCode.j_key, + KeyCode.k_key, KeyCode.l_key, KeyCode.m_key, KeyCode.n_key, KeyCode.o_key, + KeyCode.p_key, KeyCode.q_key, KeyCode.r_key, KeyCode.s_key, KeyCode.t_key, + KeyCode.u_key, KeyCode.v_key, KeyCode.w_key, KeyCode.x_key, KeyCode.y_key, KeyCode.z_key, + KeyCode.num_0_key, KeyCode.num_1_key, KeyCode.num_2_key, KeyCode.num_3_key, KeyCode.num_4_key, + KeyCode.num_5_key, KeyCode.num_6_key, KeyCode.num_7_key, KeyCode.num_8_key, KeyCode.num_9_key, + KeyCode.space_key, KeyCode.escape_key +] + +last_key = "None" + +open_window("Last Typed Key", 800, 600) + +while not quit_requested(): + process_events() + + # Update the text when a supported key is typed + for key in tracked_keys: + if key_typed(key): + last_key = key_name(key) + + clear_screen(color_white()) + + draw_text_no_font_no_size("Press a supported key", color_black(), 20, 20) + draw_text_no_font_no_size("Last typed: " + last_key, color_blue(), 20, 80) + + refresh_screen() + +close_all_windows() \ No newline at end of file diff --git a/public/usage-examples/input/key_typed-1-example.txt b/public/usage-examples/input/key_typed-1-example.txt new file mode 100644 index 000000000..2eeed5363 --- /dev/null +++ b/public/usage-examples/input/key_typed-1-example.txt @@ -0,0 +1,3 @@ +Last Typed Key + +Press a supported key to display the most recently typed key on screen. \ No newline at end of file diff --git a/public/usage-examples/input/mouse_clicked-1-example-oop.cs b/public/usage-examples/input/mouse_clicked-1-example-oop.cs new file mode 100644 index 000000000..066f5a991 --- /dev/null +++ b/public/usage-examples/input/mouse_clicked-1-example-oop.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using SplashKitSDK; + +namespace MouseClickedExample +{ + public class Program + { + public static void Main() + { + SplashKit.OpenWindow("Click to Place Markers", 800, 600); + + List clicks = new(); + + while (!SplashKit.QuitRequested()) + { + SplashKit.ProcessEvents(); + + // Add a marker where the left mouse button was clicked + if (SplashKit.MouseClicked(MouseButton.LeftButton)) + { + clicks.Add(SplashKit.MousePosition()); + } + + SplashKit.ClearScreen(); + + foreach (Point2D pt in clicks) + { + SplashKit.FillCircle(Color.Red, pt.X, pt.Y, 8); + } + + SplashKit.RefreshScreen(60); + } + + SplashKit.CloseAllWindows(); + } + } +} \ No newline at end of file diff --git a/public/usage-examples/input/mouse_clicked-1-example-top-level.cs b/public/usage-examples/input/mouse_clicked-1-example-top-level.cs new file mode 100644 index 000000000..f08daa800 --- /dev/null +++ b/public/usage-examples/input/mouse_clicked-1-example-top-level.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +OpenWindow("Click to Place Markers", 800, 600); + +List clicks = new(); + +while (!QuitRequested()) +{ + ProcessEvents(); + + // Add a marker where the left mouse button was clicked + if (MouseClicked(MouseButton.LeftButton)) + { + clicks.Add(MousePosition()); + } + + ClearScreen(ColorWhite()); + + foreach (Point2D pt in clicks) + { + FillCircle(ColorRed(), pt.X, pt.Y, 8); + } + + RefreshScreen(60); +} + +CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/input/mouse_clicked-1-example.cpp b/public/usage-examples/input/mouse_clicked-1-example.cpp new file mode 100644 index 000000000..a6d78f1aa --- /dev/null +++ b/public/usage-examples/input/mouse_clicked-1-example.cpp @@ -0,0 +1,32 @@ +#include "splashkit.h" +#include + +int main() +{ + open_window("Click to Place Markers", 800, 600); + + std::vector clicks; + + while (!quit_requested()) + { + process_events(); + + // Add a marker where the left mouse button was clicked + if (mouse_clicked(LEFT_BUTTON)) + { + clicks.push_back(mouse_position()); + } + + clear_screen(color_white()); + + for (const point_2d &pt : clicks) + { + fill_circle(COLOR_RED, pt.x, pt.y, 8); + } + + refresh_screen(60); + } + + close_all_windows(); + return 0; +} \ No newline at end of file diff --git a/public/usage-examples/input/mouse_clicked-1-example.png b/public/usage-examples/input/mouse_clicked-1-example.png new file mode 100644 index 000000000..c56ef1fa9 Binary files /dev/null and b/public/usage-examples/input/mouse_clicked-1-example.png differ diff --git a/public/usage-examples/input/mouse_clicked-1-example.py b/public/usage-examples/input/mouse_clicked-1-example.py new file mode 100644 index 000000000..ef448e1f2 --- /dev/null +++ b/public/usage-examples/input/mouse_clicked-1-example.py @@ -0,0 +1,21 @@ +from splashkit import * + +open_window("Click to Place Markers", 800, 600) + +clicks = [] + +while not quit_requested(): + process_events() + + # Add a marker where the left mouse button was clicked + if mouse_clicked(MouseButton.left_button): + clicks.append(mouse_position()) + + clear_screen(color_white()) + + for pt in clicks: + fill_circle(color_red(), pt.x, pt.y, 8) + + refresh_screen() + +close_all_windows() \ No newline at end of file diff --git a/public/usage-examples/input/mouse_clicked-1-example.txt b/public/usage-examples/input/mouse_clicked-1-example.txt new file mode 100644 index 000000000..c8da88383 --- /dev/null +++ b/public/usage-examples/input/mouse_clicked-1-example.txt @@ -0,0 +1,3 @@ +Click to Place Markers + +Left click anywhere in the window to place a red marker at the clicked position. \ No newline at end of file