From 4af95ee319e2411ac74f42427393008743a4e874 Mon Sep 17 00:00:00 2001 From: drosborn <30788343+drosborn@users.noreply.github.com> Date: Sat, 7 Oct 2017 14:17:11 +1100 Subject: [PATCH] NEW: Add new windows guide --- source/guides/windows/index.html.erb | 6 ++ ...track-of-your-windows-in-splashkit.html.md | 68 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 source/guides/windows/index.html.erb create mode 100644 source/guides/windows/keeping-track-of-your-windows-in-splashkit.html.md diff --git a/source/guides/windows/index.html.erb b/source/guides/windows/index.html.erb new file mode 100644 index 0000000..4e8865a --- /dev/null +++ b/source/guides/windows/index.html.erb @@ -0,0 +1,6 @@ +

JSON Guides

+
+ <% find_guides_in_category('code-examples/windows').each do |f| %> + <%= f[:doc_title] %> + <% end %> +
diff --git a/source/guides/windows/keeping-track-of-your-windows-in-splashkit.html.md b/source/guides/windows/keeping-track-of-your-windows-in-splashkit.html.md new file mode 100644 index 0000000..76148b0 --- /dev/null +++ b/source/guides/windows/keeping-track-of-your-windows-in-splashkit.html.md @@ -0,0 +1,68 @@ + + + + +#Keeping track of your windows in SplashKit + +SplashKit [Windows library](/api/windows) provides a [```window```](/api/windows/#window) data type that refers to your open windows. + +The ability to identify each individual window is fundamental to the management of applications that require multiply window. + +SplashKit gives us the [```open_window(string caption, int x, int y)```](/api/windows/#window_open) function to open a new graphic window. + +We have two options to identify a window; + +* We can refer to the the caption parameter that we passed into the [```open_window(string caption, int x, int y)```](/api/windows/#window_open) function. Then we can use function that are in the form [```set_current_window(const string &name)```](/api/windows/#set_current_window_named). +* Or we can refere to a variable that we assign the window returned when we call the [```open_window(string caption, int x, int y)```](/api/windows/#window_open). Then we can use functions that are in the form [```set_current_window(window wind)```](/api/windows/#set_current_window). + +### Example code + +```c++ +#include "splashkit.h" + +int main() +{ + int window_width = 500; + int window_height = 500; + + //Option 1 + //Open a Window + open_window("Window A",window_width,window_height); + + //Set to current window by name + set_current_window("Window A"); + + //Options 2 + //Initialise a window variable + window window_b; + //Assign the window to a variable + window_b = open_window("Window B",window_width,window_height); + + //Set to current window unsing the window variable + set_current_window(window_b); + + //or + + //We can still set to current window by name + set_current_window("Window B"); + +``` +## From named window to window type + +Some functions e.g. [```resize_window(window wind)```](/api/windows/#resize_window) do not have a verison that allows us to direcrtly reference a window by its caption. We can use the [```window_named(string caption)```](/api/windows/#window_named) function to return a window by passing in a caption. + +### Example code + +```c++ + //Initialise a window variable + window window_a; + //Assign the window to a variable + window_a = window_named("Window A"); + resize_window(window_a, int width, int height); + + //or + + //in one step + resize_window(window_named("Window A"), int width, int height); +} +```