def loop(self): while (self.window.is_open): #INPUT pynk.lib.nk_input_begin(self.gui.ctx) for event in self.window.events: if (event.type == sf.Event.CLOSED): self.window.close() elif (event.type == sf.Event.RESIZED): self.winH = event.items()._mapping.event.height self.window.view = sf.View( sf.Rect( (0, 0), (event.items()._mapping.event.width, self.winH))) self.gui.eventsToGui(event) pynk.lib.nk_input_end(self.gui.ctx) #draw self.gui.gui_loop(self.winH, self.window, self.cpu_ifs, self.gpu_ifs, self.general) self.window.clear() self.gui.draw(self.window) if self.cpu_ifs.screen != None: defaultView = self.window.view self.window.view = self.view self.window.draw(self.cpu_ifs.screen) self.window.view = defaultView self.window.display()
def __init__(self, target): super().__init__(target) self.next_scene = None size = self.target.size view = sf.View(sf.Rectangle((0, 0), (size.x, size.y))) self.target.view = view font = sf.Font.from_file(assets.get_asset("/fonts/Amethyst.ttf")) # Title self.title = sf.Text() self.title.string = "Reversi" self.title.font = font self.title.color = sf.Color.WHITE title_bounds = self.title.global_bounds # Menu items self.menuitems = [] for item in [["Spela en spelare", self._switch_colormenu], ["Spela två spelare", self._switch_sizemenu], ["Avsluta", target.close]]: button = Button(target, item[0]) button.set_listener(item[1]) self.menuitems.append(button) self.add_component(button) self._setup_buttons()
def __init__(self, target): self.target = target self.background_image = sf.Sprite( sf.Texture.from_file(target.dialog_background)) self.dialog_icon = sf.Sprite(sf.Texture.from_file(target.dialog_icon)) self.label = target.label self.next_label = self.label ### ATTENTION ^ BUG IF STRING IS EMPTY` self.name = sf.Text(target.name, sf.Font.from_file("data/font.ttf"), 40) self.name.position = 300, 475 #self.name.string = target.name self.name.color = sf.Color(241, 213, 169) #self.dialog_file = target.dialog_file with open(target.dialog_file) as data_file: self.data = json.load(data_file) #print(self.data[self.label]) #self.font = sf.Font.from_file() self.text = sf.Text(self.data[self.label]['text'], sf.Font.from_file("data/font.ttf"), 40) #self.text.string = self.data[self.label]['text'] self.text.position = 500, 610 self.text.color = sf.Color(45, 35, 18) self.answers = [] self.cursor = sf.RectangleShape() self.cursor.fill_color = sf.Color(30, 40, 50, 60) self.cursor.size = 300, 30 self.cursor.position = 50, 565 self.loadAnswers() self.texture = sf.Texture.create(window.size.x, window.size.y) self.texture.update(window) self.sprite = sf.Sprite(self.texture) self.camera = sf.View() self.camera.reset([0, 0, 1280, 800]) window.view = self.camera
def default_event_handler(event): if event == sf.Event.CLOSED: window.close() elif event == sf.Event.KEY_PRESSED: if event['code'] == sf.Keyboard.TILDE: state_machine.addState(Console()) elif event == sf.Event.RESIZED: visibleArea = [0, 0, event['width'], event['height']] window.view = sf.View(visibleArea)
def event(self, events): super().event(events) for e in events: if type(e) == sf.ResizeEvent: size = self.target.size view = sf.View(sf.Rectangle((0, 0), (size.x, size.y))) self.target.view = view self._setup_components()
def event(self, events): super().event(events) for e in events: if type(e) == sf.ResizeEvent: # Window has been resized. Resize components. size = self.target.size view = sf.View(sf.Rectangle((0, 0), (size.x, size.y))) self.target.view = view self._setup_buttons()
def __init__(self): self.view = sf.View(sf.Rect((0, 0), (500, 500))) self.view.viewport = (sf.Rect((0.474, 0.2685), (0.26, 0.463))) self.settings = sf.ContextSettings() self.settings.antialiasing_level = 8 self.window = sf.RenderWindow(sf.VideoMode(1920, 1080), "IFS Flame Fractal Generator", sf.Style.DEFAULT, self.settings) self.window.framerate_limit = 60 self.general = ifs_general() self.cpu_ifs = ifs_cpu(self.general) self.gpu_ifs = ifs_gpu(self.general) self.gui = ui()
def __init__(self, target): self.camera = sf.View() self.camera.reset([0, 0, 1280, 800]) window.view = self.camera self.texture = sf.Texture.create(window.size.x, window.size.y) self.texture.update(window) self.sprite = sf.Sprite(self.texture) self.background = sf.Sprite( sf.Texture.from_file("data/images/inventory_background2.png")) codes = state_machine.states[len(state_machine.states) - 1].player.inventory self.inventory = [] for code in codes: self.inventory.append(InventoryObject(code)) begin = {'x': 505, 'y': 165} #355,162 self.offset = 57 group_by = 10 counter = -1 row = 0 for c, obj in enumerate(self.inventory, 0): counter += 1 if counter >= group_by: counter = 0 row += 1 obj.sprite.position = [ begin['x'] + counter * self.offset, begin['y'] + self.offset * row ] self.info_table = sf.Text("", sf.Font.from_file("data/font.ttf"), 20) self.cursor = sf.Sprite( sf.Texture.from_file("data/images/inventory_cursor.png")) self.cursor.position = [begin['x'] - 6, begin['y'] - 7] self.info_table.position = [ begin['x'] + self.offset, begin['y'] + self.offset ] self.cursor_target = 0 #self.cursor.position = [self.inventory[self.cursor_target].position.x-6,self.inventory[self.cursor_target].position.y-8] try: self.info_table.string = self.inventory[0].description except Exception as e: print(e)
def __init__(self): self.camera = sf.View() self.camera.reset([0, 0, 1280, 800]) window.view = self.camera self.texture = sf.Texture.create(window.size.x, window.size.y) self.texture.update(window) self.sprite = sf.Sprite(self.texture) self.rect = sf.RectangleShape() self.rect.position = 0, 0 self.rect.size = window.size.x, window.size.y / 2 self.rect.fill_color = sf.Color(30, 30, 30, 200) self.text = sf.Text("", sf.Font.from_file("data/files/fonts/Bricks.otf"), 20) self.ps1 = sf.Text("->: ", sf.Font.from_file("data/font.ttf"), 20) self.ps1.position = 0, window.size.y / 2 - 30 self.text.position = 25, window.size.y / 2 - 30 self.shader = sf.Shader.from_file(fragment="data/blur.frag") self.shader.set_parameter("source") self.shader.set_parameter("offsetFactor", 0.00075, 0.00075) self.states = sf.RenderStates() self.states.shader = self.shader
def __call__(self, scrollSpeed=50): current_view = sf.View() current_view.reset( sf.Rectangle((0, 0), (self._mode.width, self._mode.width))) window = sf.RenderWindow(self._mode, "Fractal Application.", sf.Style.TITLEBAR + sf.Style.CLOSE) while window.is_open: for event in window.events: if type(event) is sf.CloseEvent: window.close() elif type(event) is sf.KeyEvent and event.pressed: if sf.Keyboard.is_key_pressed(sf.Keyboard.NUM1): self._fractal = MandelbrotSet(self._mode.width, self._mode.height) elif sf.Keyboard.is_key_pressed(sf.Keyboard.NUM2): self._fractal = KochSnowflake(5) elif sf.Keyboard.is_key_pressed(sf.Keyboard.NUM3): self._fractal = SerpinskiTriangle( 0, (320, 100), (100, 500), (540, 500)) elif type(event) is sf.MouseWheelEvent: if event.delta > 0: current_view.size = (current_view.size.x - scrollSpeed, current_view.size.y - scrollSpeed) elif event.delta < 0: current_view.size = (current_view.size.x + scrollSpeed, current_view.size.y + scrollSpeed) elif type(event) is sf.MouseMoveEvent: if sf.Mouse.is_button_pressed(sf.Mouse.LEFT): x, y = event.position current_view.center = self._mode.width - x, self._mode.height - y window.view = current_view window.clear(sf.Color.WHITE) window.draw(self._fractal) window.display()
def mainloop(pis): size = sf.Vector2(1024, 600) vmode = sf.VideoMode(1024, 600) view = sf.View() view.size = size view.center = sf.Vector2(0, 0) window = sf.RenderWindow(vmode, "tokenring", sf.Style.FULLSCREEN) window.framerate_limit = 60 window.view = view clothes = [PiCloth(pi, 30) for p, pi in sorted(pis.items())] place_in_circle(clothes, size) selected_player = None observable_cloth = None world = None brush = sf.CircleShape(10) selected = set() while window.is_open: for event in window.events: if event == sf.Event.CLOSED: window.close() if event == sf.Event.MOUSE_BUTTON_PRESSED: v = sf.Vector2(event['x'], event['y']) - size / 2 target = get_cloth_under(clothes, v) if event['button'] == sfml.window.Button.LEFT and target: methods = ['add', 'remove'] getattr(selected, methods[target in selected])(target) if event['button'] == sfml.window.Button.RIGHT and target: observable_cloth = target t = time() maxtime = max(t - c.pi.ltt for c in clothes if c.pi.ltt > 0) mp = sf.Mouse.get_position(window) mp -= size / 2 selected_player = None for c in clothes: c.resolve_color(t, maxtime) if c.under(mp): selected_player = c if observable_cloth: observable_cloth.fill_color = sf.Color.BLUE world = observable_cloth.pi.world for selected_player in selected: selected_player.fill_color = sf.Color.YELLOW play_with_selected(selected_player) window.clear(sf.Color.BLACK) for c in clothes: window.draw(c) draw_world(world, window, brush) window.display()