diff --git a/Difficult_Rocket/command/line.py b/Difficult_Rocket/command/line.py index 17e6d36..62cbd75 100644 --- a/Difficult_Rocket/command/line.py +++ b/Difficult_Rocket/command/line.py @@ -64,7 +64,16 @@ class CommandText: else: return False - def greedy(self, name: str = None): + def greedy(self, name: str = None) -> str: + if name: + self.value_dict[name] = self.text + self.value_list.append(self.text) + return self.text + + def value(self, + name: str = None, + split: str = ' ', + middle: list = ('\'', '\"')): pass def __str__(self): diff --git a/Difficult_Rocket/guis/widgets.py b/Difficult_Rocket/guis/widgets.py index 43593f7..2256b81 100644 --- a/Difficult_Rocket/guis/widgets.py +++ b/Difficult_Rocket/guis/widgets.py @@ -49,13 +49,11 @@ class InputBox(widgets.WidgetBase): """ def __init__(self, - x: int, - y: int, - width: int, - height: int, + x: int, y: int, width: int, height: int, message: str = '', font_name: str = translate.鸿蒙简体, font_size: int = 15, + blod: bool = False, text_color: [int, int, int] = (0, 0, 0, 255), out_line_color: [int, int, int] = (255, 255, 255), cursor_color: [int, int, int] = (255, 255, 255), @@ -65,7 +63,7 @@ class InputBox(widgets.WidgetBase): super().__init__(x, y, width, height) self._text = message self.text = self._text - self.字体 = font.load(font_name, font_size) + self.字体 = font.load(name=font_name, size=font_size, blod=blod) self.字高 = self.字体.ascent - self.字体.descent self.外框距离 = out_line self._输入框 = Label(x=x + out_line, y=y + out_line, @@ -83,6 +81,10 @@ class InputBox(widgets.WidgetBase): width=1, height=self.字高, batch=batch, group=group) + """ + 输入框的属性 + """ + @property def text(self): return self._text @@ -94,10 +96,42 @@ class InputBox(widgets.WidgetBase): self._输入框.text = value @property - def value(self): - return self.text + def opacity(self): + return self._输入框.opacity + + @opacity.setter + def opacity(self, value: int): + assert type(value) is int, 'Input Box\'s opacity must be int!' + self._输入框.opacity = value + self._外框.opacity = value + self._光标.opacity = value + + """ + 事件调用 + """ def _update_position(self): self._输入框.position = self._x + self.外框距离, self._y + self.外框距离 self._外框.position = self._x - self.外框距离, self._y - self.外框距离 self._光标.position = self._x + self.外框距离, self._y + self.外框距离 + + def on_text(self, text): + pass + + def on_text_motion(self, motion): + pass + + def on_text_motion_select(self, motion): + pass + + def on_mouse_press(self, x, y, buttons, modifiers): + pass + + def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers): + pass + + def on_mouse_release(self, x, y, buttons, modifiers): + pass + + def on_commit(self, text: str): + pass diff --git a/libs/pyglet/app/base.py b/libs/pyglet/app/base.py index 3e574c6..ef34a4c 100644 --- a/libs/pyglet/app/base.py +++ b/libs/pyglet/app/base.py @@ -152,6 +152,7 @@ class EventLoop(event.EventDispatcher): for window in app.windows: window.switch_to() window.dispatch_event('on_draw') + window.dispatch_event('on_refresh', dt) window.flip() def run(self, interval=1/60): @@ -162,7 +163,7 @@ class EventLoop(event.EventDispatcher): Developers are discouraged from overriding this method, as the implementation is platform-specific. """ - self.clock.schedule_interval_soft(self._redraw_windows, interval) + self.clock.schedule_interval(self._redraw_windows, interval) self.has_exit = False diff --git a/libs/pyglet/sprite.py b/libs/pyglet/sprite.py index 9182835..1737a4e 100644 --- a/libs/pyglet/sprite.py +++ b/libs/pyglet/sprite.py @@ -130,21 +130,22 @@ vertex_source = """#version 150 core mat4 view; } window; - mat4 m_trans_scale = mat4(1.0); + mat4 m_scale = mat4(1.0); mat4 m_rotation = mat4(1.0); + mat4 m_translate = mat4(1.0); void main() { - m_trans_scale[3][0] = translate.x; - m_trans_scale[3][1] = translate.y; - m_trans_scale[0][0] = scale.x; - m_trans_scale[1][1] = scale.y; + m_scale[0][0] = scale.x; + m_scale[1][1] = scale.y; + m_translate[3][0] = translate.x; + m_translate[3][1] = translate.y; m_rotation[0][0] = cos(-radians(rotation)); m_rotation[0][1] = sin(-radians(rotation)); m_rotation[1][0] = -sin(-radians(rotation)); m_rotation[1][1] = cos(-radians(rotation)); - gl_Position = window.projection * window.view * m_trans_scale * m_rotation * vec4(position, 0, 1); + gl_Position = window.projection * window.view * m_translate * m_rotation * m_scale * vec4(position, 0, 1); vertex_colors = colors; texture_coords = tex_coords; diff --git a/libs/pyglet/text/layout.py b/libs/pyglet/text/layout.py index a377338..7fe2a08 100644 --- a/libs/pyglet/text/layout.py +++ b/libs/pyglet/text/layout.py @@ -328,7 +328,7 @@ class _GlyphBox(_AbstractBox): try: group = layout.group_cache[self.owner] except KeyError: - group = layout.default_group_class(self.owner, get_default_layout_shader(), order=1, parent=layout.group) + group = layout.group_class(self.owner, get_default_layout_shader(), order=1, parent=layout.group) layout.group_cache[self.owner] = group n_glyphs = self.length @@ -809,7 +809,7 @@ class TextLayout: the desired width if word-wrapping failed. `content_height` : int Calculated height of the text in the layout. - `default_group_class` : `~pyglet.graphics.Group` + `group_class` : `~pyglet.graphics.Group` Top-level rendering group. `background_decoration_group` : `~pyglet.graphics.Group` Rendering group for background color. @@ -823,7 +823,8 @@ class TextLayout: _update_enabled = True _own_batch = False - default_group_class = TextLayoutGroup + group_class = TextLayoutGroup + decoration_class = TextDecorationGroup _x = 0 _y = 0 @@ -870,8 +871,8 @@ class TextLayout: self._user_group = group decoration_shader = get_default_decoration_shader() - self.background_decoration_group = TextDecorationGroup(decoration_shader, order=0, parent=self._user_group) - self.foreground_decoration_group = TextDecorationGroup(decoration_shader, order=2, parent=self._user_group) + self.background_decoration_group = self.decoration_class(decoration_shader, order=0, parent=self._user_group) + self.foreground_decoration_group = self.decoration_class(decoration_shader, order=2, parent=self._user_group) self.group_cache = {} @@ -1771,7 +1772,8 @@ class ScrollableTextLayout(TextLayout): Use `view_x` and `view_y` to scroll the text within the viewport. """ - default_group_class = ScrollableTextLayoutGroup + group_class = ScrollableTextLayoutGroup + decoration_class = ScrollableTextDecorationGroup _translate_x = 0 _translate_y = 0 @@ -1911,7 +1913,8 @@ class IncrementalTextLayout(TextLayout, EventDispatcher): _selection_color = [255, 255, 255, 255] _selection_background_color = [46, 106, 197, 255] - default_group_class = IncrementalTextLayoutGroup + group_class = IncrementalTextLayoutGroup + decoration_class = IncrementalTextDecorationGroup _translate_x = 0 _translate_y = 0 @@ -1931,9 +1934,7 @@ class IncrementalTextLayout(TextLayout, EventDispatcher): self.owner_runs = runlist.RunList(0, None) super().__init__(document, width, height, multiline, dpi, batch, group, wrap_lines) - self._update_translation() - self._update() self._update_scissor_area() def _update_scissor_area(self): @@ -2177,8 +2178,6 @@ class IncrementalTextLayout(TextLayout, EventDispatcher): if line.y + line.ascent > self._translate_y - self.height: end = max(end, i) + 1 - # print("Visible line start/end:", self.visible_lines.start, self.visible_lines.end) - # Delete newly invisible lines for i in range(self.visible_lines.start, min(start, len(self.lines))): self.lines[i].delete(self) @@ -2242,8 +2241,9 @@ class IncrementalTextLayout(TextLayout, EventDispatcher): @x.setter def x(self, x): self._x = x - self.on_insert_text(0, self._document.text) - self._update() + self._uninit_document() + self._init_document() + self._update_scissor_area() @property def y(self): @@ -2252,8 +2252,9 @@ class IncrementalTextLayout(TextLayout, EventDispatcher): @y.setter def y(self, y): self._y = y - self.on_insert_text(0, self._document.text) - self._update() + self._uninit_document() + self._init_document() + self._update_scissor_area() @property def position(self): @@ -2261,7 +2262,9 @@ class IncrementalTextLayout(TextLayout, EventDispatcher): @position.setter def position(self, position): - self.x, self.y = position + self._x, self._y = position + self._uninit_document() + self._init_document() self._update_scissor_area() @property diff --git a/libs/pyglet/window/__init__.py b/libs/pyglet/window/__init__.py index 73d6a5e..676cbe9 100644 --- a/libs/pyglet/window/__init__.py +++ b/libs/pyglet/window/__init__.py @@ -602,12 +602,12 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)): self.switch_to() + self._create_projection() + if visible: self.set_visible(True) self.activate() - self._create_projection() - def _create_projection(self): self._default_program = shader.ShaderProgram(shader.Shader(self._default_vertex_source, 'vertex')) self.ubo = self._default_program.uniform_blocks['WindowBlock'].create_ubo() @@ -1717,7 +1717,7 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)): :event: """ - def on_draw(self): + def on_draw(self, dt): """The window contents must be redrawn. The `EventLoop` will dispatch this event when the window @@ -1737,6 +1737,25 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)): :event: """ + def on_refresh(self, dt): + """The window contents must be redrawn. + + The `EventLoop` will dispatch this event when the window + should be redrawn. + + The window will already have the GL context, so there is no + need to call `switch_to`. The window's `flip` method will + be called after this event, so your event handler should not. + + You should make no assumptions about the window contents when + this event is triggered; a resize or expose event may have + invalidated the framebuffer since the last time it was drawn. + + .. versionadded:: 2.0 + + :event: + """ + BaseWindow.register_event_type('on_key_press') BaseWindow.register_event_type('on_key_release') @@ -1762,6 +1781,7 @@ BaseWindow.register_event_type('on_context_lost') BaseWindow.register_event_type('on_context_state_lost') BaseWindow.register_event_type('on_file_drop') BaseWindow.register_event_type('on_draw') +BaseWindow.register_event_type('on_refresh') class FPSDisplay: diff --git a/textures/icon.png b/textures/icon.png new file mode 100644 index 0000000..96ace26 Binary files /dev/null and b/textures/icon.png differ