Exemplo n.º 1
0
def click():  # Simple function ilustrating how to add a function to click
    if button.color == Colors().red:
        button.color = Colors().green

        button.placement = (75, 100, 250, 100)
    else:
        button.color = Colors().red

        button.placement = (125, 100, 150, 50)
Exemplo n.º 2
0
import pygame
from UIComponents import Background, Colors, Button, Slider

# ---------- PYGAME SETUP ----------
pygame.init()
size = (400, 700)
surface = pygame.display.set_mode(size)
clock = pygame.time.Clock()
stop = False
# ----------------------------------

# ----- CREATING A BACKGROUND -----
background = Background((10, 200, 300, 400), Colors().red, 120)

# Creating sub objects
slider = Slider((100, 100, 100, 5),
                0,
                100,
                2,
                50,
                Colors().red,
                Colors().black,
                'My current value',
                font_size=20)
button = Button((50, 300, 150, 50), Colors().red, 'Click Me!')

# Adding sub objects
background.add_sub_object(slider)
background.add_sub_object(button)

button_down = False
Exemplo n.º 3
0
stop = False

# ----------------------------------


# -------- CREATING A SLIDER -------
def slide():
    pass


slider1 = Slider((100, 100, 100, 5),
                 0,
                 100,
                 2,
                 50,
                 Colors().red,
                 Colors().black,
                 'My current value',
                 font_size=20,
                 click_function=slide)
slider2 = Slider((100, 300, 200, 5),
                 10,
                 30,
                 0.1,
                 20,
                 Colors().red,
                 Colors().black,
                 'My current value',
                 font_size=20,
                 click_function=slide)
Exemplo n.º 4
0
import pygame
from UIComponents import Background, Colors, Button, Slider

# ---------- PYGAME SETUP ----------
pygame.init()
size = (400, 700)
surface = pygame.display.set_mode(size)
clock = pygame.time.Clock()
stop = False
# ----------------------------------

# ----- CREATING A BACKGROUND -----
background = Background((10, 200, 300, 400), Colors().red, 120)

# Creating sub objects
slider = Slider((100, 100, 100, 5),
                background.position,
                0,
                100,
                2,
                50,
                Colors().red,
                Colors().black,
                5,
                255,
                'My current value',
                font_size=20)
button = Button((50, 300, 150, 50),
                background.position,
                Colors().red,
                255,
Exemplo n.º 5
0
def click():  # Simple function ilustrating how to add a function to click
    if button.color == Colors().red:
        button.color = Colors().green
    else:
        button.color = Colors().red
Exemplo n.º 6
0
clock = pygame.time.Clock()
stop = False

# ----------------------------------


# ---------- CREATING A BUTTON ----------
def click():  # Simple function ilustrating how to add a function to click
    if button.color == Colors().red:
        button.color = Colors().green
    else:
        button.color = Colors().red


button = Button((125, 100, 150, 50), (0, 0),
                Colors().red,
                255,
                'Click Me!',
                font_size=25,
                click_function=click)

# Standard game loop
while not stop:
    # Standard event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            stop = True
        # User clicked mouse button (any)
        elif event.type == pygame.MOUSEBUTTONDOWN:
            # Checking if user has clicked the button and running click_function
            if button.clicked(pygame.mouse.get_pos()):
Exemplo n.º 7
0
import pygame
from UIComponents import Placeholder, Colors, Button, Slider

# ---------- PYGAME SETUP ----------
pygame.init()
size = (400, 700)
surface = pygame.display.set_mode(size)
clock = pygame.time.Clock()
stop = False
# ----------------------------------

# ----- CREATING A PLACEHOLDER -----
placeholder = Placeholder((10, 200, 300, 400))

# Creating sub objects
slider = Slider((100, 100, 100, 5), 0, 100, 2, 50, Colors().red, Colors().black, 'My current value', font_size=20)
button = Button((50, 300, 150, 50), Colors().red, 'Click Me!')

# Adding sub objects
placeholder.add_sub_object(slider)
placeholder.add_sub_object(button)

button_down = False

# Standard game loop
while not stop:
    # Standard event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            stop = True
        # User clicked mouse button (any)
Exemplo n.º 8
0
import pygame
from UIComponents import Slider, Colors

# ---------- PYGAME SETUP ----------
pygame.init()
size = (400, 700)
surface = pygame.display.set_mode(size)
clock = pygame.time.Clock()
stop = False
# ----------------------------------

# -------- CREATING A SLIDER -------
def slide():
    pass

slider1 = Slider((100, 100, 100, 5), (0,0), 0, 100, 2, 50, Colors().red, Colors().black, 5, 255, 'My current value', font_size=20, click_function=slide)
slider2 = Slider((100, 300, 200, 5), (0,0), 10, 30, 0.1, 20, Colors().red, Colors().black, 5, 255, 'My current value', font_size=20, click_function=slide)

button_down = False

# Standard game loop
while not stop:
    # Standard event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            stop = True
        # User clicked mouse button (any)
        elif event.type == pygame.MOUSEBUTTONDOWN:
            # Keep track of if mouse button is still down
            button_down = True
            
Exemplo n.º 9
0
import pygame
from UIComponents import Placeholder, Colors, Button, Slider

# ---------- PYGAME SETUP ----------
pygame.init()
size = (400, 700)
surface = pygame.display.set_mode(size)
clock = pygame.time.Clock()
stop = False
# ----------------------------------

# ----- CREATING A PLACEHOLDER -----
placeholder = Placeholder((10, 200, 300, 400))

# Creating sub objects
slider = Slider((100, 100, 100, 5), placeholder.position, 0, 100, 2, 50, Colors().red, Colors().black, 5, 255, 'My current value', font_size=20)
button = Button((50, 300, 150, 50), placeholder.position, Colors().red, 255, 'Click Me!', font_size=25)

# Adding sub objects
placeholder.add_sub_object(slider)
placeholder.add_sub_object(button)

button_down = False

# Standard game loop
while not stop:
    # Standard event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            stop = True
        # User clicked mouse button (any)