def test(): my_test_engine = TestEngine(400, 300, 'Testing different UI elements') # Create UI elements text1 = UI.Text(my_test_engine, rect=pygame.Rect(30, 30, 60, 20), text='Hello') text2 = UI.Text(my_test_engine, rect=pygame.Rect(30, 65, 60, 20), text='World!', background_color=(200, 200, 200, 50)) text3 = UI.Text(my_test_engine, rect=pygame.Rect(30, 100, 150, 20), z=5, text='0', background_color=(70, 200, 70)) text4 = UI.Text(my_test_engine, rect=pygame.Rect(100, 120, 120, 20), z=4, text='') textbox1 = UI.TextBox(my_test_engine, rect=pygame.Rect(100, 30, 180, 20), background_text='Username') textbox2 = UI.TextBox(my_test_engine, rect=pygame.Rect(100, 65, 180, 20), background_text='Password') checkbox1 = UI.CheckBox(my_test_engine, rect=pygame.Rect(290, 30, 14, 14)) checkbox2 = UI.CheckBox(my_test_engine, rect=pygame.Rect(290, 65, 14, 14)) button1 = UI.Button(my_test_engine, rect=pygame.Rect(310, 30, 70, 20), text='Press me') button2 = UI.Button(my_test_engine, rect=pygame.Rect(310, 65, 50, 20), text='Don\'t') textbox1.set_callback(display_text_input) textbox2.set_callback(display_text_input) checkbox1.set_callback(display_checked) checkbox2.set_callback(display_checked) button1.set_callback(display_button) button2.set_callback(display_button) # Test setting and getting of each UI element (only one per class is necessary) test_text(text1) test_textbox(textbox1) # test moving text and setting visibility text1.rect = pygame.Rect(30, 20, text1.rect.width, text1.rect.height) text2.visible = False text3.text = 'This was an update counter' text4.text = 'This was blank' while True: my_test_engine.update() my_test_engine.render() pygame.time.delay(20)
button_img2 = UI.Button( x = 250, y = 350, param_options={ 'image' : img, 'hover_image':hover_img, 'text' : "Button4" } ) checkBox = UI.CheckBox( 300, 180, 30, { 'outline':True, 'background_color': (200, 200, 200) } ) running = True # Game Loop while running: pygame.display.update() screen.fill((255,255,255)) #pygame.draw.rect(screen,(255,0,0),(100,100,100,100)) #draw and update our buttons and textbox InputBox.update()
def __init__(self): #sys vars self.running = True self.click = False self.hold = False self.startHold = None self.size = (300,500) self.screen = pygame.display.set_mode(self.size) self.clock = pygame.time.Clock() self.current_screen = self.Main_menu self.sys_font = pygame.font.Font(pygame.font.match_font('Calibri'), 40) self.mouse_drag_start = None self.swipe_dir = [] self.swipe = '' #hunt specefic vars self.hunt_id = None self.all_questions = [] self.current_question = 0 #BUTTONS button_theme = { 'outline': True, 'curve': 0.4, 'background_color': (255, 0, 0) } button_theme_new = button_theme.copy() button_theme_new.update({'dont_generate': True}) #buttons for Main menu self.Main_menu_buttons = [ UI.Button( self.size[0]//2 - 100, 100 + dy*100, 200, 40, button_theme_new) for dy in range(3)] #set text and actions to main menu buttons self.Main_menu_buttons[0].Update_text("history") self.Main_menu_buttons[1].Update_text("Hunt") self.Main_menu_buttons[2].Update_text("Scan") self.Main_menu_buttons[0].on_click = History_button self.Main_menu_buttons[1].on_click = Start_hunt_button self.Main_menu_buttons[2].on_click = Scan_button button_theme_new = button_theme.copy() button_theme_new.update({'on_click': Question_button, 'text': 'Question'}) self.current_question_button = UI.Button( self.size[0]//2 - 100, 400, 200, 40, button_theme_new) #create the buttons on camera screen surf = pygame.Surface((30,30), pygame.SRCALPHA) for y in range(3): pygame.draw.line(surf,(255,255,255),(0,5 + y*10),(30,5 + y*10), 1) button_theme_new = button_theme.copy() button_theme_new.update({'image': surf, 'enlarge': True, 'on_click': Camera_main_menu_button}) self.Camera_menu_button = UI.Button(self.size[0] - 60,self.size[1] - 60, param_options=button_theme_new) surf = pygame.Surface((30,30),pygame.SRCALPHA) surf2 = pygame.Surface((40,40),pygame.SRCALPHA) pygame.draw.circle(surf,(255,255,255),(15,15),15,2) pygame.draw.circle(surf2, (255,255,255), (20,20), 20,2) button_theme_new = button_theme.copy() button_theme_new.update({'image': surf, 'hover_image': surf2 }) self.Camera_settings_button = UI.Button(self.size[0]//4-20, self.size[1] - 60, param_options=button_theme_new) surf = pygame.Surface((60,60),pygame.SRCALPHA) surf2 = pygame.Surface((60,60),pygame.SRCALPHA) pygame.draw.circle(surf, (255,255,255),(30,30),30,4) pygame.draw.circle(surf2, (255,255,255),(30,30),30,8) button_theme_new = button_theme.copy() button_theme_new.update({'image': surf, 'hover_image': surf2 }) self.Camera_take_photo_button = UI.Button(self.size[0]//2 - 30,self.size[1] - 90, param_options=button_theme_new) #Settings self.settings_check_boxes = [UI.CheckBox(200,150 + 50*i,40, {'background_color': (200,200,200), 'outline': True} ) for i in range(3)] self.setting_back_button = UI.Button(50, 400, 200, 40, {'background_color': (255, 0, 0), 'curve': 0.4, 'text': 'Back', 'outline': True } ) #all hunts self.hunt_names = db.get_all_hunts() + [['Cancel']] self.hunt_names_buttons = [UI.Button(50, 100 + 100*i,200, 40, { 'background_color': (255,0,0), 'outline': True, 'text': self.hunt_names[i][0], 'curve': 0.4} ) for i in range(len(self.hunt_names))] num_hunts = db.num_hunts() if num_hunts > 3: scroll_amount = (num_hunts - 3) * 100 self.hunt_screen_scroll = UI.Scroll({'range_y': scroll_amount}) else: self.hunt_screen_scroll = None
enlarge = True, text = "" ) button_img2 = UI.Button( x = 350, y = 350, image = img, hover_image=hover_img, text = "Button4" ) checkBox = UI.CheckBox( 300, 180, 30, outline=UI.Outline(), background=(200,200,200) ) running = True # Game Loop while running: pygame.display.update() screen.fill((255,255,255)) #pygame.draw.rect(screen,(255,0,0),(100,100,100,100))
import pygame import UI #setup pygame pygame.init() screen = UI.Window(500, 400) #creates a window 500x400 checkBox = UI.CheckBox(250, 250, 30, { 'outline': UI.Outline(), 'background': (200, 200, 200) }) print(checkBox.backgound) running = True # Game Loop while running: pygame.display.update() screen.fill((255, 255, 255)) checkBox.update() if checkBox: print("checkBox = true") for e in pygame.event.get(): # checks all events that happen if e.type == pygame.QUIT: running = False pygame.quit()