; Shared native appearance. Dimensions are logical pixels; the GUI runtime ; scales both fonts and padding when a window moves between monitors. Function WacUiStyle(button:Int,appearance:Int=2) SetButtonAppearance button,appearance SetButtonPadding button,12,6 End Function Function WacUiHeading(gadget:Int,size:Int=16) Local font:Int=LoadFont("Segoe UI",size,True) If font<>0 Then SetGadgetFont gadget,font:FreeFont font End Function ; Collapsible section headings share one look: a bold, left-aligned caption ; after a chevron (UTF-8) that points down while open and right while closed. Global gSectionOpenMark$=Chr($E2)+Chr($96)+Chr($BE)+" " Global gSectionClosedMark$=Chr($E2)+Chr($96)+Chr($B8)+" " Function WacUiSectionHeading(button:Int,size:Int=13) WacUiHeading button,size:WacUiStyle button,2 SetButtonAppearance button,2,1 End Function Function WacUiSectionCaption$(title$,open:Int) If open Then Return gSectionOpenMark+title Return gSectionClosedMark+title End Function Function WacUiButton:Int(caption$,x:Int,y:Int,width:Int,height:Int,parent:Int,style:Int=1) Local button:Int=CreateButton(caption,x,y,width,height,parent,style) If style=1 Or style=4 Or style=5 Then WacUiStyle button If height<34 Then SetButtonPadding button,8,4 EndIf Return button End Function Function WacUiButtonWidth:Int(button:Int,minimum:Int=0) Local width:Int=ButtonPreferredWidth(button) If width1 Then candidate=WacUiJoinPath(GetEnv("blitzpath"),"samples\world-editor\"+relative) If FileType(candidate)<>1 Then candidate=WacUiJoinPath(CurrentDir(),relative) If FileType(candidate)=1 Then Return candidate Return "" End Function ; Loads the Add object icon strip once. Without it, buttons keep their captions. Global gWacAddObjectIconCount:Int=0 Function WacUiAddObjectIcons:Int() If gWacAddObjectIconsSearched Then Return gWacAddObjectIcons gWacAddObjectIconsSearched=True Local path$=WacUiIconPath("add_object.png") If path<>"" Then gWacAddObjectIcons=LoadIconStrip(path) gWacAddObjectIconCount=WacUiPngStripCount(path) EndIf Return gWacAddObjectIcons End Function ; How many square icons a PNG strip holds, from its header's width and height, ; so an older strip beside a newer editor leaves new tiles with their captions. Function WacUiPngStripCount:Int(path$) Local file:Int=ReadFile(path) If file=0 Then Return 0 SeekFile file,16 Local width:Int=0,height:Int=0 For index:Int=0 To 3 width=(width Shl 8) Or ReadByte(file) Next For index=0 To 3 height=(height Shl 8) Or ReadByte(file) Next CloseFile file If height<=0 Then Return 0 Return width/height End Function ; Toolbar and command icons, drawn with the hierarchy icons below by ; tools/Update-WorldEditorIcons.ps1. Keep this order in step with its TOOLBAR. Const WAC_TOOL_ICON_NEW=0,WAC_TOOL_ICON_OPEN=1,WAC_TOOL_ICON_SAVE=2,WAC_TOOL_ICON_UNDO=3 Const WAC_TOOL_ICON_REDO=4,WAC_TOOL_ICON_MOVE=5,WAC_TOOL_ICON_ROTATE=6,WAC_TOOL_ICON_SCALE=7 Const WAC_TOOL_ICON_PLAY=8,WAC_TOOL_ICON_STOP=9,WAC_TOOL_ICON_PAUSE=10,WAC_TOOL_ICON_WARNING=11 Const WAC_TOOL_ICON_OK=12,WAC_TOOL_ICON_TEST=13,WAC_TOOL_ICON_ADD=14,WAC_TOOL_ICON_FRAME=15 Const WAC_TOOL_ICON_DELETE=16,WAC_TOOL_ICON_CONTINUE=17,WAC_TOOL_ICON_SCULPT=18,WAC_TOOL_ICON_PAINT=19 ; The strip's 64-pixel icons stay sharp when shown at 20 on any monitor. ; toolbar_dark.png draws the same icons with light lines, for dark faces. Const WAC_TOOL_ICON_SIZE=20 ; The toolbars' icons, as large as the IDE's toolbar icons. Const WAC_TOOL_BAR_ICON_SIZE=32 Global gToolIcons:Int=0,gToolIconsSearched:Int=False Global gToolIconsDark:Int=0,gToolIconsDarkSearched:Int=False ; The icons for a light face, or with lightInk for a dark one. Without the ; light-line strip, the ordinary one still shows. Function WacToolIconStrip:Int(lightInk:Int=False) If gToolIconsSearched=False Then gToolIconsSearched=True Local path$=WacUiIconPath("toolbar.png") If path<>"" Then gToolIcons=LoadIconStrip(path) EndIf If lightInk And gToolIconsDarkSearched=False Then gToolIconsDarkSearched=True Local darkPath$=WacUiIconPath("toolbar_dark.png") If darkPath<>"" Then gToolIconsDark=LoadIconStrip(darkPath) EndIf If lightInk And gToolIconsDark<>0 Then Return gToolIconsDark Return gToolIcons End Function ; A button showing a command icon, remembered so its icon can be drawn again ; in lines that read on its face whenever the face or the GUI theme changes. Type WacIconButton Field button:Int,icon:Int=-1,strong:Int=False,size:Int=WAC_TOOL_ICON_SIZE End Type Function WacIconButtonFor.WacIconButton(button:Int) For entry.WacIconButton=Each WacIconButton If entry\button=button Then Return entry Next entry=New WacIconButton entry\button=button Return entry End Function ; Forgets a button about to be freed. Function WacIconButtonForget(button:Int) If button=0 Then Return For entry.WacIconButton=Each WacIconButton If entry\button=button Then Delete entry Next End Function ; Puts a command icon before a button's caption. Without the strip the ; button simply keeps its caption. A strong button is an accent or danger ; one, whose face is dark in Light and Classic and light in Dark. Function WacToolIcon(button:Int,icon:Int,strong:Int=-1,size:Int=0) If button=0 Then Return Local entry.WacIconButton=WacIconButtonFor(button) entry\icon=icon If strong<>-1 Then entry\strong=strong If size>0 Then entry\size=size WacIconButtonShow entry End Function ; Changes an icon button's appearance and gives its icon lines that suit ; the new face. Function WacToolAppearance(button:Int,appearance:Int) If button=0 Then Return SetButtonAppearance button,appearance Local entry.WacIconButton=WacIconButtonFor(button) Local strong:Int=appearance=1 Or appearance=4 If strong<>entry\strong Then entry\strong=strong WacIconButtonShow entry EndIf End Function Function WacIconButtonShow(entry.WacIconButton) If entry\icon<0 Then Return Local lightInk:Int=entry\strong If GuiTheme()=2 Then lightInk=Not entry\strong Local strip:Int=WacToolIconStrip(lightInk) If strip<>0 Then SetButtonIcon entry\button,strip,entry\icon,0,entry\size End Function ; The hierarchy's 16-pixel object icons, drawn by the same tool from ; tools/world_editor_icons/editor_ui_icons.js. Keep this order in step with it. Const WAC_TREE_ICON_WORLD=0,WAC_TREE_ICON_PIVOT=1,WAC_TREE_ICON_CAMERA=2,WAC_TREE_ICON_LIGHT=3 Const WAC_TREE_ICON_MODEL=4,WAC_TREE_ICON_SHAPE=5,WAC_TREE_ICON_PLANE=6,WAC_TREE_ICON_TERRAIN=7 Const WAC_TREE_ICON_PREFAB=8,WAC_TREE_ICON_JOINT=9,WAC_TREE_ICON_IMPORTED=10,WAC_TREE_ICON_LOCKED=11 Const WAC_TREE_ICON_OBJECT=12,WAC_TREE_ICON_ZONE=13,WAC_TREE_ICON_REFLECTION_PROBE=14,WAC_TREE_ICON_CROWD=15 Global gWacTreeIcons:Int=0,gWacTreeIconsSearched:Int=False Global gWacTreeIconsDark:Int=0,gWacTreeIconsDarkSearched:Int=False ; The hierarchy icons for the theme being drawn: light lines in Dark. ; The Behaviours section's icons (behaviours.png, and behaviours_dark.png in ; the Dark theme), in WAC_BEHAVIOUR_* order, or 0 without the strips. Global gWacBehaviourIcons:Int=0,gWacBehaviourIconsSearched:Int=False Global gWacBehaviourIconsDark:Int=0,gWacBehaviourIconsDarkSearched:Int=False Function WacUiBehaviourIcons:Int() If gWacBehaviourIconsSearched=False Then gWacBehaviourIconsSearched=True Local path$=WacUiIconPath("behaviours.png") If path<>"" Then gWacBehaviourIcons=LoadIconStrip(path) EndIf If GuiTheme()=2 Then If gWacBehaviourIconsDarkSearched=False Then gWacBehaviourIconsDarkSearched=True Local darkPath$=WacUiIconPath("behaviours_dark.png") If darkPath<>"" Then gWacBehaviourIconsDark=LoadIconStrip(darkPath) EndIf If gWacBehaviourIconsDark<>0 Then Return gWacBehaviourIconsDark EndIf Return gWacBehaviourIcons End Function Function WacUiTreeIcons:Int() If gWacTreeIconsSearched=False Then gWacTreeIconsSearched=True Local path$=WacUiIconPath("tree.png") If path<>"" Then gWacTreeIcons=LoadIconStrip(path) EndIf If GuiTheme()=2 Then If gWacTreeIconsDarkSearched=False Then gWacTreeIconsDarkSearched=True Local darkPath$=WacUiIconPath("tree_dark.png") If darkPath<>"" Then gWacTreeIconsDark=LoadIconStrip(darkPath) EndIf If gWacTreeIconsDark<>0 Then Return gWacTreeIconsDark EndIf Return gWacTreeIcons End Function Function WacUiJoinPath$(directory$,relative$) If directory="" Then Return relative If Right(directory,1)<>"\" And Right(directory,1)<>"/" Then directory=directory+"\" Return directory+relative End Function ; A tile: its icon above its caption, for the Primitives tab's things to add. Function WacUiIconTile(button:Int,icon:Int) SetButtonPadding button,2,5 Local strip:Int=WacUiAddObjectIcons() If strip<>0 And icon