Procházet zdrojové kódy

tools: drop toolbar.ui

Daniele Bartolini před 9 měsíci
rodič
revize
ab79154836

+ 2 - 3
tools/level_editor/level_editor.vala

@@ -686,7 +686,7 @@ public class LevelEditorApplication : Gtk.Application
 	private Gtk.Label _inspector_stack_compiler_failed_compilation_label;
 	private Gtk.Label _inspector_stack_stopping_backend_label;
 
-	private Gtk.Toolbar _toolbar;
+	private Toolbar _toolbar;
 	private Gtk.Image _run_game_image;
 	private Gtk.Image _stop_game_image;
 	private Gtk.Button _game_run;
@@ -966,8 +966,7 @@ public class LevelEditorApplication : Gtk.Application
 		_inspector_stack_stopping_backend_label = stopping_backend_label();
 		_inspector_stack.add(_inspector_stack_stopping_backend_label);
 
-		Gtk.Builder builder = new Gtk.Builder.from_resource("/org/crownengine/Crown/ui/toolbar.ui");
-		_toolbar = builder.get_object("toolbar") as Gtk.Toolbar;
+		_toolbar = new Toolbar();
 
 		// Game run/stop button.
 		_run_game_image = new Gtk.Image.from_icon_name("game-run", Gtk.IconSize.MENU);

+ 0 - 1
tools/level_editor/resources/resources.gresource.xml

@@ -11,7 +11,6 @@
     <file compressed="true">ui/style-light.css</file>
     <file compressed="true">ui/style-dark.css</file>
     <file compressed="true" preprocess="xml-stripblanks">gtk/menus.ui</file>
-    <file compressed="true" preprocess="xml-stripblanks">ui/toolbar.ui</file>
     <file>theme/Adwaita/assets/bullet-symbolic.symbolic.png</file>
     <file>theme/Adwaita/assets/check-symbolic.symbolic.png</file>
     <file>theme/Adwaita/assets/dash-symbolic.symbolic.png</file>

+ 0 - 179
tools/level_editor/resources/ui/toolbar.ui

@@ -1,179 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.36.0 -->
-<interface>
-  <requires lib="gtk+" version="3.16"/>
-  <object class="GtkToolbar" id="toolbar">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="halign">start</property>
-    <property name="valign">start</property>
-    <property name="margin_start">8</property>
-    <property name="margin_top">8</property>
-    <property name="orientation">vertical</property>
-    <property name="toolbar_style">icons</property>
-    <property name="icon_size">2</property>
-    <child>
-      <object class="GtkToggleToolButton">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="tooltip_text" translatable="yes">Place</property>
-        <property name="action_name">app.tool</property>
-        <property name="action_target">0</property>
-        <property name="use_underline">True</property>
-        <property name="icon_name">tool-place</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkToggleToolButton" id="radiotoolbutton1">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="tooltip_text" translatable="yes">Move</property>
-        <property name="action_name">app.tool</property>
-        <property name="action_target">1</property>
-        <property name="use_underline">True</property>
-        <property name="icon_name">tool-move</property>
-        <property name="active">True</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkToggleToolButton">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="tooltip_text" translatable="yes">Rotate</property>
-        <property name="action_name">app.tool</property>
-        <property name="action_target">2</property>
-        <property name="use_underline">True</property>
-        <property name="icon_name">tool-rotate</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkToggleToolButton">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="tooltip_text" translatable="yes">Scale</property>
-        <property name="action_name">app.tool</property>
-        <property name="action_target">3</property>
-        <property name="use_underline">True</property>
-        <property name="icon_name">tool-scale</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkSeparatorToolItem">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkToggleToolButton" id="radiotoolbutton2">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="action_name">app.snap</property>
-        <property name="action_target">0</property>
-        <property name="use_underline">True</property>
-        <property name="icon_name">reference-local</property>
-        <property name="active">True</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkToggleToolButton">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="action_name">app.snap</property>
-        <property name="action_target">1</property>
-        <property name="use_underline">True</property>
-        <property name="icon_name">reference-world</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkSeparatorToolItem">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkToggleToolButton" id="radiotoolbutton3">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="action_name">app.reference-system</property>
-        <property name="action_target">0</property>
-        <property name="use_underline">True</property>
-        <property name="icon_name">axis-local</property>
-        <property name="active">True</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkToggleToolButton">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="action_name">app.reference-system</property>
-        <property name="action_target">1</property>
-        <property name="use_underline">True</property>
-        <property name="icon_name">axis-world</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkSeparatorToolItem">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkToggleToolButton">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="action_name">app.snap-to-grid</property>
-        <property name="use_underline">True</property>
-        <property name="icon_name">snap-to-grid</property>
-        <property name="active">False</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="homogeneous">True</property>
-      </packing>
-    </child>
-  </object>
-</interface>

