GUI#
- class arcade.gui.Surface(*, size: Tuple[int, int], position: Tuple[int, int] = (0, 0), pixel_ratio: float = 1.0)[源代码]#
基类:
持有一个
arcade.gl.Framebuffer
并将其上的图画抽象。在内部用于呈现小部件。- draw(area: Tuple[float, float, float, float] | List[float] | None = None) None [源代码]#
绘制曲面的内容。
表面将在配置的
position
并受到给定条件的限制area
。这一区域可能是禁区。- 参数:
area -- 限制我们正在绘制的曲面中的区域(x,y,w,h)
- draw_texture(x: float, y: float, width: float, height: float, tex: Texture | NinePatchTexture, angle: float = 0.0, alpha: int = 255)[源代码]#
- resize(*, size: Tuple[int, int], pixel_ratio: float) None [源代码]#
通过重新分配新纹理来调整内部纹理的大小
- 参数:
size -- 以像素为单位的新大小(XY)
pixel_ratio -- 窗口的像素比例
- blend_func_render#
绘制曲面时的混合模式
- blend_func_render_into#
当我们绘制到表面时的混合模式
- height#
- pixel_ratio#
- position#
获取或设置曲面位置
- size#
以窗坐标表示的曲面大小
- size_scaled#
缓冲区的物理大小
- width#
- class arcade.gui.UIButtonRow(*, vertical: bool = False, align: str = 'center', size_hint: ~typing.Any = (0, 0), size_hint_min: ~typing.Any | None = None, size_hint_max: ~typing.Any | None = None, space_between: int = 10, style: ~typing.Any | None = None, button_factory: type = <class 'arcade.gui.widgets.buttons.UIFlatButton'>)[源代码]#
基类:
UIBoxLayout
将按钮放置在一行中。:参数垂直:按钮行是否垂直。:param Align:将按钮行对齐的位置。用法:param SIZE_HINT:应该请求父级的多少空间的浮点数(0.0-1.0)的元组。:param SIZE_HINT_MIN:最小宽度和高度,单位为像素。:param size_hint_max:以像素为单位的最大宽度和高度。:param SPACE_BETWING:子代之间的空格。:参数样式:未使用。:Param Tuple [str, ...] BUTTON_Labels:按钮的标签。:param回调:将接收所点击按钮的文本的回调函数。
- on_action(event: UIOnActionEvent)[源代码]#
- class arcade.gui.UIMessageBox(*, width: float, height: float, message_text: str, buttons=('Ok',))[源代码]#
基类:
UIMouseFilterMixin
,UIAnchorLayout
这是一个简单的对话框,其中弹出一条消息,其中包含关闭按钮。将此类划分为子类,或使用以下内容覆盖‘on_action’事件处理程序
box = UIMessageBox(...) @box.event("on_action") def on_action(event: UIOnActionEvent): pass
- 参数:
width -- 消息框的宽度
height -- 消息框的高度
message_text -- 要作为消息显示给用户的文本
buttons -- 字符串列表,显示为按钮
- on_action(event: UIOnActionEvent)[源代码]#
按下按钮时调用
- class arcade.gui.UIDraggableMixin(*, x: float = 0, y: float = 0, width: float = 100, height: float = 100, children: Iterable[UIWidget] = (), size_hint=None, size_hint_min=None, size_hint_max=None, **kwargs)[源代码]#
基类:
UILayout
UIDraggableMixin可以用来制作任何
UIWidget
可拖拽的。例如,创建一个具有背景的可拖动框架,这对于类似窗口的构造很有用:
- 类DraggablePane(UITexturePane,UIDraggableMixin):
..。
这确实会覆盖
UILayout
定位自己的行为,比如UIAnchorWidget
- class arcade.gui.UIMouseFilterMixin(*, x: float = 0, y: float = 0, width: float = 100, height: float = 100, children: Iterable[UIWidget] = (), size_hint=None, size_hint_min=None, size_hint_max=None, **kwargs)[源代码]#
基类:
UIWidget
UIMouseFilterMixin
可用于捕获此小部件内发生的所有鼠标事件。对于类似窗口的小部件非常有用,
UIMouseEvents
不应触发小工具下的效果。
- class arcade.gui.UIWindowLikeMixin(*, x: float = 0, y: float = 0, width: float = 100, height: float = 100, children: Iterable[UIWidget] = (), size_hint=None, size_hint_min=None, size_hint_max=None, **kwargs)[源代码]#
基类:
UIMouseFilterMixin
,UIDraggableMixin
,UIWidget
使小部件窗口如下所示:
处理小部件边界内发生的所有鼠标事件
可以被拖动
- class arcade.gui.UIView[源代码]#
基类:
View
该视图提供基本的图形用户界面设置。
这是一个方便的类,它将UIManager添加到 self.ui 。显示视图时启用UIManager,隐藏视图时禁用UIManager。
如果您覆盖
on_show_view
或on_show_view
,不要忘记调用Super().on_show_view()或Super().on_Hide_view()。
- class arcade.gui.UIManager(window: Window | None = None)[源代码]#
-
UIManager是Arade的图形用户界面系统中的中心组件。处理窗口事件、布局处理和渲染。
为了处理窗口事件,
UIManager.enable()
必须被调用,它将为所有窗口事件注入事件回调,并通过小部件树重定向它们。如果在视图中使用
UIManager.enable()
应从View.on_show_view()
和UIManager.disable()
应从View.on_hide_view()
支架 size_hint 根据窗口大小直接放大/缩小子项。支架 size_hint_min 以确保直接子对象的大小(例如UIBoxLayout)。支架 size_hint_max 以确保直接子对象的大小(例如UIBoxLayout)。
class MyView(arcade.View): def __init__(): super().__init__() manager = UIManager() manager.add(Dummy()) def on_show_view(self): # Set background color self.window.background_color = arcade.color.DARK_BLUE_GRAY # Enable UIManager when view is shown to catch window events self.ui.enable() def on_hide_view(self): # Disable UIManager when view gets inactive self.ui.disable() def on_draw(): self.clear() ... manager.draw() # draws the UI on screen
- add(widget: W, *, index=None, layer=0) W [源代码]#
将小部件添加到
UIManager
。添加的小部件将接收UI事件并呈现。默认情况下,最新添加的小部件将首先接收UI事件,并在其他小部件上呈现。
UIManager支持分层设置,添加到较高层的小部件绘制在较低层之上,并首先接收事件。层10保留用于覆盖下拉式菜单或工具提示等组件。
- 参数:
widget -- 要添加的小部件
index -- 添加微件的位置,没有优先级最高的微件
layer -- 微件应该添加到的层,更高的层在上面
- 返回:
小工具
- adjust_mouse_coordinates(x: float, y: float) Tuple[float, float] [源代码]#
此方法用于将鼠标坐标转换为与摄影机的视区和投影相关的坐标。
它使用内部摄影机的map_坐标方法,并且应该使用基本的正交摄影机可能进行的所有变换。
- disable() None [源代码]#
删除处理程序函数 (on_. ..)来自
arcade.Window
如果每一次
arcade.View
使用它自己的arcade.gui.UIManager
,则应调用此方法arcade.View.on_hide_view()
。
- enable() None [源代码]#
注册处理程序函数 (on_. ..)至
arcade.gui.UIElement
ON_DRAW未注册,以提供对绘制顺序的完全控制,因此它必须由开发人员自己调用。
在视图中,此方法应从
arcade.View.on_show_view()
。
- execute_layout()[源代码]#
执行所有Widget的布局流程。
这在以下过程中自动调用
UIManager.draw()
。
- get_widgets_at(pos: ~typing.Tuple[float, float], cls: ~typing.Type[~arcade.gui.ui_manager.W] = <class 'arcade.gui.widgets.UIWidget'>, layer=0) Iterable[W] [源代码]#
生成包含位置的所有小部件,返回作为CLS实例的第一个顶层小部件。
- 参数:
pos -- 小部件范围内的位置
cls -- 小部件应该是其实例的
layer -- 要搜索的层,则无将搜索所有层
- 返回:
位置上给定类型的微件的迭代器
- walk_widgets(*, root: UIWidget | None = None, layer=0) Iterable[UIWidget] [源代码]#
按相反的绘制顺序浏览小部件树(最先绘制的小部件最多)
- 参数:
root -- 要开始的根微件,如果没有,则使用该层
layer -- 要搜索的层,则无将搜索所有层
- OVERLAY_LAYER = 10#
- rect#
- class arcade.gui.NinePatchTexture(*, left: int, right: int, bottom: int, top: int, texture: Texture, atlas: TextureAtlas | None = None)[源代码]#
基类:
使边框和边角保持恒定宽度,同时拉伸中间部分。
它可以与新的或现有的一起使用
UIWidget
子类任何地方都是普通的arcade.Texture
受支持。对于必须在保持边框装饰不变的情况下增大或缩小的图形用户界面元素(如对话框或文本框),这很有用。下图解释了此类的拉伸行为:
带箭头的编号区域 (
<--->
)沿着任何存在的箭头的方向(S)延伸铁条 (
|---|
)标记由边界参数指定的距离 (left
等)
拉伸轴和边框参数#left right |------| |------| top +------+-----------------+------+ --- | (1) | (2) | (3) | | | | <-------------> | | | +------+-----------------+------+ --- | (4) | (5) ^ | (6) | | ^ | | | ^ | | | | | | | | | | | <------+------> | | | | | | | | | | | | | | | | | | v | v | v | +------+-----------------+------+ --- | (7) | (8) | (9) | | | | <-------------> | | | +------+-----------------+------+ --- bottom
拉伸纹理时,纹理的编号切片如下所示:
区域
(1)
,(3)
,(7)
和(9)
永远不要伸展。面积
(5)
水平拉伸和垂直拉伸。区域
(2)
和(8)
只能水平伸展。区域
(4)
和(6)
只能垂直伸展。
- 参数:
left -- 9面片左侧边框的宽度(以像素为单位)
right -- 9面片右边框的宽度(以像素为单位)
bottom -- 9面片的底框高度(以像素为单位)
top -- 9面片顶部边框的高度(以像素为单位)
texture -- 用于9面片的原始纹理
atlas -- 指定Arcade的默认纹理图集以外的图集
- draw_sized(*, position: Tuple[float, float] = (0.0, 0.0), size: Tuple[float, float], pixelated: bool = False, **kwargs)[源代码]#
绘制具有特定大小的9面片纹理。
警告
此方法假定传递的维度是正确的!
如果指定的大小小于边界区域的总大小,则可能会发生意外行为。
- 参数:
position -- 纹理的左下偏移量(以像素为单位
size -- 9面片的大小,以宽度、高度为单位(像素)
pixelated -- 是否使用最近邻插值法绘制
- bottom#
获取或设置9补丁的底部边框。
- ctx#
OpenGL上下文。
- height#
纹理的高度,以像素为单位。
- left#
获取或设置9补丁的左侧边框。
- program#
获取或设置着色器程序。
如果未指定其他着色器,则返回默认着色器。
- right#
获取或设置9补丁的右边框。
- size#
以像素为单位的宽度、高度元组的纹理大小。
- texture#
获取或设置纹理。
- top#
获取或设置9补丁的顶部边框。
- width#
纹理的宽度,以像素为单位。