diff --git a/docs_md/changelog.md b/docs_md/changelog.md index 5893be1..d14ca49 100644 --- a/docs_md/changelog.md +++ b/docs_md/changelog.md @@ -413,7 +413,7 @@ Also now you can change the input priority of components temporary. For example - **#133** [Hotkey] Add new extended component: Hotkey - It's allow you set hotkeys to call callbacks - - You should pass one action key and several modificator keys (left shift, ctrl etc) + - You should pass one action key and several modificator keys (left shift, right ctrl etc) - List of modificator keys setup via component style (you can change it) - You can add several hotkeys on one callback via `hotkey:add_hotkey` with additional params - **#98** [Layout] Add new extended component: Layout @@ -440,3 +440,4 @@ Also now you can change the input priority of components temporary. For example - **#185** [System] Add `on_window_resized` component interest. It will called on game window size changes - **#189** [System] Add optional flag to `component:set_input_priority` to mark it as temporary. It will reset to default input priority after the `component:reset_input_priority` - **#204** [System] Fix: wrong code example link, if open example from direct URL +- **#202** [System] Enabled stencil check to true by default. To disable this, use druid.no_stencil_check in game.project settings diff --git a/druid/extended/layout.lua b/druid/extended/layout.lua index 2a4a24f..f2cfd75 100644 --- a/druid/extended/layout.lua +++ b/druid/extended/layout.lua @@ -5,6 +5,15 @@ -- @within BaseComponent -- @alias druid.layout +--- Layout node +-- @tfield node node + +--- Current layout mode +-- @tfield string mode + +---On window resize callback(self, new_size) +-- @tfield DruidEvent on_size_changed @{DruidEvent} + --- @@ -17,111 +26,162 @@ local Event = require("druid.event") local Layout = component.create("layout") -function Layout:init(node, mode, on_size_changed_callback) - self.node = self:get_node(node) +--- Component init function +-- @tparam Layout self @{Layout} +-- @tparam node node Gui node +-- @tparam string node The layout mode (from const.LAYOUT_MODE) +-- @tparam[opt] function on_size_changed_callback The callback on window resize +function Layout.init(self, node, mode, on_size_changed_callback) + self.node = self:get_node(node) - self._min_size = nil - self._max_size = nil - self._inited = false + self._min_size = nil + self._max_size = nil + self._inited = false - self.gui_size = vmath.vector3(gui.get_width(), gui.get_height(), 0) - self.mode = mode or const.LAYOUT_MODE.FIT + self._fit_node = nil - self.on_size_changed = Event(on_size_changed_callback) + self.mode = mode or const.LAYOUT_MODE.FIT + + self.on_size_changed = Event(on_size_changed_callback) end -function Layout:on_late_init() - self._inited = true - self.origin_size = self.origin_size or gui.get_size(self.node) - self.fit_size = self.fit_size or vmath.vector3(self.origin_size) - self.pivot = helper.get_pivot_offset(gui.get_pivot(self.node)) - self.origin_position = gui.get_position(self.node) - self.position = vmath.vector3(self.origin_position) - gui.set_size_mode(self.node, gui.SIZE_MODE_MANUAL) - gui.set_adjust_mode(self.node, gui.ADJUST_FIT) - self:on_window_resized() +function Layout.on_late_init(self) + self._inited = true + self.origin_size = self.origin_size or gui.get_size(self.node) + self.fit_size = self.fit_size or vmath.vector3(self.origin_size) + self.pivot = helper.get_pivot_offset(gui.get_pivot(self.node)) + self.origin_position = gui.get_position(self.node) + self.position = vmath.vector3(self.origin_position) + gui.set_size_mode(self.node, gui.SIZE_MODE_MANUAL) + gui.set_adjust_mode(self.node, gui.ADJUST_FIT) + self:on_window_resized() end -function Layout:on_window_resized() - if not self._inited then - return - end +function Layout.on_window_resized(self) + if not self._inited then + return + end local x_koef, y_koef = helper.get_screen_aspect_koef() - local new_size = vmath.vector3(self.origin_size) - if self.mode == const.LAYOUT_MODE.STRETCH_X or self.mode == const.LAYOUT_MODE.STRETCH then - new_size.x = new_size.x * x_koef - end - if self.mode == const.LAYOUT_MODE.STRETCH_Y or self.mode == const.LAYOUT_MODE.STRETCH then - new_size.y = new_size.y * y_koef - end + if self._fit_node then + self.fit_size = gui.get_size(self._fit_node) + self.fit_size.x = self.fit_size.x / x_koef + self.fit_size.y = self.fit_size.y / y_koef + end - -- Fit to the stretched container (node size or other defined) - if self.mode == const.LAYOUT_MODE.ZOOM_MIN then - new_size = new_size * math.min(x_koef, y_koef) - end - if self.mode == const.LAYOUT_MODE.ZOOM_MAX then - new_size = new_size * math.max(x_koef, y_koef) - end + x_koef = self.fit_size.x / self.origin_size.x * x_koef + y_koef = self.fit_size.y / self.origin_size.y * y_koef - if self._min_size then - new_size.x = math.max(new_size.x, self._min_size.x) - new_size.y = math.max(new_size.y, self._min_size.y) - end - if self._max_size then - new_size.x = math.min(new_size.x, self._max_size.x) - new_size.y = math.min(new_size.y, self._max_size.y) - end - gui.set_size(self.node, new_size) + local new_size = vmath.vector3(self.origin_size) + + if self.mode == const.LAYOUT_MODE.STRETCH_X or self.mode == const.LAYOUT_MODE.STRETCH then + new_size.x = new_size.x * x_koef + end + if self.mode == const.LAYOUT_MODE.STRETCH_Y or self.mode == const.LAYOUT_MODE.STRETCH then + new_size.y = new_size.y * y_koef + end + + -- Fit to the stretched container (node size or other defined) + if self.mode == const.LAYOUT_MODE.ZOOM_MIN then + new_size = new_size * math.min(x_koef, y_koef) + end + if self.mode == const.LAYOUT_MODE.ZOOM_MAX then + new_size = new_size * math.max(x_koef, y_koef) + end + + if self._min_size then + new_size.x = math.max(new_size.x, self._min_size.x) + new_size.y = math.max(new_size.y, self._min_size.y) + end + if self._max_size then + new_size.x = math.min(new_size.x, self._max_size.x) + new_size.y = math.min(new_size.y, self._max_size.y) + end + gui.set_size(self.node, new_size) self.position.x = self.origin_position.x + self.origin_position.x * (x_koef - 1) self.position.y = self.origin_position.y + self.origin_position.y * (y_koef - 1) - gui.set_position(self.node, self.position) + gui.set_position(self.node, self.position) - self.on_size_changed:trigger(self:get_context(), new_size) + self.on_size_changed:trigger(self:get_context(), new_size) end -function Layout:set_min_size(min_size) - self._min_size = min_size - return self +--- Set minimal size of layout node +-- @tparam Layout self @{Layout} +-- @tparam vector3 min_size +-- @treturn Layout @{Layout} +function Layout.set_min_size(self, min_size) + self._min_size = min_size + return self end -function Layout:set_max_size(max_size) - self._max_size = max_size - return self +--- Set maximum size of layout node +-- @tparam Layout self @{Layout} +-- @tparam vector3 min_size +-- @treturn Layout @{Layout} +function Layout.set_max_size(self, max_size) + self._max_size = max_size + return self end -function Layout:set_origin_position(new_origin_position) - self.origin_position = new_origin_position or self.origin_position - return self +--- Set new origin position of layout node. You should apply this on node movement +-- @tparam Layout self @{Layout} +-- @tparam vector3 new_origin_position +-- @treturn Layout @{Layout} +function Layout.set_origin_position(self, new_origin_position) + self.origin_position = new_origin_position or self.origin_position + self:on_window_resized() + return self end -function Layout:set_origin_size(new_origin_size) - self.origin_size = new_origin_size or self.origin_size - self:on_window_resized() - return self +--- Set new origin size of layout node. You should apply this on node manual size change +-- @tparam Layout self @{Layout} +-- @tparam vector3 new_origin_size +-- @treturn Layout @{Layout} +function Layout.set_origin_size(self, new_origin_size) + self.origin_size = new_origin_size or self.origin_size + self:on_window_resized() + return self end -function Layout:fit_into_size(target_size) - self.fit_size = target_size - self:on_window_resized() - return self +--- Set size for layout node to fit inside it +-- @tparam Layout self @{Layout} +-- @tparam vector3 target_size +-- @treturn Layout @{Layout} +function Layout.fit_into_size(self, target_size) + self.fit_size = target_size + self:on_window_resized() + return self end -function Layout:fit_into_window() - return self:fit_into_size(vmath.vector3( - gui.get_width(), - gui.get_height(), - 0)) +--- Set node for layout node to fit inside it. Pass nil to reset +-- @tparam Layout self @{Layout} +-- @tparam[opt] Node node +-- @treturn Layout @{Layout} +function Layout.fit_into_node(self, node) + self._fit_node = node + self:on_window_resized() + return self +end + + +--- Set current size for layout node to fit inside it +-- @tparam Layout self @{Layout} +-- @treturn Layout @{Layout} +function Layout.fit_into_window(self) + return self:fit_into_size(vmath.vector3( + gui.get_width(), + gui.get_height(), + 0)) end diff --git a/example/assets/images/kenney.atlas b/example/assets/images/kenney.atlas index 31a9f7b..ead7b5a 100644 --- a/example/assets/images/kenney.atlas +++ b/example/assets/images/kenney.atlas @@ -62,6 +62,10 @@ images { image: "/example/assets/images/buttons/button_blue.png" sprite_trim_mode: SPRITE_TRIM_MODE_OFF } +images { + image: "/example/assets/images/logo.png" + sprite_trim_mode: SPRITE_TRIM_MODE_OFF +} margin: 0 extrude_borders: 2 inner_padding: 0 diff --git a/example/assets/images/logo.png b/example/assets/images/logo.png new file mode 100644 index 0000000..7a56d26 Binary files /dev/null and b/example/assets/images/logo.png differ diff --git a/example/example.gui_script b/example/example.gui_script index d6f1c1d..4b50739 100644 --- a/example/example.gui_script +++ b/example/example.gui_script @@ -162,6 +162,9 @@ local function init_lobby(self) self.lobby_grid:add(get_button(self, "Reinit data", "data_list_reinit_data", "/data_list/reinit_data/reinit_data.gui_script")) self.lobby_grid:add(get_button(self, "With component", "data_list_with_component", "/data_list/with_component/with_component.gui_script")) + self.lobby_grid:add(get_title(self, "Layouts")) + self.lobby_grid:add(get_button(self, "Layout fit", "layout_fit", "/custom/layout_fit/layout_fit.gui_script")) + self.lobby_grid:add(get_title(self, "Custom components")) self.lobby_grid:add(get_button(self, "Rich Input", "custom_rich_input", "/custom/rich_input/rich_input.gui_script")) self.lobby_grid:add(get_button(self, "Pin Knob", "custom_pin_knob", "/custom/pin_knob/pin_knob.gui_script")) diff --git a/example/examples/general/layout/layout.gui b/example/examples/general/layout/layout.gui index f946c05..385aaff 100644 --- a/example/examples/general/layout/layout.gui +++ b/example/examples/general/layout/layout.gui @@ -70,7 +70,7 @@ nodes { } nodes { position { - x: -100.0 + x: 0.0 y: 250.0 z: 0.0 w: 1.0 @@ -190,7 +190,7 @@ nodes { } nodes { position { - x: -100.0 + x: 0.0 y: 100.0 z: 0.0 w: 1.0 @@ -310,7 +310,7 @@ nodes { } nodes { position { - x: -100.0 + x: 0.0 y: -50.0 z: 0.0 w: 1.0 @@ -430,7 +430,7 @@ nodes { } nodes { position { - x: -100.0 + x: 0.0 y: -200.0 z: 0.0 w: 1.0 @@ -637,7 +637,7 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Layout Stretch by Y Anchor W" + text: "Layout Stretch by X Anchor W" font: "game" id: "text_layout_stretch3" xanchor: XANCHOR_NONE diff --git a/example/examples/general/layout/layout.gui_script b/example/examples/general/layout/layout.gui_script index 2550a26..a5adf93 100644 --- a/example/examples/general/layout/layout.gui_script +++ b/example/examples/general/layout/layout.gui_script @@ -9,7 +9,7 @@ function init(self) self.druid:new_layout("node_layout_stretch", const_druid.LAYOUT_MODE.STRETCH) self.druid:new_layout("node_layout_stretch_x", const_druid.LAYOUT_MODE.STRETCH_X) self.druid:new_layout("node_layout_stretch_y", const_druid.LAYOUT_MODE.STRETCH_Y) - self.druid:new_layout("node_layout_stretch_y_anchor_w", const_druid.LAYOUT_MODE.STRETCH_Y) + self.druid:new_layout("node_layout_stretch_y_anchor_w", const_druid.LAYOUT_MODE.STRETCH_X) end diff --git a/example/examples/layout/layout_fit/layout_fit.collection b/example/examples/layout/layout_fit/layout_fit.collection new file mode 100644 index 0000000..d8e2914 --- /dev/null +++ b/example/examples/layout/layout_fit/layout_fit.collection @@ -0,0 +1,37 @@ +name: "layout_fit" +scale_along_z: 0 +embedded_instances { + id: "go" + data: "components {\n" + " id: \"layout_fit\"\n" + " component: \"/example/examples/layout/layout_fit/layout_fit.gui\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/example/examples/layout/layout_fit/layout_fit.gui b/example/examples/layout/layout_fit/layout_fit.gui new file mode 100644 index 0000000..fddab63 --- /dev/null +++ b/example/examples/layout/layout_fit/layout_fit.gui @@ -0,0 +1,1247 @@ +script: "/example/examples/layout/layout_fit/layout_fit.gui_script" +fonts { + name: "game" + font: "/example/assets/fonts/game.font" +} +textures { + name: "kenney" + texture: "/example/assets/images/kenney.atlas" +} +background_color { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 +} +nodes { + position { + x: 300.0 + y: 415.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 600.0 + y: 830.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "kenney/empty" + id: "root" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.7019608 + y: 0.8 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "node_zoom_test" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_AUTO + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 274.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 140.0 + y: 172.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "kenney/logo" + id: "image" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_AUTO + custom_type: 0 +} +nodes { + position { + x: -185.0 + y: 69.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 96.0 + y: 96.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 0.3019608 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "back_1" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 140.0 + y: 172.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "kenney/logo" + id: "image_1" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "back_1" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 0.75 + template_node_child: false + size_mode: SIZE_MODE_AUTO + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: -106.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 0.75 + y: 0.75 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "STRECH" + font: "game" + id: "text_hint_1" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "back_1" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 0.75 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 69.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 96.0 + y: 96.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 0.3019608 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "back_2" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 140.0 + y: 172.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "kenney/logo" + id: "image_2" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "back_2" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 0.75 + template_node_child: false + size_mode: SIZE_MODE_AUTO + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: -106.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 0.75 + y: 0.75 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "ZOOM MAX" + font: "game" + id: "text_hint_2" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "back_2" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 0.75 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +nodes { + position { + x: 185.0 + y: 69.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 96.0 + y: 96.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 0.3019608 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "back_3" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 140.0 + y: 172.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "kenney/logo" + id: "image_3" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "back_3" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 0.75 + template_node_child: false + size_mode: SIZE_MODE_AUTO + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: -106.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 0.75 + y: 0.75 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "ZOOM MIN" + font: "game" + id: "text_hint_3" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "back_3" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 0.75 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +nodes { + position { + x: -185.0 + y: -192.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 96.0 + y: 96.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 0.3019608 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "back_4" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 140.0 + y: 172.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "kenney/logo" + id: "image_4" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "back_4" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 0.75 + template_node_child: false + size_mode: SIZE_MODE_AUTO + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: -106.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 0.75 + y: 0.75 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "STRECH X" + font: "game" + id: "text_hint_4" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "back_4" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 0.75 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: -192.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 96.0 + y: 96.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 0.3019608 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "back_5" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 140.0 + y: 172.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "kenney/logo" + id: "image_5" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "back_5" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 0.75 + template_node_child: false + size_mode: SIZE_MODE_AUTO + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: -106.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 0.75 + y: 0.75 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "STRECH Y" + font: "game" + id: "text_hint_5" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "back_5" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 0.75 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +nodes { + position { + x: 185.0 + y: -192.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 96.0 + y: 96.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 0.3019608 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "back_6" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "root" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 140.0 + y: 172.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "kenney/logo" + id: "image_6" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + parent: "back_6" + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 0.75 + template_node_child: false + size_mode: SIZE_MODE_AUTO + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: -106.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 0.75 + y: 0.75 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "FIT" + font: "game" + id: "text_hint_6" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "back_6" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 0.75 + shadow_alpha: 0.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +layers { + name: "image" +} +layers { + name: "text" +} +material: "/builtins/materials/gui.material" +adjust_reference: ADJUST_REFERENCE_PARENT +max_nodes: 512 diff --git a/example/examples/layout/layout_fit/layout_fit.gui_script b/example/examples/layout/layout_fit/layout_fit.gui_script new file mode 100644 index 0000000..9a1c538 --- /dev/null +++ b/example/examples/layout/layout_fit/layout_fit.gui_script @@ -0,0 +1,44 @@ +local druid = require("druid.druid") +local const_druid = require("druid.const") +local layout = require("druid.extended.layout") + +function init(self) + druid.register("layout", layout) + self.druid = druid.new(self) + + self.druid:new_layout("node_zoom_test", const_druid.LAYOUT_MODE.STRETCH) + :fit_into_window() + + self.druid:new_layout("image_1", const_druid.LAYOUT_MODE.STRETCH) + :fit_into_node(gui.get_node("back_1")) + self.druid:new_layout("image_2", const_druid.LAYOUT_MODE.ZOOM_MAX) + :fit_into_node(gui.get_node("back_2")) + self.druid:new_layout("image_3", const_druid.LAYOUT_MODE.ZOOM_MIN) + :fit_into_node(gui.get_node("back_3")) + self.druid:new_layout("image_4", const_druid.LAYOUT_MODE.STRETCH_X) + :fit_into_node(gui.get_node("back_4")) + self.druid:new_layout("image_5", const_druid.LAYOUT_MODE.STRETCH_Y) + :fit_into_node(gui.get_node("back_5")) + self.druid:new_layout("image_6", const_druid.LAYOUT_MODE.FIT) + :fit_into_node(gui.get_node("back_6")) +end + + +function final(self) + self.druid:final() +end + + +function update(self, dt) + self.druid:update(dt) +end + + +function on_message(self, message_id, message, sender) + self.druid:on_message(message_id, message, sender) +end + + +function on_input(self, action_id, action) + return self.druid:on_input(action_id, action) +end