UI: use icons for the toolbar

This commit is contained in:
Campbell Barton 2018-04-24 09:19:28 +02:00
parent 4b544e857c
commit 3581b997d4
13 changed files with 97 additions and 37 deletions

View File

@ -123,7 +123,7 @@ def write_mesh_data_lists(me):
return (tris_coords, tris_colors)
def write_mesh_to_py(fh, me):
def write_mesh_to_py(fh, ob):
def float_as_byte(f):
# -1..1 -> 0..255
@ -131,14 +131,24 @@ def write_mesh_to_py(fh, me):
f = int(round(f * 255))
return min(max(f, 0), 255)
tris_coords, tris_colors = write_mesh_data_lists(me)
with TriMesh(ob) as me:
tris_coords, tris_colors = write_mesh_data_lists(me)
# pixel size needs to be increased since a pixel needs one extra geom coordinate
coords_range = (
ob.get("size_x") or 255,
ob.get("size_y") or 255,
)
print("Writing:", fh.name, coords_range)
fw = fh.write
# Header (version 0).
fw(b'VCO\x00')
# Width, Height
fw(bytes((255, 255)))
fw(bytes(coords_range))
# X, Y
fw(bytes((0, 0)))
@ -197,10 +207,8 @@ def main():
for name, ob in objects:
filename = os.path.join(args.output_dir, name + ".dat")
print("Writing:", filename)
with open(filename, 'wb') as fh:
with TriMesh(ob) as me:
write_mesh_to_py(fh, me)
write_mesh_to_py(fh, ob)
if __name__ == "__main__":

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -27,6 +27,9 @@ __all__ = (
)
# (filename -> icon_value) map
_icon_cache = {}
class ToolSelectPanelHelper:
"""
Generic Class, can be used for any toolbar.
@ -51,6 +54,28 @@ class ToolSelectPanelHelper:
an optional triple of: ``(operator_id, operator_properties, keymap_item_args)``
"""
@staticmethod
def _icon_value_from_icon_handle(icon_name):
import os
if icon_name is not None:
assert(type(icon_name) is str)
icon_value = _icon_cache.get(icon_name)
if icon_value is None:
dirname = bpy.utils.resource_path('SYSTEM')
filename = os.path.join(dirname, "datafiles", "icons", icon_name + ".dat")
try:
icon_value = bpy.app.icons.new_triangles_from_file(filename)
except Exception as ex:
if os.path.exists(filename):
print("Missing icons:", filename, ex)
else:
print("Corrupt icon:", filename, ex)
icon_value = 0
_icon_cache[icon_name] = icon_value
return icon_value
else:
return 0
@staticmethod
def _tool_is_group(tool):
return type(tool[0]) is not str
@ -68,9 +93,9 @@ class ToolSelectPanelHelper:
@classmethod
def _tool_vars_from_def(cls, item):
text, mp_idname, actions = item
text, icon_name, mp_idname, actions = item
km, km_idname = (None, None) if actions is None else cls._tool_keymap[text]
return (km_idname, mp_idname)
return (km_idname, mp_idname), icon_name
@staticmethod
def _tool_vars_from_active_with_index(context):
@ -89,7 +114,7 @@ class ToolSelectPanelHelper:
)
@classmethod
def _km_actionmouse_simple(cls, kc, text, actions):
def _km_actionmouse_simple(cls, kc, text, icon_name, actions):
# standalone
def props_assign_recursive(rna_props, py_props):
@ -135,9 +160,9 @@ class ToolSelectPanelHelper:
return
for item in ToolSelectPanelHelper._tools_flatten(cls.tools_all()):
text, mp_idname, actions = item
text, icon_name, mp_idname, actions = item
if actions is not None:
km, km_idname = cls._km_actionmouse_simple(kc, text, actions)
km, km_idname = cls._km_actionmouse_simple(kc, text, icon_name, actions)
cls._tool_keymap[text] = km, km_idname
def draw(self, context):
@ -151,12 +176,16 @@ class ToolSelectPanelHelper:
tool_def_active, index_active = self._tool_vars_from_active_with_index(context)
layout = self.layout
scale_y = 2.0
for tool_items in self.tools_from_context(context):
if tool_items:
col = layout.column(align=True)
col.scale_y = scale_y
for item in tool_items:
if item is None:
col = layout.column(align=True)
col.scale_y = scale_y
continue
if self._tool_is_group(item):
@ -165,7 +194,7 @@ class ToolSelectPanelHelper:
for i, sub_item in enumerate(item):
if sub_item is None:
continue
tool_def = self._tool_vars_from_def(sub_item)
tool_def, icon_name = self._tool_vars_from_def(sub_item)
is_active = (tool_def == tool_def_active)
if is_active:
index = i
@ -184,21 +213,23 @@ class ToolSelectPanelHelper:
index = -1
use_menu = False
tool_def = self._tool_vars_from_def(item)
tool_def, icon_name = self._tool_vars_from_def(item)
is_active = (tool_def == tool_def_active)
icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(icon_name)
if use_menu:
props = col.operator_menu_hold(
"wm.tool_set",
text=item[0],
depress=is_active,
menu="WM_MT_toolsystem_submenu",
icon_value=icon_value,
)
else:
props = col.operator(
"wm.tool_set",
text=item[0],
depress=is_active,
icon_value=icon_value,
)
props.keymap = tool_def[0] or ""
@ -231,7 +262,7 @@ class WM_MT_toolsystem_submenu(Menu):
if (item_group is not None) and ToolSelectPanelHelper._tool_is_group(item_group):
if index_button < len(item_group):
item = item_group[index_button]
tool_def = cls._tool_vars_from_def(item)
tool_def, icon_name = cls._tool_vars_from_def(item)
is_active = (tool_def == tool_def_button)
if is_active:
return cls, item_group, index_button
@ -239,6 +270,8 @@ class WM_MT_toolsystem_submenu(Menu):
def draw(self, context):
layout = self.layout
layout.scale_y = 2.0
cls, item_group, index_active = self._tool_group_from_button(context)
if item_group is None:
# Should never happen, just in case
@ -250,10 +283,12 @@ class WM_MT_toolsystem_submenu(Menu):
if item is None:
layout.separator()
continue
tool_def = cls._tool_vars_from_def(item)
tool_def, icon_name = cls._tool_vars_from_def(item)
icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(icon_name)
props = layout.operator(
"wm.tool_set",
text=item[0],
icon_value=icon_value,
)
props.keymap = tool_def[0] or ""
props.manipulator_group = tool_def[1] or ""