+ 78 - 0
tools/level_editor/toolbar.vala

@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2012-2025 Daniele Bartolini et al.
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+namespace Crown
+{
+public class Toolbar : Gtk.Box
+{
+	public Toolbar()
+	{
+		this.orientation = Gtk.Orientation.VERTICAL;
+		this.halign = Gtk.Align.START;
+		this.valign = Gtk.Align.START;
+		this.margin_top = 8;
+		this.margin_start = 8;
+
+		add_tool_buttons();
+		add_snap_buttons();
+		add_reference_system_buttons();
+		add_snap_to_grid_buttons();
+	}
+
+	private void add_tool_buttons()
+	{
+		this.pack_start(make_toggle_button("app.tool", new GLib.Variant.int32(ToolType.PLACE), "tool-place"));
+		this.pack_start(make_toggle_button("app.tool", new GLib.Variant.int32(ToolType.MOVE), "tool-move"));
+		this.pack_start(make_toggle_button("app.tool", new GLib.Variant.int32(ToolType.ROTATE), "tool-rotate"));
+		var last = make_toggle_button("app.tool", new GLib.Variant.int32(ToolType.SCALE), "tool-scale");
+		last.margin_bottom = last.margin + 8;
+		this.pack_start(last);
+	}
+
+	private void add_snap_buttons()
+	{
+		this.pack_start(make_toggle_button("app.snap", new GLib.Variant.int32(SnapMode.RELATIVE), "reference-local"));
+		var last = make_toggle_button("app.snap", new GLib.Variant.int32(SnapMode.ABSOLUTE), "reference-world");
+		last.margin_bottom = last.margin + 8;
+		this.pack_start(last);
+	}
+
+	private void add_reference_system_buttons()
+	{
+		this.pack_start(make_toggle_button("app.reference-system", new GLib.Variant.int32(ReferenceSystem.LOCAL), "axis-local"));
+		var last = make_toggle_button("app.reference-system", new GLib.Variant.int32(ReferenceSystem.WORLD), "axis-world");
+		last.margin_bottom = last.margin + 8;
+		this.pack_start(last);
+	}
+
+	private void add_snap_to_grid_buttons()
+	{
+		var last = make_toggle_button("app.snap-to-grid", null, "snap-to-grid");
+		last.margin_bottom = last.margin + 8;
+		this.pack_start(last);
+	}
+
+	private Gtk.ToggleButton make_toggle_button(string action_name
+		, GLib.Variant? action_target
+		, string icon_name
+		, Gtk.IconSize icon_size = Gtk.IconSize.LARGE_TOOLBAR
+		)
+	{
+		var btn = new Gtk.ToggleButton();
+		btn.action_name = action_name;
+		if (action_target != null)
+			btn.action_target = action_target;
+		btn.can_focus = false;
+		btn.get_style_context().add_class("flat");
+
+		var img = new Gtk.Image.from_icon_name(icon_name, icon_size);
+		img.margin = 8;
+		btn.set_image(img);
+
+		return btn;
+	}
+}
+
+} /* namespace Crown */