First commit

This commit is contained in:
Leonard Guyot
2026-11-02 19:38:04 +01:00
parent e92d00047c
commit 68783081ed
217 changed files with 21796 additions and 0 deletions
+849
View File
@@ -0,0 +1,849 @@
@tool
class_name PdToolbar
extends HBoxContainer
## Top toolbar: icon-only buttons grouped by category, with tooltips.
## The FIRST button is the two-half WORKSPACE switch
## [ 3D Editor | Texture Editor ] - exactly one half is always active.
## The toolbar then shows the CONTEXTUAL group of the active workspace:
## - MODEL group: selection modes, Draw split, view toggles, mesh edits
## - TEXTURE group: [Paint | Edit UV] submode + that submode's tools
## Exactly one group is visible - texture tools REPLACE the modeling
## buttons when the texture editor is active. Sliders and deeper settings
## live in the right panel.
## Draw stays a SPLIT BUTTON: the main half shows the current shape icon
## and activates that mode, the attached arrow half opens the shape menu.
## The gizmo button is a split too: main toggles the gizmo, the arrow menu
## picks Move or Scale.
signal mode_requested(m: int)
signal workspace_requested(tex: bool)
signal toggle_gizmo(v: bool)
signal gizmo_kind_requested(k: int)
signal toggle_snap(v: bool)
signal toggle_grid(v: bool)
signal toggle_both_sides(v: bool)
signal draw_kind(k: String)
signal add_shape(kind: String)
signal duplicate_requested
signal delete_requested
signal undo_requested
signal redo_requested
signal save_requested
signal load_requested
signal import_model_requested
signal export_requested(kind: String)
signal bg_changed(c: Color)
signal tex_submode(edit: bool)
signal paint_tool_requested(t: String)
signal uv_snap_requested(v: bool)
signal rotate_uv_requested(dir: int)
signal uv_tool_requested(t: String)
signal import_requested
signal detach_requested
signal reset_uvs_requested
var doc: PdDocument
var _ws_3d: Button
var _ws_tex: Button
var _mode_buttons := {}
var _mode_group := ButtonGroup.new()
# Side-by-side gizmo pair: [Move] [Scale] - the active kind is pressed
# while the gizmo is ON; clicking the pressed one again turns it off.
var _btn_gizmo_move: Button
var _btn_gizmo_scale: Button
var _btn_gizmo_rotate: Button
var _btn_snap: Button
var _btn_grid: Button
var _btn_sides: Button
var _draw_main: Button
var _draw_arrow: Button
var _draw_popup: PopupMenu
var _btn_undo: Button
var _btn_redo: Button
var _bg_pick: ColorPickerButton
var _btn_settings: Button
var _btn_docs: Button
var _settings_popup: PopupPanel
var _shade_btns: Array = []
var _grid_btn: Button
var _hints_btn: Button
var _checker_btn: Button
var _bake_btn: Button
var _docs_win: Window
# contextual groups: exactly one is visible at a time
var _model_box: HBoxContainer
var _tex_box: HBoxContainer
var _tex_paint_box: HBoxContainer
var _tex_uv_box: HBoxContainer
var _tex_paint: Button
var _tex_edituv: Button
var _tex_tool_btns := {}
var _tex_uv_snap: Button
var _tex_uv_rotate: Button
var _tex_uv_scale: Button
var _uv_tool_group: ButtonGroup
const ICONS := preload("res://addons/polydoodle/core/pd_icons.gd")
const ACCENT := PdDocument.ACCENT
const ACCENT_DARK := PdDocument.ACCENT_DARK # bottom bevel of active buttons
const DRAW_ICONS := {
"Freehand": "tool_freehand",
"Rectangle": "tool_rect",
"Circle": "tool_circle",
"Triangle": "tool_triangle",
"Pentagon": "tool_pentagon",
"Hexagon": "tool_hexagon",
"Star": "tool_star",
"Torus": "tool_torus",
}
func _icon(n: String) -> Texture2D:
return ICONS.get_icon(n.trim_suffix(".svg"))
# ------------------------------------------------------------ styling ---
## TACTILE button states - reserved for the workspace split button, the
## right panel and the settings popup. Idle is flat dark, hover lifts
## slightly, and the ACTIVE (pressed) state is a SOLID accent fill - no
## transparency - with a darker bottom edge (2px bevel) that gives the
## button a physical 3D look, like a key sitting lower on its base. A
## lighter top border adds a subtle rim light from above.
func _box(corners := Vector4(4, 4, 4, 4)) -> StyleBoxFlat:
var sb := StyleBoxFlat.new()
sb.bg_color = Color(1, 1, 1, 0.04)
sb.set_corner_radius_all(0)
sb.corner_radius_top_left = int(corners.x)
sb.corner_radius_bottom_left = int(corners.y)
sb.corner_radius_top_right = int(corners.z)
sb.corner_radius_bottom_right = int(corners.w)
sb.content_margin_left = 5
sb.content_margin_right = 5
sb.content_margin_top = 3
sb.content_margin_bottom = 3
return sb
func _bevel(sb: StyleBoxFlat, bottom_px: int) -> StyleBoxFlat:
sb.border_width_bottom = bottom_px
sb.border_color = ACCENT_DARK
return sb
func _paint_states(b: Button, base: StyleBoxFlat) -> void:
var hover := base.duplicate()
hover.bg_color = Color(1, 1, 1, 0.10)
# ACTIVE: solid accent (opaque), darker bottom bevel = 3D look
var pressed := base.duplicate()
pressed.bg_color = ACCENT
_bevel(pressed, 3)
pressed.content_margin_top = 4
pressed.content_margin_bottom = 2
# active + hovered: same solid fill, slightly lifted top rim
var hover_pressed := base.duplicate()
hover_pressed.bg_color = ACCENT.lightened(0.08)
_bevel(hover_pressed, 3)
hover_pressed.content_margin_top = 4
hover_pressed.content_margin_bottom = 2
var disabled := base.duplicate()
disabled.bg_color = Color(1, 1, 1, 0.015)
b.add_theme_stylebox_override("normal", base)
b.add_theme_stylebox_override("hover", hover)
b.add_theme_stylebox_override("pressed", pressed)
b.add_theme_stylebox_override("hover_pressed", hover_pressed)
b.add_theme_stylebox_override("disabled", disabled)
b.add_theme_stylebox_override("focus", StyleBoxEmpty.new())
# Pin EVERY icon state to white. Without icon_hover_pressed_color the
# editor theme's fallback tints the icon blue while the active half of
# the workspace split is hovered - blue on blue.
b.add_theme_color_override("icon_pressed_color", Color(1, 1, 1, 1))
b.add_theme_color_override("icon_normal_color", Color(1, 1, 1, 0.82))
b.add_theme_color_override("icon_hover_color", Color(1, 1, 1, 1))
b.add_theme_color_override("icon_hover_pressed_color", Color(1, 1, 1, 1))
b.add_theme_color_override("icon_focus_color", Color(1, 1, 1, 1))
b.add_theme_color_override("icon_disabled_color", Color(1, 1, 1, 0.3))
func _style_tactile(b: Button) -> void:
_paint_states(b, _box())
## FLAT toolbar states - the Godot-default look for every top-toolbar
## button EXCEPT the workspace split. At rest the button is invisible:
## only the icon shows. Hovering washes the background slightly lighter.
## The ACTIVE (toggled) state colors the ICON with the theme accent - no
## solid fill, no bevel.
## Geometry: every button is a SQUARE chip with rounded
## corners like Godot's own toolbar - symmetric margins, a fixed 28x28
## minimum size and shrink-center so the highlight can never stretch
## into a portrait rectangle.
const TB_CHIP := 28.0 # square side of a toolbar button
const TB_RADIUS := 5 # corner radius of the highlight
func _style_flat(b: Button) -> void:
var normal := StyleBoxFlat.new()
normal.bg_color = Color(1, 1, 1, 0)
normal.set_corner_radius_all(TB_RADIUS)
normal.content_margin_left = 6
normal.content_margin_right = 6
normal.content_margin_top = 6
normal.content_margin_bottom = 6
var hover := normal.duplicate()
hover.bg_color = Color(1, 1, 1, 0.07)
var pressed := normal.duplicate()
pressed.bg_color = Color(1, 1, 1, 0.045)
var hover_pressed := normal.duplicate()
hover_pressed.bg_color = Color(1, 1, 1, 0.09)
var disabled := normal.duplicate()
b.add_theme_stylebox_override("normal", normal)
b.add_theme_stylebox_override("hover", hover)
b.add_theme_stylebox_override("pressed", pressed)
b.add_theme_stylebox_override("hover_pressed", hover_pressed)
b.add_theme_stylebox_override("disabled", disabled)
b.add_theme_stylebox_override("focus", StyleBoxEmpty.new())
b.add_theme_color_override("icon_normal_color", Color(1, 1, 1, 0.78))
b.add_theme_color_override("icon_hover_color", Color(1, 1, 1, 1))
b.add_theme_color_override("icon_pressed_color", ACCENT)
b.add_theme_color_override("icon_disabled_color", Color(1, 1, 1, 0.28))
b.custom_minimum_size = Vector2(TB_CHIP, TB_CHIP)
b.size_flags_vertical = Control.SIZE_SHRINK_CENTER
func _style(b: Button) -> void:
# default for toolbar buttons: flat Godot-like states. The workspace
# split and the settings popup explicitly ask for _style_tactile.
_style_flat(b)
func _button(icon: String, tip: String) -> Button:
var b := Button.new()
b.icon = _icon(icon)
b.text = ""
b.focus_mode = Control.FOCUS_NONE
b.tooltip_text = tip
b.add_theme_constant_override("icon_max_width", 16)
_style(b)
return b
func _toggle(icon: String, tip: String, group: ButtonGroup = null) -> Button:
var b := _button(icon, tip)
b.toggle_mode = true
b.button_group = group
return b
func _sep() -> VSeparator:
return VSeparator.new()
func _gap(px: float) -> Control:
var c := Control.new()
c.custom_minimum_size = Vector2(px, 0)
return c
## A joined pair [main | arrow]: the main half activates the mode and
## shows the current tool icon; the arrow half opens the tool menu. The
## arrow carries a visible chevron icon so the dropdown affordance reads
## at a glance. `tactile` keeps the 3D key look - used by the workspace
## switch only; every other split is flat.
func _split(main_tip: String, arrow_tip: String, tactile := false) -> Array:
var box := HBoxContainer.new()
box.add_theme_constant_override("separation", 0)
var main := Button.new()
main.toggle_mode = true
main.focus_mode = Control.FOCUS_NONE
main.tooltip_text = main_tip
main.add_theme_constant_override("icon_max_width", 16)
if tactile:
_paint_states(main, _box(Vector4(4, 4, 0, 0)))
else:
_style_flat(main)
# joined pill: outer corners rounded, inner corners square so the
# two square chips read as one control
_join_split_corners(main, true)
var arrow := Button.new()
arrow.focus_mode = Control.FOCUS_NONE
arrow.tooltip_text = arrow_tip
arrow.icon = _icon("arrow_down") # the dropdown indicator
arrow.custom_minimum_size = Vector2(20, TB_CHIP)
arrow.add_theme_constant_override("icon_max_width", 12)
if tactile:
_paint_states(arrow, _box(Vector4(0, 0, 4, 4)))
else:
_style_flat(arrow)
_join_split_corners(arrow, false)
if not tactile:
arrow.add_theme_color_override("icon_normal_color", Color(1, 1, 1, 0.5))
arrow.add_theme_color_override("icon_hover_color", Color(1, 1, 1, 0.95))
arrow.add_theme_color_override("icon_pressed_color", ACCENT)
else:
arrow.add_theme_color_override("icon_normal_color", Color(1, 1, 1, 0.55))
arrow.add_theme_color_override("icon_hover_color", Color(1, 1, 1, 0.95))
box.add_child(main)
box.add_child(arrow)
return [box, main, arrow]
## Reroute the corner radii of a flat split half: the OUTER corners stay
## rounded (the chip look), the INNER corners (where the two halves meet)
## square. `is_main` picks which side is outer.
func _join_split_corners(b: Button, is_main: bool) -> void:
for state in ["normal", "hover", "pressed", "hover_pressed", "disabled"]:
var sb := b.get_theme_stylebox(state) as StyleBoxFlat
if sb == null:
continue
var s := sb.duplicate()
s.corner_radius_top_left = TB_RADIUS if is_main else 0
s.corner_radius_bottom_left = TB_RADIUS if is_main else 0
s.corner_radius_top_right = 0 if is_main else TB_RADIUS
s.corner_radius_bottom_right = 0 if is_main else TB_RADIUS
b.add_theme_stylebox_override(state, s)
func _open_popup(pm: PopupMenu, at: Control) -> void:
var gp := at.get_global_rect()
pm.position = Vector2i(int(gp.position.x), int(gp.end.y) + 2)
pm.popup()
func setup(d: PdDocument) -> void:
doc = d
add_theme_constant_override("separation", 3)
# --- WORKSPACE switch (first buttons): 3D Editor | Texture Editor
# A joined pair where EXACTLY ONE half is always pressed: the left
# half is the 3D modeler (quad view + mesh tools), the right half
# the texture editor (3D viewport + texture canvas + tool strip).
# The ONLY tactile control on the toolbar: the 3D key look marks
# it as the master switch of the whole editor.
var wsp := _split("3D Editor\nQuad view: Top / Perspective / Side / Front with all modeling tools (1-5)",
"Texture Editor\n3D viewport over the texture canvas: paint and edit UVs (6)", true)
_ws_3d = wsp[1]
_ws_tex = wsp[2]
# the right half is a mode, not a dropdown arrow: a dedicated
# checkered-cube icon (distinct from the Edit-UV submode button's)
# inside a shared button group, so exactly one half reads as
# active at a time.
_ws_3d.icon = _icon("ws_3d")
_ws_tex.icon = _icon("ws_uv")
_ws_tex.toggle_mode = true # the arrow half is not a toggle by default
_ws_tex.add_theme_constant_override("icon_max_width", 16)
var wsgrp := ButtonGroup.new()
_ws_3d.button_group = wsgrp
_ws_tex.button_group = wsgrp
_ws_3d.pressed.connect(func(): workspace_requested.emit(false))
_ws_tex.pressed.connect(func(): workspace_requested.emit(true))
add_child(wsp[0])
add_child(_gap(8))
# ================================================== MODEL group ==
# All 3D-modeling buttons. Hidden while the texture editor is
# active - the TEXTURE group replaces it in place.
_model_box = HBoxContainer.new()
_model_box.add_theme_constant_override("separation", 3)
add_child(_model_box)
# --- ADD MODELS: front of the toolbar group, directly after the
# workspace switch - the quickest way to start a scene
var add := _menu("add", "Add a primitive shape")
var am := add.get_popup()
am.add_theme_font_size_override("font_size", 12)
am.add_item("Cube", 0)
am.add_item("Plane", 1)
am.add_item("Cylinder", 2)
am.add_item("Sphere", 3)
am.add_item("Prism", 4)
am.add_item("Torus", 5)
am.id_pressed.connect(func(id: int):
add_shape.emit(["Cube", "Plane", "Cylinder", "Sphere", "Prism", "Torus"][id]))
_model_box.add_child(add)
_model_box.add_child(_gap(6))
# --- selection modes (category 1) ---
var modes := [
[PdDocument.Mode.OBJECT, "mode_object", "Object mode (1)\nSelect and move whole shapes"],
[PdDocument.Mode.VERTEX, "mode_vertex", "Vertex mode (2)\nSelect and drag vertices"],
[PdDocument.Mode.EDGE, "mode_edge", "Edge mode (3)\nSelect and drag edges"],
[PdDocument.Mode.FACE, "mode_face", "Face mode (4)\nSelect and move faces"],
]
for m in modes:
var b := _toggle(m[1], m[2], _mode_group)
b.pressed.connect(func(): mode_requested.emit(m[0]))
_mode_buttons[m[0]] = b
_model_box.add_child(b)
# --- draw (category 2, set slightly apart) ---
_model_box.add_child(_gap(10))
# Draw: split button - main shows the current shape, arrow opens
# the shapes menu; picking a shape enters Draw mode with it.
var dsp := _split("Draw mode (5)\nSketch shapes in any viewport - current shape: Rectangle",
"Choose a shape to draw")
_draw_main = dsp[1]
_draw_arrow = dsp[2]
_draw_main.pressed.connect(func(): mode_requested.emit(PdDocument.Mode.DRAW))
_mode_buttons[PdDocument.Mode.DRAW] = _draw_main
_draw_popup = PopupMenu.new()
_draw_popup.add_theme_font_size_override("font_size", 12)
# match every other icon in the UI (16px) - PopupMenu draws item
# icons at native texture size unless capped, and our source PNGs
# are 32px, so without this the shape list looked twice as big as
# the toolbar buttons that open it.
_draw_popup.add_theme_constant_override("icon_max_width", 16)
for i in PdDocument.DRAW_KINDS.size():
_draw_popup.add_radio_check_item(PdDocument.DRAW_KINDS[i], i)
_draw_popup.set_item_icon(i, _icon(DRAW_ICONS.get(
PdDocument.DRAW_KINDS[i], "tool_rect")))
_draw_popup.id_pressed.connect(func(id: int):
draw_kind.emit(PdDocument.DRAW_KINDS[id])
mode_requested.emit(PdDocument.Mode.DRAW))
_draw_arrow.pressed.connect(func(): _open_popup(_draw_popup, _draw_arrow))
_model_box.add_child(dsp[0])
_model_box.add_child(_draw_popup)
_model_box.add_child(_gap(4))
_model_box.add_child(_sep())
# --- view toggles. The gizmo controls are a SIDE-BY-SIDE pair:
# [Move] [Scale]. The active kind is pressed while the gizmo is
# on; clicking the pressed half again hides the gizmo.
_btn_gizmo_move = _toggle("gizmo_move", "Move Gizmo (G)\nShow the 3-axis move arrows on the selection.\nClick again to hide the gizmo. G/S/R pick Move/Scale/Rotate.\nDirect dragging always works too.")
_btn_gizmo_move.pressed.connect(func(): _gizmo_pair(0))
_model_box.add_child(_btn_gizmo_move)
_btn_gizmo_scale = _toggle("gizmo_scale", "Scale Gizmo (S)\nShow the scale handles on the selection: axis cubes scale one axis,\nthe center cube scales uniformly.\nClick again to hide the gizmo.")
_btn_gizmo_scale.pressed.connect(func(): _gizmo_pair(1))
_model_box.add_child(_btn_gizmo_scale)
_btn_gizmo_rotate = _toggle("gizmo_rotate", "Rotate Gizmo (R)\nShow the rotation rings on the selection: drag a ring to rotate\naround that axis. In the 2D views this is a single ring around the\nview's own axis.\nClick again to hide the gizmo.")
_btn_gizmo_rotate.pressed.connect(func(): _gizmo_pair(2))
_model_box.add_child(_btn_gizmo_rotate)
_btn_snap = _toggle("snap", "Grid snapping (T)\nMoves and shapes land on the grid.\nWorks even when the grid is hidden.")
_btn_snap.pressed.connect(func(): toggle_snap.emit(_btn_snap.button_pressed))
_model_box.add_child(_btn_snap)
_btn_grid = _toggle("grid", "Grid visibility (V)\nHide the grid but keep snapping.")
_btn_grid.pressed.connect(func(): toggle_grid.emit(_btn_grid.button_pressed))
_model_box.add_child(_btn_grid)
_btn_sides = _toggle("doubleside", "Render both sides (B)\nShow backfaces - no culling. On by default.")
_btn_sides.pressed.connect(func(): toggle_both_sides.emit(_btn_sides.button_pressed))
_model_box.add_child(_btn_sides)
_model_box.add_child(_sep())
# --- edit ---
var dup := _button("duplicate", "Duplicate selected object (Ctrl+D)")
dup.pressed.connect(func(): duplicate_requested.emit())
_model_box.add_child(dup)
var del := _button("delete", "Delete selection (Del)")
# destructive action = red icon
del.add_theme_color_override("icon_normal_color",
Color(0.94, 0.44, 0.44, 0.9))
del.add_theme_color_override("icon_hover_color", Color(1, 0.52, 0.52))
del.pressed.connect(func(): delete_requested.emit())
_model_box.add_child(del)
# ================================================ TEXTURE group ==
# Replaces the modeling buttons while the texture editor is
# active: the [Paint | Edit UV] submode buttons followed by the
# contextual toolset of the active submode. Sizes and colors live
# in the right panel.
_tex_box = HBoxContainer.new()
_tex_box.add_theme_constant_override("separation", 3)
_tex_box.visible = false
add_child(_tex_box)
var tgrp := ButtonGroup.new()
# own icon (mode_paint), distinct from tool_brush - the submode
# button and the individual Brush TOOL button below must not read
# as the same control
_tex_paint = _toggle("mode_paint",
"Paint\nBrush, fill and pixel tools paint the texture directly", tgrp)
_tex_paint.pressed.connect(func(): tex_submode.emit(false))
_tex_edituv = _toggle("tool_uv",
"Edit UV\nDrag island corners, edges or whole islands to re-map UVs.\nClick a face in the 3D view to select it - its island highlights here.\nRight-click: detach / merge / extrude / fill / delete menu", tgrp)
_tex_edituv.pressed.connect(func(): tex_submode.emit(true))
_tex_box.add_child(_tex_paint)
_tex_box.add_child(_tex_edituv)
_tex_box.add_child(_sep())
# ---- PAINT submode tools (visible only in Paint submode)
var pgrp := ButtonGroup.new()
var tools := [["Brush", "tool_brush", "Brush - paint smooth round strokes"],
["Fill", "tool_fill", "Fill - repaint exactly one face's texture island"],
["Fill Object", "tool_fillobject", "Fill Object - repaint the whole object's texture"],
["Pixel", "tool_pixel", "Pixel - texel-perfect pixel-art brush"],
["Eraser", "tool_eraser", "Eraser - restore blank with brush strokes (works on the model and the canvas)"],
["Picker", "tool_picker", "Color Picker - click the model or the canvas to make that texel's color the paint color"],
["Replace", "tool_replace", "Replace Color - click a texel: its color is swapped for the paint color across the WHOLE canvas (all faces); the Tolerance slider in the right panel widens the color match"]]
_tex_paint_box = HBoxContainer.new()
_tex_paint_box.add_theme_constant_override("separation", 3)
_tex_box.add_child(_tex_paint_box)
for t in tools:
var b := _toggle(t[1], t[2], pgrp)
b.pressed.connect(func(): paint_tool_requested.emit(t[0]))
_tex_tool_btns[t[0]] = b
_tex_paint_box.add_child(b)
var imp := _button("image",
"Import Image\nPlace a picture onto the texture: move it, wheel-scales,\nclick places it - then paint over it or erase it")
imp.pressed.connect(func(): import_requested.emit())
_tex_paint_box.add_child(imp)
# ---- EDIT UV submode tools (visible only in Edit UV submode)
_tex_uv_box = HBoxContainer.new()
_tex_uv_box.add_theme_constant_override("separation", 3)
_tex_uv_box.visible = false
_tex_box.add_child(_tex_uv_box)
_tex_uv_snap = _toggle("snap", "UV snapping (texel grid)\nUV drags land on whole texels. Hold Ctrl to drag freely.")
_tex_uv_snap.pressed.connect(func(): uv_snap_requested.emit(_tex_uv_snap.button_pressed))
var det := _button("detach",
"Detach selected face(s)\nMove the selected islands to free texture space so they can\nbe moved individually. Select faces, then press.")
det.pressed.connect(func(): detach_requested.emit())
var ruv := _button("uv_reset", "Reset UVs\nRe-unwrap every face of the object to its planar projection")
ruv.pressed.connect(func(): reset_uvs_requested.emit())
# Rotate / Scale: a mutually exclusive toggle pair (the active one
# can be clicked again to switch off). The rotate tool shows the
# 0..360 angle slider in the right panel; the scale tool turns
# every corner drag of the selection into a uniform scale and shows
# the percent slider. Quick 90-degree actions stay available via
# R / Shift+R and the canvas right-click menu.
_uv_tool_group = ButtonGroup.new()
_uv_tool_group.allow_unpress = true
_tex_uv_rotate = _toggle("rotate",
"Rotate UVs\nToggle the rotate tool: an Angle slider (0-360\ndegrees, or type a number) appears in the right panel and\nrotates the selected faces' texture islands around their center.\nR / Shift+R rotate 90 degrees quickly.",
_uv_tool_group)
_tex_uv_rotate.pressed.connect(func():
uv_tool_requested.emit(
"rotate" if _tex_uv_rotate.button_pressed else "none"))
_tex_uv_scale = _toggle("gizmo_scale",
"Scale UVs\nToggle the scale tool: drag any corner of the selected\nisland(s) to scale them uniformly (aspect ratio preserved).\nA Scale slider (10-400%) also appears in the right panel.",
_uv_tool_group)
_tex_uv_scale.pressed.connect(func():
uv_tool_requested.emit(
"scale" if _tex_uv_scale.button_pressed else "none"))
_tex_uv_box.add_child(_tex_uv_snap)
_tex_uv_box.add_child(_tex_uv_rotate)
_tex_uv_box.add_child(_tex_uv_scale)
_tex_uv_box.add_child(det)
_tex_uv_box.add_child(ruv)
add_child(_sep())
# --- history ---
_btn_undo = _button("undo", "Undo (Ctrl+Z)")
_btn_undo.pressed.connect(func(): undo_requested.emit())
add_child(_btn_undo)
_btn_redo = _button("redo", "Redo (Ctrl+Shift+Z)")
_btn_redo.pressed.connect(func(): redo_requested.emit())
add_child(_btn_redo)
add_child(_sep())
# --- file ---
var save := _button("save", "Save project as .pdoodle")
save.pressed.connect(func(): save_requested.emit())
add_child(save)
var open := _button("open", "Open a .pdoodle project")
open.pressed.connect(func(): load_requested.emit())
add_child(open)
var import_model := _button("import_model",
"Import a 3D model (OBJ, glTF, FBX) with its textures")
import_model.pressed.connect(func(): import_model_requested.emit())
add_child(import_model)
var export := _menu("export", "Export for use directly in Godot")
var em := export.get_popup()
em.add_theme_font_size_override("font_size", 12)
em.add_item("Mesh (.tres)", 0)
em.add_item("Scene (.tscn)", 1)
em.add_item("OBJ (.obj + texture)", 2)
em.add_item("Add to current scene", 3)
em.id_pressed.connect(func(id: int):
export_requested.emit(["tres", "tscn", "obj", "scene"][id]))
add_child(export)
var spacer := Control.new()
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
add_child(spacer)
_bg_pick = ColorPickerButton.new()
_bg_pick.custom_minimum_size = Vector2(34, 24)
_bg_pick.focus_mode = Control.FOCUS_NONE
_bg_pick.color = doc.bg_color
_bg_pick.tooltip_text = "Background color"
_bg_pick.color_changed.connect(func(c: Color): bg_changed.emit(c))
add_child(_bg_pick)
# --- editor settings (gear): shading mode buttons, grid toggle ---
_btn_settings = _button("gear", "Editor settings\n3D shading mode, grid and contextual hints")
_btn_settings.pressed.connect(_open_settings)
add_child(_btn_settings)
_build_settings_popup()
# --- documentation (book): every button, tool and feature explained
_btn_docs = _button("docs", "Documentation\nEvery button, tool and feature of the plugin, with how-tos\nand use cases")
_btn_docs.pressed.connect(_open_docs)
add_child(_btn_docs)
sync_from_doc()
func _menu(icon: String, tip: String) -> MenuButton:
var m := MenuButton.new()
m.icon = _icon(icon)
m.text = ""
m.focus_mode = Control.FOCUS_NONE
m.tooltip_text = tip
m.add_theme_constant_override("icon_max_width", 16)
m.flat = false
_style(m)
return m
# -------------------------------------------------------- settings UI ---
## Editor settings: tactile BUTTONS (pressed = active, one button in a
## group is always pressed) instead of on/off switches - a shading mode
## is a choice, not a switch, and a pressed button clearly shows state.
func _build_settings_popup() -> void:
_settings_popup = PopupPanel.new()
var v := VBoxContainer.new()
v.add_theme_constant_override("separation", 8)
v.custom_minimum_size = Vector2(252, 0)
_settings_popup.add_child(v)
var head := Label.new()
head.text = "Editor Settings"
head.add_theme_font_size_override("font_size", 14)
v.add_child(head)
var sh := Label.new()
sh.text = "3D shading"
sh.add_theme_font_size_override("font_size", 11)
sh.modulate = Color(1, 1, 1, 0.6)
v.add_child(sh)
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 4)
v.add_child(row)
var grp := ButtonGroup.new()
var modes := [[0, "Shaded + Wire", "Solid model with an x-ray wireframe overlay"],
[1, "Shaded", "Solid model only - no wireframe"],
[2, "Wireframe", "Wireframe only - no solid surfaces"]]
for md in modes:
var b := Button.new()
b.text = md[1]
b.toggle_mode = true
b.button_group = grp
b.focus_mode = Control.FOCUS_NONE
b.tooltip_text = md[2]
b.add_theme_font_size_override("font_size", 12)
b.custom_minimum_size = Vector2(0, 26)
_style_tactile(b)
var want: int = md[0]
b.pressed.connect(func():
doc.set_view_shading(want)
_sync_settings())
_shade_btns.append([b, want])
row.add_child(b)
var gh := Label.new()
gh.text = "Viewport"
gh.add_theme_font_size_override("font_size", 11)
gh.modulate = Color(1, 1, 1, 0.6)
v.add_child(gh)
_grid_btn = Button.new()
_grid_btn.text = "Show Grid"
_grid_btn.toggle_mode = true
_grid_btn.focus_mode = Control.FOCUS_NONE
_grid_btn.tooltip_text = "Show or hide the grid (V)\nSnapping keeps working while the grid is hidden"
_grid_btn.add_theme_font_size_override("font_size", 12)
_grid_btn.custom_minimum_size = Vector2(0, 26)
_style_tactile(_grid_btn)
_grid_btn.pressed.connect(func():
doc.set_grid_visible(_grid_btn.button_pressed)
_sync_settings())
v.add_child(_grid_btn)
_hints_btn = Button.new()
_hints_btn.text = "Contextual Hints"
_hints_btn.toggle_mode = true
_hints_btn.focus_mode = Control.FOCUS_NONE
_hints_btn.tooltip_text = "Show or hide the in-viewport tip lines\n(the small help text at the bottom of each view)"
_hints_btn.add_theme_font_size_override("font_size", 12)
_hints_btn.custom_minimum_size = Vector2(0, 26)
_style_tactile(_hints_btn)
_hints_btn.pressed.connect(func():
doc.set_hints(_hints_btn.button_pressed)
_sync_settings())
v.add_child(_hints_btn)
var ch := Label.new()
ch.text = "Checkerboard"
ch.add_theme_font_size_override("font_size", 11)
ch.modulate = Color(1, 1, 1, 0.6)
v.add_child(ch)
_checker_btn = Button.new()
_checker_btn.text = "Show Checkerboard"
_checker_btn.toggle_mode = true
_checker_btn.focus_mode = Control.FOCUS_NONE
_checker_btn.tooltip_text = "Show or hide the checkerboard under unpainted texels\n\nON: unpainted areas show the checker placeholder (the classic look).\nOFF: unpainted areas are FULLY TRANSPARENT in every view - and they\nexport transparent (alpha 0), so the model gets real holes there."
_checker_btn.add_theme_font_size_override("font_size", 12)
_checker_btn.custom_minimum_size = Vector2(0, 26)
_style_tactile(_checker_btn)
_checker_btn.pressed.connect(func():
doc.set_show_checker(_checker_btn.button_pressed)
_sync_settings())
v.add_child(_checker_btn)
_bake_btn = Button.new()
_bake_btn.text = "Bake Into Export"
_bake_btn.toggle_mode = true
_bake_btn.focus_mode = Control.FOCUS_NONE
_bake_btn.tooltip_text = "Bake the checkerboard into every exported texture\n\nON: exported textures (mesh, scene, OBJ PNGs) carry the checker -\nnothing is transparent where nothing was painted.\nOFF: the export follows the Show Checkerboard switch - hidden checker\nexports transparent, visible checker exports baked.\nRender Both Sides always applies to the exported material."
_bake_btn.add_theme_font_size_override("font_size", 12)
_bake_btn.custom_minimum_size = Vector2(0, 26)
_style_tactile(_bake_btn)
_bake_btn.pressed.connect(func():
doc.set_export_checker(_bake_btn.button_pressed)
_sync_settings())
v.add_child(_bake_btn)
add_child(_settings_popup)
func _open_settings() -> void:
_sync_settings()
_settings_popup.reset_size()
_place_settings_popup()
_settings_popup.popup()
# embedded popups can be re-fitted by the windowing system on
# show: re-place once the REAL size is known
_place_settings_popup.call_deferred()
## Position the settings popup on the RIGHT side, right-aligned under the
## gear, clamped INSIDE the plugin tab area so it can never spill over
## the editor docks. Falls back to the editor base-control rect when the
## main screen reports a degenerate (headless / not-yet-laid-out) rect.
func _place_settings_popup() -> void:
if _settings_popup == null or not is_instance_valid(_settings_popup):
return
var gear := _btn_settings.get_global_rect()
var ps := Vector2(_settings_popup.size)
if ps.x <= 1.0 or ps.y <= 1.0:
ps = _settings_popup.get_contents_minimum_size() \
+ Vector2(8, 8)
var main := EditorInterface.get_editor_main_screen().get_global_rect()
if main.size.x < 50.0 or main.size.y < 50.0:
main = EditorInterface.get_base_control().get_global_rect()
var margin := 4.0
var pos := Vector2(gear.end.x - ps.x, gear.end.y + 2.0)
pos.x = clampf(pos.x, main.position.x + margin,
maxf(main.position.x + margin, main.end.x - ps.x - margin))
pos.y = clampf(pos.y, main.position.y + margin,
maxf(main.position.y + margin, main.end.y - ps.y - margin))
_settings_popup.position = Vector2i(int(pos.x), int(pos.y))
func _sync_settings() -> void:
if _settings_popup == null:
return
for pair in _shade_btns:
var b: Button = pair[0]
b.set_pressed_no_signal(doc.view_shading == int(pair[1]))
_grid_btn.set_pressed_no_signal(doc.grid_visible)
if _hints_btn != null:
_hints_btn.set_pressed_no_signal(doc.hints_enabled)
if _checker_btn != null:
_checker_btn.set_pressed_no_signal(doc.show_checker)
if _bake_btn != null:
_bake_btn.set_pressed_no_signal(doc.export_checker)
# --------------------------------------------------------- gizmo pair ---
## One of the three gizmo buttons was pressed: select that kind and show
## the gizmo, or hide the gizmo when the active kind is clicked again.
func _gizmo_pair(kind: int) -> void:
if doc.gizmo_on and doc.gizmo_kind == kind:
doc.set_gizmo(false)
toggle_gizmo.emit(false)
else:
doc.set_gizmo(true)
toggle_gizmo.emit(true)
if doc.gizmo_kind != kind:
gizmo_kind_requested.emit(kind)
doc.set_gizmo_kind(kind)
sync_from_doc()
# -------------------------------------------------------------- docs ---
## Open (or raise) the documentation window next to the settings gear.
## The Window must be parented into the editor's base control or it will
## never be shown.
func _open_docs() -> void:
if _docs_win != null and is_instance_valid(_docs_win):
_docs_win.show()
_docs_win.move_to_foreground()
else:
_docs_win = PdDocs.open(null)
EditorInterface.get_base_control().add_child(_docs_win)
# CENTER the window on the editor: an unpositioned editor
# Window opens in the top-left corner. Computed from the
# base control's rect (popup_centered mis-centers when the
# host screen reports a degenerate size) and clamped so a
# degenerate rect can never push it off-screen.
var bc := EditorInterface.get_base_control()
var br := bc.get_global_rect()
var cp := br.position + ((br.size - Vector2(_docs_win.size))
* 0.5).floor()
_docs_win.position = Vector2i(
maxi(0, int(cp.x)), maxi(0, int(cp.y)))
func sync_from_doc() -> void:
if doc == null:
return
# workspace switch: exactly one half active, and the contextual
# group swaps in place - texture tools REPLACE the modeling tools
var tex := doc.mode == PdDocument.Mode.TEXTURE
_ws_3d.button_pressed = not tex
_ws_tex.button_pressed = tex
if _model_box != null:
_model_box.visible = not tex
if _tex_box != null:
_tex_box.visible = tex
for m in _mode_buttons:
_mode_buttons[m].button_pressed = m == doc.mode
# side-by-side gizmo pair mirrors on/off AND the active kind
_btn_gizmo_move.set_pressed_no_signal(doc.gizmo_on and doc.gizmo_kind == 0)
_btn_gizmo_scale.set_pressed_no_signal(doc.gizmo_on and doc.gizmo_kind == 1)
_btn_gizmo_rotate.set_pressed_no_signal(doc.gizmo_on and doc.gizmo_kind == 2)
_btn_snap.button_pressed = doc.snap_enabled
_btn_grid.button_pressed = doc.grid_visible
_btn_sides.button_pressed = doc.both_sides
# draw split button: main icon always mirrors the active shape
_draw_main.icon = _icon(DRAW_ICONS.get(doc.draw_kind, "tool_rect"))
_draw_main.tooltip_text = "Draw mode (5)\nSketch shapes in any viewport - current shape: %s" % doc.draw_kind
for i in PdDocument.DRAW_KINDS.size():
_draw_popup.set_item_checked(i, PdDocument.DRAW_KINDS[i] == doc.draw_kind)
# texture group state (contextual: paint tools OR uv tools)
_tex_paint.set_pressed_no_signal(not doc.tex_edit)
_tex_edituv.set_pressed_no_signal(doc.tex_edit)
if _tex_paint_box != null:
_tex_paint_box.visible = not doc.tex_edit
if _tex_uv_box != null:
_tex_uv_box.visible = doc.tex_edit
for t in _tex_tool_btns:
_tex_tool_btns[t].set_pressed_no_signal(t == doc.paint_tool)
_tex_uv_snap.set_pressed_no_signal(doc.uv_snap)
if _tex_uv_rotate != null:
_tex_uv_rotate.set_pressed_no_signal(doc.uv_tool == "rotate")
if _tex_uv_scale != null:
_tex_uv_scale.set_pressed_no_signal(doc.uv_tool == "scale")
_btn_undo.disabled = not doc.undo.has_undo()
_btn_redo.disabled = not doc.undo.has_redo()
if _bg_pick:
_bg_pick.set_deferred("color", doc.bg_color)
func set_bg_silent(c: Color) -> void:
if _bg_pick:
_bg_pick.set_deferred("color", c)