View File

@ -53,34 +53,36 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
# for reuse
_tools_transform = (
("Translate", "TRANSFORM_WGT_manipulator",
("Translate", "ops.transform.translate", "TRANSFORM_WGT_manipulator",
(("transform.translate", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')),)),
("Rotate", "TRANSFORM_WGT_manipulator",
("Rotate", "ops.transform.rotate", "TRANSFORM_WGT_manipulator",
(("transform.rotate", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')),)),
("Scale", "TRANSFORM_WGT_manipulator",
(("transform.resize", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')),)),
("Scale Cage", "VIEW3D_WGT_xform_cage", None),
(
("Scale", "ops.transform.resize", "TRANSFORM_WGT_manipulator",
(("transform.resize", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')),)),
("Scale Cage", "ops.transform.resize.cage", "VIEW3D_WGT_xform_cage", None),
),
None,
("Ruler/Protractor", "VIEW3D_WGT_ruler",
("Ruler/Protractor", None, "VIEW3D_WGT_ruler",
(("view3d.ruler_add", dict(), dict(type='EVT_TWEAK_A', value='ANY')),)),
)
_tools = {
None: [
("Cursor", None,
("Cursor", "ops.generic.cursor", None,
(("view3d.cursor3d", dict(), dict(type='ACTIONMOUSE', value='CLICK')),)),
# 'Select' Group
(
("Select Border", None, (
("Select Border", "ops.generic.select_border", None, (
("view3d.select_border", dict(deselect=False), dict(type='EVT_TWEAK_A', value='ANY')),
("view3d.select_border", dict(deselect=True), dict(type='EVT_TWEAK_A', value='ANY', ctrl=True)),
)),
("Select Circle", None, (
("Select Circle", "ops.generic.select_circle", None, (
("view3d.select_circle", dict(deselect=False), dict(type='ACTIONMOUSE', value='PRESS')),
("view3d.select_circle", dict(deselect=True), dict(type='ACTIONMOUSE', value='PRESS', ctrl=True)),
)),
("Select Lasso", None, (
("Select Lasso", "ops.generic.select_lasso", None, (
("view3d.select_lasso",
dict(deselect=False), dict(type='EVT_TWEAK_A', value='ANY')),
("view3d.select_lasso",
@ -97,28 +99,28 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
],
'EDIT_ARMATURE': [
*_tools_transform,
("Roll", None, (
("Roll", None, None, (
("transform.transform",
dict(release_confirm=True, mode='BONE_ROLL'),
dict(type='EVT_TWEAK_A', value='ANY')),
)),
None,
("Extrude Cursor", None,
("Extrude Cursor", None, None,
(("armature.click_extrude", dict(), dict(type='ACTIONMOUSE', value='PRESS')),)),
],
'EDIT_MESH': [
*_tools_transform,
None,
("Rip Region", None, (
("Rip Region", None, None, (
("mesh.rip_move", dict(TRANSFORM_OT_translate=dict(release_confirm=True)),
dict(type='ACTIONMOUSE', value='PRESS')),
)),
("Rip Edge", None, (
("Rip Edge", None, None, (
("mesh.rip_edge_move", dict(TRANSFORM_OT_translate=dict(release_confirm=True)),
dict(type='ACTIONMOUSE', value='PRESS')),
)),
("Poly Build", None, (
("Poly Build", None, None, (
("mesh.polybuild_face_at_cursor_move",
dict(TRANSFORM_OT_translate=dict(release_confirm=True)),
dict(type='ACTIONMOUSE', value='PRESS')),
@ -132,30 +134,30 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
# Knife Group
(
("Knife", None, (
("Knife", None, None, (
("mesh.knife_tool",
dict(wait_for_input=False, use_occlude_geometry=True, only_selected=False),
dict(type='ACTIONMOUSE', value='PRESS')),)),
("Knife (Selected)", None, (
("Knife (Selected)", None, None, (
("mesh.knife_tool",
dict(wait_for_input=False, use_occlude_geometry=False, only_selected=True),
dict(type='ACTIONMOUSE', value='PRESS')),)),
None,
("Bisect", None, (
("Bisect", None, None, (
("mesh.bisect",
dict(),
dict(type='EVT_TWEAK_A', value='ANY')),)),
),
# End group.
("Extrude Cursor", None,
("Extrude Cursor", None, None,
(("mesh.dupli_extrude_cursor", dict(), dict(type='ACTIONMOUSE', value='PRESS')),)),
],
'EDIT_CURVE': [
*_tools_transform,
None,
("Draw", None,
("Draw", None, None,
(("curve.draw", dict(wait_for_input=False), dict(type='ACTIONMOUSE', value='PRESS')),)),
("Extrude Cursor", None,
("Extrude Cursor", None, None,
(("curve.vertex_add", dict(), dict(type='ACTIONMOUSE', value='PRESS')),)),
],
}

View File

@ -1226,6 +1226,15 @@ static void icon_draw_size(
/* We need to flush widget base first to ensure correct ordering. */
UI_widgetbase_draw_cache_flush();
/* TODO(campbell): scale icons up for toolbar, we need a way to detect larger buttons and do this automatic. */
{
/* Icons are currently 38 aligned, scale from 16 -> 38. */
float scale = 2.375f;
y = (y + (h / 2)) - ((h * scale) / 2);
w *= scale;
h *= scale;
}
/* This could re-generate often if rendered at different sizes in the one interface.
* TODO(campbell): support caching multiple sizes. */
ImBuf *ibuf = di->data.geom.image_cache;

View File

@ -958,6 +958,12 @@ delayed_do_install(${TARGETDIR_VER})
unset(BLENDER_TEXT_FILES)
unset(BLENDER_TEXT_FILES_DESTINATION)
# Geometry icons.
install(
DIRECTORY
${CMAKE_SOURCE_DIR}/release/datafiles/icons
DESTINATION ${TARGETDIR_VER}/datafiles
)
# -----------------------------------------------------------------------------
# Setup link libs