继续干活

This commit is contained in:
shenjack 2023-08-20 02:01:15 +08:00
parent 5f335fa9b5
commit bff9649ca9
Signed by: shenjack
GPG Key ID: 7B1134A979775551

View File

@ -16,7 +16,7 @@ from typing import Optional, Union, Tuple
# from libs import pyglet # from libs import pyglet
# from pyglet import font # from pyglet import font
from pyglet.text import Label, HTMLLabel from pyglet.text import Label, HTMLLabel
# from pyglet.window import key from pyglet.window import key
from pyglet.gui import widgets from pyglet.gui import widgets
# from pyglet.sprite import Sprite # from pyglet.sprite import Sprite
from pyglet.shapes import Rectangle from pyglet.shapes import Rectangle
@ -30,7 +30,7 @@ from Difficult_Rocket.api.types import Fonts
from Difficult_Rocket import DR_status from Difficult_Rocket import DR_status
class TextButton(widgets.WidgetBase): class PressTextButton(widgets.WidgetBase):
""" """
自带 字符 + 材质 的按钮就不用单独做材质了 自带 字符 + 材质 的按钮就不用单独做材质了
""" """
@ -56,16 +56,44 @@ class TextButton(widgets.WidgetBase):
self.front_group = Group(order=5) self.front_group = Group(order=5)
self.back_ground_group = Group(order=10) self.back_ground_group = Group(order=10)
self.untouched_color = (39, 73, 114, 255)
self.touched_color = (66, 150, 250, 255)
self.hit_color = (15, 135, 250, 255)
# from ImGui
self.text = text self.text = text
self.text_label = Label(font_name=font, font_size=font_size, self.text_label = Label(font_name=font, font_size=font_size,
batch=self.front_batch, group=self.front_group) batch=self.front_batch, group=self.front_group)
self.back_rec = Rectangle(x=self._x, y=self._y, width=self._width, height=self._height, self.back_rec = Rectangle(x=self._x, y=self._y, width=self._width, height=self._height,
color=self.untouched_color, # ImGui color
batch=self.back_ground_batch, group=self.back_ground_group) batch=self.back_ground_batch, group=self.back_ground_group)
@property @property
def value(self): def value(self):
return self.text return self.text
def __contains__(self, item):
return item in self.back_rec
def on_mouse_motion(self, x, y, dx, dy):
if (x, y) in self:
self.back_rec.color = self.touched_color
else:
self.back_rec.color = self.untouched_color
def on_mouse_press(self, x, y, buttons, modifiers):
if (x, y) in self:
self.back_rec.color = self.hit_color
self.dispatch_event('on_press', x, y)
return True
return False
def _update_position(self): def _update_position(self):
self.text_label.position = self._x, self._y self.text_label.position = self._x, self._y
self.back_rec.position = self._x, self._y
self.back_rec.width = self._width
self.back_rec.height = self._height
... ...
PressTextButton.register_event_type('on_press')