Cześć. Uczę się od niedawna ** Python3** i SDL2. Chciałbym stworzyć ładny przycisk - Button. Jak się za to najlepeij zabrać ?
Poniżej zamieszczam ogólny kod przyciski, który działa. Chciałbym dodać ramkę do przycisku i tekst.
Kopiuj
import sdl2 import sdl2.ext import numpy as np class Button: x : int y : int wdt : int hgh : int r : int g : int b : int def __init__(self, x : int, y : int, width: int, height: int): self.x = x self.y = y self.wdt = width self.hgh = height self.set_color(64, 64, 64) def set_color(self, r : int, g : int, b : int): self.r = r self.g = g self.b = b def cursorHover(self, mouse_x : int, mouse_y : int) -> bool: if( mouse_x >= self.x and mouse_y >= self.y and mouse_x <= self.x + self.wdt and mouse_y <= self.y + self.hgh): self.set_color(128, 128, 128) return True else: self.set_color(64, 64, 64) return False; def draw(self, renderer): renderer.color = sdl2.ext.Color(self.r, self.g, self.b) rect = sdl2.SDL_Rect(self.x, self.y, self.wdt, self.hgh) rect = sdl2.SDL_ renderer.fill(rect)