ah!
This commit is contained in:
parent
42c28aff4a
commit
fd343d877f
@ -64,7 +64,16 @@ class CommandText:
|
|||||||
else:
|
else:
|
||||||
return False
|
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
|
pass
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -49,13 +49,11 @@ class InputBox(widgets.WidgetBase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
x: int,
|
x: int, y: int, width: int, height: int,
|
||||||
y: int,
|
|
||||||
width: int,
|
|
||||||
height: int,
|
|
||||||
message: str = '',
|
message: str = '',
|
||||||
font_name: str = translate.鸿蒙简体,
|
font_name: str = translate.鸿蒙简体,
|
||||||
font_size: int = 15,
|
font_size: int = 15,
|
||||||
|
blod: bool = False,
|
||||||
text_color: [int, int, int] = (0, 0, 0, 255),
|
text_color: [int, int, int] = (0, 0, 0, 255),
|
||||||
out_line_color: [int, int, int] = (255, 255, 255),
|
out_line_color: [int, int, int] = (255, 255, 255),
|
||||||
cursor_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)
|
super().__init__(x, y, width, height)
|
||||||
self._text = message
|
self._text = message
|
||||||
self.text = self._text
|
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.字高 = self.字体.ascent - self.字体.descent
|
||||||
self.外框距离 = out_line
|
self.外框距离 = out_line
|
||||||
self._输入框 = Label(x=x + out_line, y=y + out_line,
|
self._输入框 = Label(x=x + out_line, y=y + out_line,
|
||||||
@ -83,6 +81,10 @@ class InputBox(widgets.WidgetBase):
|
|||||||
width=1, height=self.字高,
|
width=1, height=self.字高,
|
||||||
batch=batch, group=group)
|
batch=batch, group=group)
|
||||||
|
|
||||||
|
"""
|
||||||
|
输入框的属性
|
||||||
|
"""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self):
|
def text(self):
|
||||||
return self._text
|
return self._text
|
||||||
@ -94,10 +96,42 @@ class InputBox(widgets.WidgetBase):
|
|||||||
self._输入框.text = value
|
self._输入框.text = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def value(self):
|
def opacity(self):
|
||||||
return self.text
|
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):
|
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.外框距离
|
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
|
||||||
|
@ -152,6 +152,7 @@ class EventLoop(event.EventDispatcher):
|
|||||||
for window in app.windows:
|
for window in app.windows:
|
||||||
window.switch_to()
|
window.switch_to()
|
||||||
window.dispatch_event('on_draw')
|
window.dispatch_event('on_draw')
|
||||||
|
window.dispatch_event('on_refresh', dt)
|
||||||
window.flip()
|
window.flip()
|
||||||
|
|
||||||
def run(self, interval=1/60):
|
def run(self, interval=1/60):
|
||||||
@ -162,7 +163,7 @@ class EventLoop(event.EventDispatcher):
|
|||||||
Developers are discouraged from overriding this method, as the
|
Developers are discouraged from overriding this method, as the
|
||||||
implementation is platform-specific.
|
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
|
self.has_exit = False
|
||||||
|
|
||||||
|
@ -130,21 +130,22 @@ vertex_source = """#version 150 core
|
|||||||
mat4 view;
|
mat4 view;
|
||||||
} window;
|
} window;
|
||||||
|
|
||||||
mat4 m_trans_scale = mat4(1.0);
|
mat4 m_scale = mat4(1.0);
|
||||||
mat4 m_rotation = mat4(1.0);
|
mat4 m_rotation = mat4(1.0);
|
||||||
|
mat4 m_translate = mat4(1.0);
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
m_trans_scale[3][0] = translate.x;
|
m_scale[0][0] = scale.x;
|
||||||
m_trans_scale[3][1] = translate.y;
|
m_scale[1][1] = scale.y;
|
||||||
m_trans_scale[0][0] = scale.x;
|
m_translate[3][0] = translate.x;
|
||||||
m_trans_scale[1][1] = scale.y;
|
m_translate[3][1] = translate.y;
|
||||||
m_rotation[0][0] = cos(-radians(rotation));
|
m_rotation[0][0] = cos(-radians(rotation));
|
||||||
m_rotation[0][1] = sin(-radians(rotation));
|
m_rotation[0][1] = sin(-radians(rotation));
|
||||||
m_rotation[1][0] = -sin(-radians(rotation));
|
m_rotation[1][0] = -sin(-radians(rotation));
|
||||||
m_rotation[1][1] = cos(-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;
|
vertex_colors = colors;
|
||||||
texture_coords = tex_coords;
|
texture_coords = tex_coords;
|
||||||
|
@ -328,7 +328,7 @@ class _GlyphBox(_AbstractBox):
|
|||||||
try:
|
try:
|
||||||
group = layout.group_cache[self.owner]
|
group = layout.group_cache[self.owner]
|
||||||
except KeyError:
|
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
|
layout.group_cache[self.owner] = group
|
||||||
|
|
||||||
n_glyphs = self.length
|
n_glyphs = self.length
|
||||||
@ -809,7 +809,7 @@ class TextLayout:
|
|||||||
the desired width if word-wrapping failed.
|
the desired width if word-wrapping failed.
|
||||||
`content_height` : int
|
`content_height` : int
|
||||||
Calculated height of the text in the layout.
|
Calculated height of the text in the layout.
|
||||||
`default_group_class` : `~pyglet.graphics.Group`
|
`group_class` : `~pyglet.graphics.Group`
|
||||||
Top-level rendering group.
|
Top-level rendering group.
|
||||||
`background_decoration_group` : `~pyglet.graphics.Group`
|
`background_decoration_group` : `~pyglet.graphics.Group`
|
||||||
Rendering group for background color.
|
Rendering group for background color.
|
||||||
@ -823,7 +823,8 @@ class TextLayout:
|
|||||||
|
|
||||||
_update_enabled = True
|
_update_enabled = True
|
||||||
_own_batch = False
|
_own_batch = False
|
||||||
default_group_class = TextLayoutGroup
|
group_class = TextLayoutGroup
|
||||||
|
decoration_class = TextDecorationGroup
|
||||||
|
|
||||||
_x = 0
|
_x = 0
|
||||||
_y = 0
|
_y = 0
|
||||||
@ -870,8 +871,8 @@ class TextLayout:
|
|||||||
self._user_group = group
|
self._user_group = group
|
||||||
|
|
||||||
decoration_shader = get_default_decoration_shader()
|
decoration_shader = get_default_decoration_shader()
|
||||||
self.background_decoration_group = TextDecorationGroup(decoration_shader, order=0, parent=self._user_group)
|
self.background_decoration_group = self.decoration_class(decoration_shader, order=0, parent=self._user_group)
|
||||||
self.foreground_decoration_group = TextDecorationGroup(decoration_shader, order=2, parent=self._user_group)
|
self.foreground_decoration_group = self.decoration_class(decoration_shader, order=2, parent=self._user_group)
|
||||||
|
|
||||||
self.group_cache = {}
|
self.group_cache = {}
|
||||||
|
|
||||||
@ -1771,7 +1772,8 @@ class ScrollableTextLayout(TextLayout):
|
|||||||
Use `view_x` and `view_y` to scroll the text within the viewport.
|
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_x = 0
|
||||||
_translate_y = 0
|
_translate_y = 0
|
||||||
@ -1911,7 +1913,8 @@ class IncrementalTextLayout(TextLayout, EventDispatcher):
|
|||||||
_selection_color = [255, 255, 255, 255]
|
_selection_color = [255, 255, 255, 255]
|
||||||
_selection_background_color = [46, 106, 197, 255]
|
_selection_background_color = [46, 106, 197, 255]
|
||||||
|
|
||||||
default_group_class = IncrementalTextLayoutGroup
|
group_class = IncrementalTextLayoutGroup
|
||||||
|
decoration_class = IncrementalTextDecorationGroup
|
||||||
|
|
||||||
_translate_x = 0
|
_translate_x = 0
|
||||||
_translate_y = 0
|
_translate_y = 0
|
||||||
@ -1931,9 +1934,7 @@ class IncrementalTextLayout(TextLayout, EventDispatcher):
|
|||||||
self.owner_runs = runlist.RunList(0, None)
|
self.owner_runs = runlist.RunList(0, None)
|
||||||
|
|
||||||
super().__init__(document, width, height, multiline, dpi, batch, group, wrap_lines)
|
super().__init__(document, width, height, multiline, dpi, batch, group, wrap_lines)
|
||||||
|
|
||||||
self._update_translation()
|
self._update_translation()
|
||||||
self._update()
|
|
||||||
self._update_scissor_area()
|
self._update_scissor_area()
|
||||||
|
|
||||||
def _update_scissor_area(self):
|
def _update_scissor_area(self):
|
||||||
@ -2177,8 +2178,6 @@ class IncrementalTextLayout(TextLayout, EventDispatcher):
|
|||||||
if line.y + line.ascent > self._translate_y - self.height:
|
if line.y + line.ascent > self._translate_y - self.height:
|
||||||
end = max(end, i) + 1
|
end = max(end, i) + 1
|
||||||
|
|
||||||
# print("Visible line start/end:", self.visible_lines.start, self.visible_lines.end)
|
|
||||||
|
|
||||||
# Delete newly invisible lines
|
# Delete newly invisible lines
|
||||||
for i in range(self.visible_lines.start, min(start, len(self.lines))):
|
for i in range(self.visible_lines.start, min(start, len(self.lines))):
|
||||||
self.lines[i].delete(self)
|
self.lines[i].delete(self)
|
||||||
@ -2242,8 +2241,9 @@ class IncrementalTextLayout(TextLayout, EventDispatcher):
|
|||||||
@x.setter
|
@x.setter
|
||||||
def x(self, x):
|
def x(self, x):
|
||||||
self._x = x
|
self._x = x
|
||||||
self.on_insert_text(0, self._document.text)
|
self._uninit_document()
|
||||||
self._update()
|
self._init_document()
|
||||||
|
self._update_scissor_area()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def y(self):
|
def y(self):
|
||||||
@ -2252,8 +2252,9 @@ class IncrementalTextLayout(TextLayout, EventDispatcher):
|
|||||||
@y.setter
|
@y.setter
|
||||||
def y(self, y):
|
def y(self, y):
|
||||||
self._y = y
|
self._y = y
|
||||||
self.on_insert_text(0, self._document.text)
|
self._uninit_document()
|
||||||
self._update()
|
self._init_document()
|
||||||
|
self._update_scissor_area()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def position(self):
|
def position(self):
|
||||||
@ -2261,7 +2262,9 @@ class IncrementalTextLayout(TextLayout, EventDispatcher):
|
|||||||
|
|
||||||
@position.setter
|
@position.setter
|
||||||
def position(self, position):
|
def position(self, position):
|
||||||
self.x, self.y = position
|
self._x, self._y = position
|
||||||
|
self._uninit_document()
|
||||||
|
self._init_document()
|
||||||
self._update_scissor_area()
|
self._update_scissor_area()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -602,12 +602,12 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)):
|
|||||||
|
|
||||||
self.switch_to()
|
self.switch_to()
|
||||||
|
|
||||||
|
self._create_projection()
|
||||||
|
|
||||||
if visible:
|
if visible:
|
||||||
self.set_visible(True)
|
self.set_visible(True)
|
||||||
self.activate()
|
self.activate()
|
||||||
|
|
||||||
self._create_projection()
|
|
||||||
|
|
||||||
def _create_projection(self):
|
def _create_projection(self):
|
||||||
self._default_program = shader.ShaderProgram(shader.Shader(self._default_vertex_source, 'vertex'))
|
self._default_program = shader.ShaderProgram(shader.Shader(self._default_vertex_source, 'vertex'))
|
||||||
self.ubo = self._default_program.uniform_blocks['WindowBlock'].create_ubo()
|
self.ubo = self._default_program.uniform_blocks['WindowBlock'].create_ubo()
|
||||||
@ -1717,7 +1717,7 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)):
|
|||||||
:event:
|
:event:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def on_draw(self):
|
def on_draw(self, dt):
|
||||||
"""The window contents must be redrawn.
|
"""The window contents must be redrawn.
|
||||||
|
|
||||||
The `EventLoop` will dispatch this event when the window
|
The `EventLoop` will dispatch this event when the window
|
||||||
@ -1737,6 +1737,25 @@ class BaseWindow(with_metaclass(_WindowMetaclass, EventDispatcher)):
|
|||||||
:event:
|
: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_press')
|
||||||
BaseWindow.register_event_type('on_key_release')
|
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_context_state_lost')
|
||||||
BaseWindow.register_event_type('on_file_drop')
|
BaseWindow.register_event_type('on_file_drop')
|
||||||
BaseWindow.register_event_type('on_draw')
|
BaseWindow.register_event_type('on_draw')
|
||||||
|
BaseWindow.register_event_type('on_refresh')
|
||||||
|
|
||||||
|
|
||||||
class FPSDisplay:
|
class FPSDisplay:
|
||||||
|
BIN
textures/icon.png
Normal file
BIN
textures/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 172 KiB |
Loading…
Reference in New Issue
Block a user