Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5 Usage example for Graphics P2 #341

Open
wants to merge 1 commit into
base: usage-examples
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using SplashKitSDK;

public class Program
{
public static void Main()
{
// Open a window with the title "Current Clip" and dimensions
Window window= SplashKit.OpenWindow("Current Clip", 800, 600);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space after window, should look like this: Window window = SplashKit.OpenWindow("Current Clip", 800, 600);


// Push a clipping area
Rectangle rectangle = SplashKit.CurrentClip();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add window in CurrentClip() -> CurrentClip(window), otherwise it is no need to create Window window.

// Display information about the current clipping area (Width and Height) in the window
SplashKit.DrawText($"Current Clip: Width:{rectangle.Width} Height:{rectangle.Height}", Color.Black, "Arial", 24, 100, 100);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use "writeline" here to print the result on the terminal, otherwise if the user creates a smaller window would not able to see the full text.
image


// Refresh the screen to display the text
SplashKit.RefreshScreen();

// Wait for 5 seconds to observe the clipping area information
SplashKit.Delay(5000);

// Close the window
SplashKit.CloseAllWindows();
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the space in front of the code.
image
like this

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using static SplashKitSDK.SplashKit;
using SplashKitSDK;
// Open a window with the title "Current Clip" and dimensions
Window window= OpenWindow("Current Clip", 800, 600);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space after window, same as above.


// Push a clipping area
Rectangle rectangle = CurrentClip();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add window in CurrentClip() -> CurrentClip(window), otherwise it is no need to create Window window.

// Display information about the current clipping area (Width and Height) in the window
DrawText($"Current Clip: Width:{rectangle.Width} Height:{rectangle.Height}", Color.Black, "Arial", 24, 100, 100);

// Refresh the screen to display the text
RefreshScreen();

// Wait for 5 seconds to observe the clipping area information
Delay(5000);

// Close the window
CloseAllWindows();

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "splashkit.h"

int main()
{
// Open a window with the title "Current Clip" and dimensions
window win = open_window("Current Clip", 800, 600);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use window here to make sure it keep the same as the other language code.


// Define the clipping area

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure the commits are the same as well, so it makes less confusion to the users.

rectangle rect = current_clip(win);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here change to window.


// Draw the clipping information
draw_text("Current Clip: " + std::to_string(rect.width) + " X " + std::to_string(rect.height), COLOR_BLACK, "Arial", 24, 100, 100);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use the same work as the above code. Width and Height.


// Refresh the screen to display the text
refresh_screen();

// Wait for 5 seconds

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure the commits are the same as well, so it makes less confusion to the users.

delay(5000);

// Close all windows

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure the commits are the same as well, so it makes less confusion to the users.

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from splashkit import *

# Open a window with the title "Current Clip" and dimensions of 800x600 pixels

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check all commits and make sure it keeps the same please.

window = open_window("Current Clip", 800, 600)
font = load_font("Arial", "arial.ttf")

# Retrieve the current clipping area
r = current_clip()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 'rectangle' here. rectangle = current_clip(window)


# Draw the clipping area dimensions as text on the screen
draw_text("Current Clip: " + str(r.width) + " X " + str(r.height), color_black(), font, 24, 100, 100)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use the same work as above code. Width and Height.


# Refresh the screen to display the text
refresh_screen()

# Wait for 5 seconds
delay(5000)

# Close all windows
close_all_windows()

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### CURRENT CLIP

The following code shows an examples of using [Current Clip](/api/graphics#current-clip) to set a clip region and draw a rectangle to visually show the active clipping area.
34 changes: 34 additions & 0 deletions public/usage-examples/graphics/pop_clip/pop-clip-1-simple-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using SplashKitSDK;

public class Program
{
public static void Main()
{
// Open a window with the title "Pop Clip" and dimensions 800x600
Window window = SplashKit.OpenWindow("Pop Clip", 800, 600);

// Define a rectangle for the clipping area starting at (100, 100) with width 600 and height 400
Rectangle rectangle = SplashKit.RectangleFrom(100, 100, 600, 400);

// Push a clipping area to restrict drawing to within the defined rectangle
SplashKit.PushClip(window, rectangle);

// Draw a blue rectangle within the clipping area (this will be affected by clipping)
SplashKit.FillRectangle(Color.Blue, 50, 50, 700, 500); // This will be clipped

// Pop the clipping area to restore the full window area for drawing
SplashKit.PopClip(window);

// Draw a red rectangle outside the clipping area (this will be fully visible)
SplashKit.FillRectangle(Color.Red, 100, 100, 200, 200); // This won't be clipped

// Refresh the screen to display all changes
SplashKit.RefreshScreen();

// Wait for 5 seconds before closing the window
SplashKit.Delay(5000);

// Close all open windows to end the program
SplashKit.CloseAllWindows();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using static SplashKitSDK.SplashKit;
using SplashKitSDK;

// Open a window with the title "Pop Clip" and dimensions 800x600
Window window = OpenWindow("Pop Clip", 800, 600);

// Define a rectangle for the clipping area starting at (100, 100) with width 600 and height 400
Rectangle rectangle = RectangleFrom(100, 100, 600, 400);

// Push a clipping area to restrict drawing to within the defined rectangle
PushClip(window, rectangle);

// Draw a blue rectangle within the clipping area (this will be affected by clipping)
FillRectangle(Color.Blue, 50, 50, 700, 500); // This will be clipped

// Pop the clipping area to restore the full window area for drawing
PopClip(window);

// Draw a red rectangle outside the clipping area (this will be fully visible)
FillRectangle(Color.Red, 100, 100, 200, 200); // This won't be clipped

// Refresh the screen to display all changes
RefreshScreen();

// Wait for 5 seconds before closing the window
Delay(5000);

// Close all open windows to end the program
CloseAllWindows();


33 changes: 33 additions & 0 deletions public/usage-examples/graphics/pop_clip/pop-clip-1-simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "splashkit.h"

int main()
{
// Open a window with the title "Pop Clip" and dimensions 800x600
open_window("Pop Clip", 800, 600);

// Define the clipping area starting at (100, 100) with width 600 and height 400
rectangle rect = {100, 100, 600, 400};

// Push a clipping area to restrict drawing to within the defined rectangle
push_clip(rect);

// Draw a blue rectangle inside the clipping area (this will be affected by clipping)
fill_rectangle(COLOR_BLUE, 50, 50, 700, 500);

// Restore the full window area after clipping
pop_clip();

// Draw a red rectangle outside the clipping area (this won't be affected by clipping)
fill_rectangle(COLOR_RED, 100, 100, 200, 200);

// Refresh the screen to display the changes
refresh_screen();

// Wait for 5 seconds before closing the window
delay(5000);

// Close all open windows to end the program
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.
28 changes: 28 additions & 0 deletions public/usage-examples/graphics/pop_clip/pop-clip-1-simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from splashkit import *

# Open a window with the title "Pop Clip" and dimensions 800x600
window = open_window("Pop Clip", 800, 600)

# Define the clipping area as a rectangle starting at (100, 100) with width 600 and height 400
r = rectangle_from(100, 100, 600, 400)

# Push a clipping area for the window
push_clip_for_window(window, r)

# Draw a blue rectangle inside the clipping area (this will be clipped by the clipping area)
fill_rectangle(color_blue(), 50, 50, 700, 500)

# Restore the full window area after the clipping
pop_clip_for_window(window)

# Draw a red rectangle outside the clipping area (this will not be clipped)
fill_rectangle(color_red(), 100, 100, 200, 200)

# Refresh the screen to display the changes
refresh_screen()

# Wait for 5 seconds to observe the drawing
delay(5000)

# Close all open windows to end the program
close_all_windows()
3 changes: 3 additions & 0 deletions public/usage-examples/graphics/pop_clip/pop-clip-1-simple.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### POP CLIP

The following code shows an examples of using [Pop Clip](/api/graphics#pop-clip) to push a clipping area and then pop it to restore the full window drawing area, with indicators of the change.
34 changes: 34 additions & 0 deletions public/usage-examples/graphics/push_clip/push-clip-1-simple-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using SplashKitSDK;

public class Program
{
public static void Main()
{
// Open a window with the title "Push Clip" and dimensions 800x600
Window window = SplashKit.OpenWindow("Push Clip", 800, 600);

// Define a rectangular clipping area starting at (100, 100) with width 200 and height 200
Rectangle rectangle = SplashKit.RectangleFrom(100, 100, 200, 200);

// Push a clipping area on the window
SplashKit.PushClip(window, rectangle);

// Draw a blue rectangle inside the clipping area (this will be clipped by the clipping area)
SplashKit.FillRectangle(Color.Blue, 50, 50, 300, 300); // This will be clipped

// Pop the clipping area to restore full screen drawing capability
SplashKit.PopClip();

// Draw a red rectangle outside the clipping area (this won't be clipped)
SplashKit.FillRectangle(Color.Red, 300, 300, 200, 200);

// Refresh the screen to display the drawing
SplashKit.RefreshScreen();

// Wait for 5 seconds to observe the changes
SplashKit.Delay(5000);

// Close all open windows to end the program
SplashKit.CloseAllWindows();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using static SplashKitSDK.SplashKit;
using SplashKitSDK;

// Open a window with the title "Push Clip" and dimensions 800x600
Window window = OpenWindow("Push Clip", 800, 600);

// Define a rectangular clipping area starting at (100, 100) with width 200 and height 200
Rectangle rectangle = RectangleFrom(100, 100, 200, 200);

// Push a clipping area on the window
PushClip(window, rectangle);

// Draw a blue rectangle inside the clipping area (this will be clipped by the clipping area)
FillRectangle(Color.Blue, 50, 50, 300, 300); // This will be clipped

// Pop the clipping area to restore full screen drawing capability
PopClip();

// Draw a red rectangle outside the clipping area (this won't be clipped)
FillRectangle(Color.Red, 300, 300, 200, 200);

// Refresh the screen to display the drawing
RefreshScreen();

// Wait for 5 seconds to observe the changes
Delay(5000);

// Close all open windows to end the program
CloseAllWindows();


33 changes: 33 additions & 0 deletions public/usage-examples/graphics/push_clip/push-clip-1-simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "splashkit.h"

int main()
{
// Open a window with the specified title and dimensions
open_window("Push Clip", 800, 600);

// Define a rectangular clipping area starting at (100, 100) with width 200 and height 200
rectangle rect = {100, 100, 200, 200};

// Push a clipping area onto the window
push_clip(rect);

// Draw a blue rectangle inside the clipping area (this will be clipped)
fill_rectangle(COLOR_BLUE, 50, 50, 300, 300);

// Pop the clipping area to restore full screen drawing
pop_clip();

// Draw a red rectangle outside the clipping area (this will not be clipped)
fill_rectangle(COLOR_RED, 300, 300, 200, 200);

// Refresh the screen to display the drawing
refresh_screen();

// Wait for 5 seconds to observe the changes
delay(5000);

// Close all open windows
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.
27 changes: 27 additions & 0 deletions public/usage-examples/graphics/push_clip/push-clip-1-simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from splashkit import *

window = open_window("Push Clip", 800, 600)

# Define the clipping area as a rectangle
r = rectangle_from(100, 100, 200, 200)

# Push the clipping area onto the window stack
push_clip(r)

# Draw a blue rectangle within the clipping area (will be clipped)
fill_rectangle(color_blue(), 50, 50, 300, 300)

# Pop the clipping area from the window stack to restore full drawing capability
pop_clip()

# Draw a red rectangle outside the clipping area (will not be clipped)
fill_rectangle(color_red(), 300, 300, 200, 200)

# Refresh the screen to display the drawing
refresh_screen()

# Wait for 5 seconds to observe the result
delay(5000)

# Close the window
close_all_windows()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### PUSH CLIP

The following code shows an examples of using [Push Clip](/api/graphics#push-clip) to push push a small clipping area and draw a rectangle within it, then draw outside to show contrast.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using SplashKitSDK;

public class Program
{
public static void Main()
{
// Open a window with the title "Reset Clip" and dimensions 800x600
Window window= SplashKit.OpenWindow("Reset Clip", 800, 600);
Rectangle rectangle = SplashKit.RectangleFrom(100, 100, 600, 400);
// Set a clipping area
SplashKit.SetClip(window, rectangle);

// Draw inside the clipping area (will be clipped)
SplashKit.FillRectangle(Color.Blue, 50, 50, 700, 500); // This will be clipped
SplashKit.RefreshScreen();
SplashKit.Delay(1000);

// Draw outside the clipping area (still within the clipped area, so it will be clipped)
SplashKit.FillRectangle(Color.Red, 100, 100, 200, 200);
SplashKit.RefreshScreen();
SplashKit.Delay(1000);

// Reset the clipping area
SplashKit.ResetClip();
SplashKit.ClearScreen(Color.Green); // Clear the screen with a new background color
SplashKit.RefreshScreen(); // Refresh the screen to apply changes
SplashKit.Delay(5000); // Wait for 5 seconds to observe the result

// Close the window
SplashKit.CloseAllWindows();
}
}
Loading