63ca316efe755ba04bd3ad160ce30bcc8f65b071
[blender.git] / release / ui / space_image.py
1
2 import bpy
3
4 class IMAGE_MT_view(bpy.types.Menu):
5         __space_type__ = "IMAGE_EDITOR"
6         __label__ = "View"
7
8         def draw(self, context):
9                 layout = self.layout
10                 sima = context.space_data
11                 uv = sima.uv_editor
12                 settings = context.scene.tool_settings
13
14                 show_uvedit = sima.show_uvedit
15
16                 layout.itemO("IMAGE_OT_properties") # icon
17
18                 layout.itemS()
19
20                 layout.itemR(sima, "update_automatically")
21                 if show_uvedit:
22                         layout.itemR(settings, "uv_local_view") # Numpad /
23
24                 layout.itemS()
25
26                 layout.itemO("IMAGE_OT_view_zoom_in")
27                 layout.itemO("IMAGE_OT_view_zoom_out")
28
29                 layout.itemS()
30
31                 ratios = [[1, 8], [1, 4], [1, 2], [1, 1], [2, 1], [4, 1], [8, 1]];
32
33                 for a, b in ratios:
34                         text = "Zoom %d:%d" % (a, b)
35                         layout.item_floatO("IMAGE_OT_view_zoom_ratio", "ratio", a/b, text=text)
36
37                 layout.itemS()
38
39                 if show_uvedit:
40                         layout.itemO("IMAGE_OT_view_selected")
41
42                 layout.itemO("IMAGE_OT_view_all")
43                 layout.itemO("SCREEN_OT_screen_full_area")
44
45 class IMAGE_MT_select(bpy.types.Menu):
46         __space_type__ = "IMAGE_EDITOR"
47         __label__ = "Select"
48
49         def draw(self, context):
50                 layout = self.layout
51
52                 layout.itemO("UV_OT_select_border")
53                 layout.item_booleanO("UV_OT_select_border", "pinned", True)
54
55                 layout.itemS()
56                 
57                 layout.itemO("UV_OT_select_all_toggle")
58                 layout.itemO("UV_OT_select_invert")
59                 layout.itemO("UV_OT_unlink_selection")
60                 
61                 layout.itemS()
62
63                 layout.itemO("UV_OT_select_pinned")
64                 layout.itemO("UV_OT_select_linked")
65
66 class IMAGE_MT_image(bpy.types.Menu):
67         __space_type__ = "IMAGE_EDITOR"
68         __label__ = "Image"
69
70         def draw(self, context):
71                 layout = self.layout
72                 sima = context.space_data
73                 ima = sima.image
74
75                 layout.itemO("IMAGE_OT_new")
76                 layout.itemO("IMAGE_OT_open")
77
78                 show_render = sima.show_render
79
80                 if ima:
81                         if show_render:
82                                 layout.itemO("IMAGE_OT_replace")
83                                 layout.itemO("IMAGE_OT_reload")
84
85                         layout.itemO("IMAGE_OT_save")
86                         layout.itemO("IMAGE_OT_save_as")
87
88                         if ima.source == "SEQUENCE":
89                                 layout.itemO("IMAGE_OT_save_sequence")
90
91                         if not show_render:
92                                 layout.itemS()
93
94                                 if ima.packed_file:
95                                         layout.itemO("IMAGE_OT_unpack")
96                                 else:
97                                         layout.itemO("IMAGE_OT_pack")
98
99                                 # only for dirty && specific image types : XXX poll?
100                                 #if(ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
101                                 if False:
102                                         if ima.source in ("FILE", "GENERATED") and ima.type != "MULTILAYER":
103                                                 layout.item_booleanO("IMAGE_OT_pack", "as_png", True, text="Pack As PNG")
104
105                         layout.itemS()
106
107                         layout.itemR(sima, "image_painting")
108
109 class IMAGE_MT_uvs_showhide(bpy.types.Menu):
110         __space_type__ = "IMAGE_EDITOR"
111         __label__ = "Show/Hide Faces"
112
113         def draw(self, context):
114                 layout = self.layout
115
116                 layout.itemO("UV_OT_reveal")
117                 layout.itemO("UV_OT_hide")
118                 layout.item_booleanO("UV_OT_hide", "unselected", True)
119
120 class IMAGE_MT_uvs_transform(bpy.types.Menu):
121         __space_type__ = "IMAGE_EDITOR"
122         __label__ = "Transform"
123
124         def draw(self, context):
125                 layout = self.layout
126
127                 layout.item_enumO("TFM_OT_transform", "mode", "TRANSLATION")
128                 layout.item_enumO("TFM_OT_transform", "mode", "ROTATION")
129                 layout.item_enumO("TFM_OT_transform", "mode", "RESIZE")
130
131 class IMAGE_MT_uvs_mirror(bpy.types.Menu):
132         __space_type__ = "IMAGE_EDITOR"
133         __label__ = "Mirror"
134
135         def draw(self, context):
136                 layout = self.layout
137
138                 layout.item_enumO("UV_OT_mirror", "axis", "MIRROR_X") # "X Axis", M, 
139                 layout.item_enumO("UV_OT_mirror", "axis", "MIRROR_Y") # "Y Axis", M, 
140
141 class IMAGE_MT_uvs_weldalign(bpy.types.Menu):
142         __space_type__ = "IMAGE_EDITOR"
143         __label__ = "Weld/Align"
144
145         def draw(self, context):
146                 layout = self.layout
147
148                 layout.itemO("UV_OT_weld") # W, 1
149                 layout.items_enumO("UV_OT_align", "axis") # W, 2/3/4
150
151
152 class IMAGE_MT_uvs(bpy.types.Menu):
153         __space_type__ = "IMAGE_EDITOR"
154         __label__ = "UVs"
155
156         def draw(self, context):
157                 layout = self.layout
158                 sima = context.space_data
159                 uv = sima.uv_editor
160                 settings = context.scene.tool_settings
161
162                 layout.itemR(uv, "snap_to_pixels")
163                 layout.itemR(uv, "constrain_to_image_bounds")
164
165                 layout.itemS()
166
167                 layout.itemR(uv, "live_unwrap")
168                 layout.itemO("UV_OT_unwrap")
169                 layout.item_booleanO("UV_OT_pin", "clear", True, text="Unpin")
170                 layout.itemO("UV_OT_pin")
171
172                 layout.itemS()
173
174                 layout.itemO("UV_OT_pack_islands")
175                 layout.itemO("UV_OT_average_islands_scale")
176                 layout.itemO("UV_OT_minimize_stretch")
177                 layout.itemO("UV_OT_stitch")
178
179                 layout.itemS()
180
181                 layout.itemM("IMAGE_MT_uvs_transform")
182                 layout.itemM("IMAGE_MT_uvs_mirror")
183                 layout.itemM("IMAGE_MT_uvs_weldalign")
184
185                 layout.itemS()
186
187                 layout.itemR(settings, "proportional_editing")
188                 layout.item_menu_enumR(settings, "proportional_editing_falloff")
189
190                 layout.itemS()
191
192                 layout.itemM("IMAGE_MT_uvs_showhide")
193
194 class IMAGE_HT_header(bpy.types.Header):
195         __space_type__ = "IMAGE_EDITOR"
196
197         def draw(self, context):
198                 sima = context.space_data
199                 ima = sima.image
200                 iuser = sima.image_user
201                 layout = self.layout
202                 settings = context.scene.tool_settings
203
204                 show_render = sima.show_render
205                 show_paint = sima.show_paint
206                 show_uvedit = sima.show_uvedit
207
208                 layout.template_header()
209
210                 # menus
211                 if context.area.show_menus:
212                         row = layout.row()
213                         row.itemM("IMAGE_MT_view")
214
215                         if show_uvedit:
216                                 row.itemM("IMAGE_MT_select")
217
218                         # XXX menuname= (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))? "Image*": "Image";
219                         row.itemM("IMAGE_MT_image")
220
221                         if show_uvedit:
222                                 row.itemM("IMAGE_MT_uvs")
223
224                 layout.template_ID(sima, "image", new="IMAGE_OT_new", open="IMAGE_OT_open")
225
226                 """
227                 /* image select */
228
229                 pinflag= (show_render)? 0: UI_ID_PIN;
230                 xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)sima->image, ID_IM, &sima->pin, xco, yco,
231                         sima_idpoin_handle, UI_ID_BROWSE|UI_ID_BROWSE_RENDER|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_OPEN|UI_ID_DELETE|pinflag);
232                 xco += 8;
233                 """
234
235                 """
236                 if(ima && !ELEM3(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE, IMA_SRC_VIEWER) && ima->ok) {
237                         /* XXX this should not be a static var */
238                         static int headerbuttons_packdummy;
239                         
240                         headerbuttons_packdummy = 0;
241
242                         if (ima->packedfile) {
243                                 headerbuttons_packdummy = 1;
244                         }
245                         if (ima->packedfile && ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
246                                 uiDefIconButBitI(block, TOG, 1, 0 /* XXX B_SIMA_REPACK */, ICON_UGLYPACKAGE,    xco,yco,XIC,YIC, &headerbuttons_packdummy, 0, 0, 0, 0, "Re-Pack this image as PNG");
247                         else
248                                 uiDefIconButBitI(block, TOG, 1, 0 /* XXX B_SIMAPACKIMA */, ICON_PACKAGE,        xco,yco,XIC,YIC, &headerbuttons_packdummy, 0, 0, 0, 0, "Pack/Unpack this image");
249                                 
250                         xco+= XIC+8;
251                 }
252                 """
253
254                 # uv editing
255                 if show_uvedit:
256                         uvedit = sima.uv_editor
257
258                         layout.itemS()
259
260                         layout.itemR(uvedit, "pivot", text="")
261                         layout.itemR(settings, "uv_sync_selection", text="")
262
263                         if settings.uv_sync_selection:
264                                 layout.itemR(settings, "mesh_selection_mode", text="", expand=True)
265                         else:
266                                 layout.itemR(settings, "uv_selection_mode", text="", expand=True)
267                                 layout.itemR(uvedit, "sticky_selection_mode", text="")
268                         pass
269
270                         row = layout.row(align=True)
271                         row.itemR(settings, "snap", text="")
272                         if settings.snap:
273                                 row.itemR(settings, "snap_mode", text="")
274
275                         """
276                         mesh = context.edit_object.data
277                         row.item_pointerR(mesh, "active_uv_layer", mesh, "uv_layers")
278                         """
279
280                 if ima:
281                         # layers
282                         layout.template_image_layers(ima, iuser)
283
284                         # painting
285                         layout.itemR(sima, "image_painting", text="")
286
287                         # draw options
288                         row = layout.row(align=True)
289                         row.itemR(sima, "draw_channels", text="", expand=True)
290
291                         row = layout.row(align=True)
292                         if ima.type == "COMPOSITE":
293                                 row.itemO("IMAGE_OT_record_composite", icon="ICON_REC")
294                         if ima.type == "COMPOSITE" and ima.source in ("MOVIE", "SEQUENCE"):
295                                 row.itemO("IMAGE_OT_play_composite", icon="ICON_PLAY")
296                 
297                 layout.itemR(sima, "update_automatically", text="")
298
299 class IMAGE_PT_game_properties(bpy.types.Panel):
300         __space_type__ = "IMAGE_EDITOR"
301         __region_type__ = "UI"
302         __label__ = "Game Properties"
303
304         def poll(self, context):
305                 sima = context.space_data
306                 return (sima and sima.image)
307
308         def draw(self, context):
309                 sima = context.space_data
310                 layout = self.layout
311
312                 ima = sima.image
313
314                 if ima:
315                         split = layout.split()
316
317                         col = split.column()
318
319                         subcol = col.column(align=True)
320                         subcol.itemR(ima, "clamp_x")
321                         subcol.itemR(ima, "clamp_y")
322
323                         col.itemR(ima, "mapping", expand=True)
324                         col.itemR(ima, "tiles")
325
326                         col = split.column()
327
328                         subcol = col.column(align=True)
329                         subcol.itemR(ima, "animated")
330
331                         subcol = subcol.column()
332                         subcol.itemR(ima, "animation_start", text="Start")
333                         subcol.itemR(ima, "animation_end", text="End")
334                         subcol.itemR(ima, "animation_speed", text="Speed")
335                         subcol.active = ima.animated
336
337                         subrow = col.row(align=True)
338                         subrow.itemR(ima, "tiles_x", text="X")
339                         subrow.itemR(ima, "tiles_y", text="Y")
340                         subrow.active = ima.tiles or ima.animated
341
342 class IMAGE_PT_view_properties(bpy.types.Panel):
343         __space_type__ = "IMAGE_EDITOR"
344         __region_type__ = "UI"
345         __label__ = "View Properties"
346
347         def draw(self, context):
348                 sima = context.space_data
349                 layout = self.layout
350
351                 ima = sima.image
352                 show_uvedit = sima.show_uvedit
353                 uvedit = sima.uv_editor
354
355                 split = layout.split()
356
357                 col = split.column()
358                 if ima:
359                         col.itemR(ima, "display_aspect")
360
361                 col = split.column()
362                 col.itemR(sima, "draw_repeated", text="Repeat")
363                 if show_uvedit:
364                         col.itemR(uvedit, "normalized_coordinates")
365
366                 if show_uvedit:
367                         col = layout.column()
368                         row = col.row()
369                         row.itemR(uvedit, "edge_draw_type", expand=True)
370                         row = col.row()
371                         row.itemR(uvedit, "draw_smooth_edges", text="Smooth")
372                         row.itemR(uvedit, "draw_modified_edges", text="Modified")
373
374                         row = col.row()
375                         row.itemR(uvedit, "draw_stretch", text="Stretch")
376                         row.itemR(uvedit, "draw_stretch_type", text="")
377                         #col.itemR(uvedit, "draw_edges")
378                         #col.itemR(uvedit, "draw_faces")
379
380 class IMAGE_PT_curves(bpy.types.Panel):
381         __space_type__ = "IMAGE_EDITOR"
382         __region_type__ = "UI"
383         __label__ = "Curves"
384
385         def poll(self, context):
386                 sima = context.space_data
387                 return (sima and sima.image)
388
389         def draw(self, context):
390                 sima = context.space_data
391                 layout = self.layout
392
393                 layout.template_curve_mapping(sima.curves)
394
395 bpy.types.register(IMAGE_MT_view)
396 bpy.types.register(IMAGE_MT_select)
397 bpy.types.register(IMAGE_MT_image)
398 bpy.types.register(IMAGE_MT_uvs_showhide)
399 bpy.types.register(IMAGE_MT_uvs_transform)
400 bpy.types.register(IMAGE_MT_uvs_mirror)
401 bpy.types.register(IMAGE_MT_uvs_weldalign)
402 bpy.types.register(IMAGE_MT_uvs)
403 bpy.types.register(IMAGE_HT_header)
404 bpy.types.register(IMAGE_PT_game_properties)
405 bpy.types.register(IMAGE_PT_view_properties)
406 #bpy.types.register(IMAGE_PT_curves)
407