Integrated Freestyle to rendering pipeline
[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                 
11                 sima = context.space_data
12                 uv = sima.uv_editor
13                 settings = context.tool_settings
14
15                 show_uvedit = sima.show_uvedit
16
17                 layout.itemO("image.properties", icon='ICON_MENU_PANEL')
18
19                 layout.itemS()
20
21                 layout.itemR(sima, "update_automatically")
22                 if show_uvedit:
23                         layout.itemR(settings, "uv_local_view") # Numpad /
24
25                 layout.itemS()
26
27                 layout.itemO("image.view_zoom_in")
28                 layout.itemO("image.view_zoom_out")
29
30                 layout.itemS()
31
32                 ratios = [[1, 8], [1, 4], [1, 2], [1, 1], [2, 1], [4, 1], [8, 1]];
33
34                 for a, b in ratios:
35                         text = "Zoom %d:%d" % (a, b)
36                         layout.item_floatO("image.view_zoom_ratio", "ratio", a/float(b), text=text)
37
38                 layout.itemS()
39
40                 if show_uvedit:
41                         layout.itemO("image.view_selected")
42
43                 layout.itemO("image.view_all")
44                 layout.itemO("screen.screen_full_area")
45
46 class IMAGE_MT_select(bpy.types.Menu):
47         __space_type__ = 'IMAGE_EDITOR'
48         __label__ = "Select"
49
50         def draw(self, context):
51                 layout = self.layout
52
53                 layout.itemO("uv.select_border")
54                 layout.item_booleanO("uv.select_border", "pinned", True)
55
56                 layout.itemS()
57                 
58                 layout.itemO("uv.select_all_toggle")
59                 layout.itemO("uv.select_inverse")
60                 layout.itemO("uv.unlink_selection")
61                 
62                 layout.itemS()
63
64                 layout.itemO("uv.select_pinned")
65                 layout.itemO("uv.select_linked")
66
67 class IMAGE_MT_image(bpy.types.Menu):
68         __space_type__ = 'IMAGE_EDITOR'
69         __label__ = "Image"
70
71         def draw(self, context):
72                 layout = self.layout
73
74                 sima = context.space_data
75                 ima = sima.image
76
77                 layout.itemO("image.new")
78                 layout.itemO("image.open")
79
80                 show_render = sima.show_render
81
82                 if ima:
83                         if not show_render:
84                                 layout.itemO("image.replace")
85                                 layout.itemO("image.reload")
86
87                         layout.itemO("image.save")
88                         layout.itemO("image.save_as")
89
90                         if ima.source == 'SEQUENCE':
91                                 layout.itemO("image.save_sequence")
92
93                         if not show_render:
94                                 layout.itemS()
95
96                                 if ima.packed_file:
97                                         layout.itemO("image.unpack")
98                                 else:
99                                         layout.itemO("image.pack")
100
101                                 # only for dirty && specific image types, perhaps
102                                 # this could be done in operator poll too
103                                 if ima.dirty:
104                                         if ima.source in ('FILE', 'GENERATED') and ima.type != 'MULTILAYER':
105                                                 layout.item_booleanO("image.pack", "as_png", True, text="Pack As PNG")
106
107                         layout.itemS()
108
109                         layout.itemR(sima, "image_painting")
110
111 class IMAGE_MT_uvs_showhide(bpy.types.Menu):
112         __space_type__ = 'IMAGE_EDITOR'
113         __label__ = "Show/Hide Faces"
114
115         def draw(self, context):
116                 layout = self.layout
117
118                 layout.itemO("uv.reveal")
119                 layout.itemO("uv.hide")
120                 layout.item_booleanO("uv.hide", "unselected", True)
121
122 class IMAGE_MT_uvs_transform(bpy.types.Menu):
123         __space_type__ = 'IMAGE_EDITOR'
124         __label__ = "Transform"
125
126         def draw(self, context):
127                 layout = self.layout
128
129                 layout.itemO("tfm.translate")
130                 layout.itemO("tfm.rotate")
131                 layout.itemO("tfm.resize")
132
133 class IMAGE_MT_uvs_mirror(bpy.types.Menu):
134         __space_type__ = 'IMAGE_EDITOR'
135         __label__ = "Mirror"
136
137         def draw(self, context):
138                 layout = self.layout
139                 layout.operator_context = "EXEC_REGION_WIN"
140
141                 props= layout.itemO("tfm.mirror", text="X Axis", properties=True)
142                 props.constraint_axis[0]= True
143
144                 props= layout.itemO("tfm.mirror", text="Y Axis", properties=True)
145                 props.constraint_axis[1]= True
146
147 class IMAGE_MT_uvs_weldalign(bpy.types.Menu):
148         __space_type__ = 'IMAGE_EDITOR'
149         __label__ = "Weld/Align"
150
151         def draw(self, context):
152                 layout = self.layout
153
154                 layout.itemO("uv.weld") # W, 1
155                 layout.items_enumO("uv.align", "axis") # W, 2/3/4
156
157 class IMAGE_MT_uvs(bpy.types.Menu):
158         __space_type__ = 'IMAGE_EDITOR'
159         __label__ = "UVs"
160
161         def draw(self, context):
162                 layout = self.layout
163                 
164                 sima = context.space_data
165                 uv = sima.uv_editor
166                 settings = context.tool_settings
167
168                 layout.itemR(uv, "snap_to_pixels")
169                 layout.itemR(uv, "constrain_to_image_bounds")
170
171                 layout.itemS()
172
173                 layout.itemR(uv, "live_unwrap")
174                 layout.itemO("uv.unwrap")
175                 layout.item_booleanO("uv.pin", "clear", True, text="Unpin")
176                 layout.itemO("uv.pin")
177
178                 layout.itemS()
179
180                 layout.itemO("uv.pack_islands")
181                 layout.itemO("uv.average_islands_scale")
182                 layout.itemO("uv.minimize_stretch")
183                 layout.itemO("uv.stitch")
184
185                 layout.itemS()
186
187                 layout.itemM("IMAGE_MT_uvs_transform")
188                 layout.itemM("IMAGE_MT_uvs_mirror")
189                 layout.itemM("IMAGE_MT_uvs_weldalign")
190
191                 layout.itemS()
192
193                 layout.itemR(settings, "proportional_editing")
194                 layout.item_menu_enumR(settings, "proportional_editing_falloff")
195
196                 layout.itemS()
197
198                 layout.itemM("IMAGE_MT_uvs_showhide")
199
200 class IMAGE_HT_header(bpy.types.Header):
201         __space_type__ = 'IMAGE_EDITOR'
202
203         def draw(self, context):
204                 layout = self.layout
205                 
206                 sima = context.space_data
207                 ima = sima.image
208                 iuser = sima.image_user
209                 settings = context.tool_settings
210
211                 show_render = sima.show_render
212                 show_paint = sima.show_paint
213                 show_uvedit = sima.show_uvedit
214
215                 row = layout.row(align=True)
216                 row.template_header()
217
218                 # menus
219                 if context.area.show_menus:
220                         sub = row.row(align=True)
221                         sub.itemM("IMAGE_MT_view")
222
223                         if show_uvedit:
224                                 sub.itemM("IMAGE_MT_select")
225
226                         if ima and ima.dirty:
227                                 sub.itemM("IMAGE_MT_image", text="Image*")
228                         else:
229                                 sub.itemM("IMAGE_MT_image", text="Image")
230
231                         if show_uvedit:
232                                 sub.itemM("IMAGE_MT_uvs")
233
234                 layout.template_ID(sima, "image", new="image.new")
235
236                 # uv editing
237                 if show_uvedit:
238                         uvedit = sima.uv_editor
239
240                         layout.itemR(uvedit, "pivot", text="", icon_only=True)
241                         layout.itemR(settings, "uv_sync_selection", text="")
242
243                         if settings.uv_sync_selection:
244                                 layout.itemR(settings, "mesh_selection_mode", text="", expand=True)
245                         else:
246                                 layout.itemR(settings, "uv_selection_mode", text="", expand=True)
247                                 layout.itemR(uvedit, "sticky_selection_mode", text="", icon_only=True)
248                         pass
249
250                         row = layout.row(align=True)
251                         row.itemR(settings, "snap", text="")
252                         if settings.snap:
253                                 row.itemR(settings, "snap_mode", text="")
254
255                         """
256                         mesh = context.edit_object.data
257                         row.item_pointerR(mesh, "active_uv_layer", mesh, "uv_textures")
258                         """
259
260                 if ima:
261                         # layers
262                         layout.template_image_layers(ima, iuser)
263
264                         # painting
265                         layout.itemR(sima, "image_painting", text="")
266
267                         # draw options
268                         row = layout.row(align=True)
269                         row.itemR(sima, "draw_channels", text="", expand=True)
270
271                         row = layout.row(align=True)
272                         if ima.type == 'COMPOSITE':
273                                 row.itemO("image.record_composite", icon='ICON_REC')
274                         if ima.type == 'COMPOSITE' and ima.source in ('MOVIE', 'SEQUENCE'):
275                                 row.itemO("image.play_composite", icon='ICON_PLAY')
276                 
277                 if show_uvedit or sima.image_painting:
278                         layout.itemR(sima, "update_automatically", text="")
279
280 class IMAGE_PT_image_properties(bpy.types.Panel):
281         __space_type__ = 'IMAGE_EDITOR'
282         __region_type__ = 'UI'
283         __label__ = "Image"
284
285         def poll(self, context):
286                 sima = context.space_data
287                 return (sima.image)
288
289         def draw(self, context):
290                 layout = self.layout
291
292                 sima = context.space_data
293                 ima = sima.image
294                 iuser = sima.image_user
295
296                 layout.template_image(sima, "image", iuser, compact=True)
297
298 class IMAGE_PT_game_properties(bpy.types.Panel):
299         __space_type__ = 'IMAGE_EDITOR'
300         __region_type__ = 'UI'
301         __label__ = "Game Properties"
302
303         def poll(self, context):
304                 rd = context.scene.render_data
305                 sima = context.space_data
306                 return (sima and sima.image) and (rd.engine == 'BLENDER_GAME')
307
308         def draw(self, context):
309                 layout = self.layout
310                 
311                 sima = context.space_data
312                 ima = sima.image
313
314                 split = layout.split()
315
316                 col = split.column()
317                 
318                 sub = col.column(align=True)
319                 sub.itemR(ima, "animated")
320
321                 subsub = sub.column()
322                 subsub.active = ima.animated
323                 subsub.itemR(ima, "animation_start", text="Start")
324                 subsub.itemR(ima, "animation_end", text="End")
325                 subsub.itemR(ima, "animation_speed", text="Speed")
326                 
327                 col.itemR(ima, "tiles")
328                 sub = col.column(align=True)
329                 sub.active = ima.tiles or ima.animated
330                 sub.itemR(ima, "tiles_x", text="X")
331                 sub.itemR(ima, "tiles_y", text="Y")
332         
333                 col = split.column()
334                 col.itemL(text="Clamp:")
335                 col.itemR(ima, "clamp_x", text="X")
336                 col.itemR(ima, "clamp_y", text="Y")
337                 col.itemS()
338                 col.itemR(ima, "mapping", expand=True)
339
340                 
341
342 class IMAGE_PT_view_properties(bpy.types.Panel):
343         __space_type__ = 'IMAGE_EDITOR'
344         __region_type__ = 'UI'
345         __label__ = "Display"
346
347         def poll(self, context):
348                 sima = context.space_data
349                 return (sima and (sima.image or sima.show_uvedit))
350
351         def draw(self, context):
352                 layout = self.layout
353                 
354                 sima = context.space_data
355                 ima = sima.image
356                 show_uvedit = sima.show_uvedit
357                 uvedit = sima.uv_editor
358
359                 split = layout.split()
360
361                 col = split.column()
362                 if ima:
363                         col.itemR(ima, "display_aspect", text="Aspect Ratio")
364
365                         col = split.column()
366                         col.itemL(text="Coordinates:")
367                         col.itemR(sima, "draw_repeated", text="Repeat")
368                         if show_uvedit:
369                                 col.itemR(uvedit, "normalized_coordinates", text="Normalized")
370                 elif show_uvedit:
371                         col.itemL(text="Coordinates:")
372                         col.itemR(uvedit, "normalized_coordinates", text="Normalized")
373
374                 if show_uvedit:
375                         
376                         col = layout.column()
377                         col.itemL(text="UVs:")
378                         row = col.row()
379                         row.itemR(uvedit, "edge_draw_type", expand=True)
380                         
381                         split = layout.split()
382
383                         col = split.column()
384                         col.itemR(uvedit, "draw_stretch", text="Stretch")
385                         sub = col.column()
386                         sub.active = uvedit.draw_stretch
387                         sub.row().itemR(uvedit, "draw_stretch_type", expand=True)
388                         
389                         col = split.column()
390                         col.itemR(uvedit, "draw_smooth_edges", text="Smooth")
391                         col.itemR(uvedit, "draw_modified_edges", text="Modified")
392                         #col.itemR(uvedit, "draw_edges")
393                         #col.itemR(uvedit, "draw_faces")
394
395 class IMAGE_PT_paint(bpy.types.Panel):
396         __space_type__ = 'IMAGE_EDITOR'
397         __region_type__ = 'UI'
398         __label__ = "Paint"
399
400         def poll(self, context):
401                 sima = context.space_data
402                 return sima.show_paint
403
404         def draw(self, context):
405                 layout = self.layout
406                 
407                 settings = context.tool_settings.image_paint
408                 brush = settings.brush
409
410                 col = layout.split().column()
411                 row = col.row()
412                 row.template_list(settings, "brushes", settings, "active_brush_index", rows=2)
413                         
414                 col.template_ID(settings, "brush", new="brush.add")
415
416                 row = layout.row(align=True)
417                 row.item_enumR(settings, "tool", 'DRAW')
418                 row.item_enumR(settings, "tool", 'SOFTEN')
419                 row.item_enumR(settings, "tool", 'CLONE')
420                 row.item_enumR(settings, "tool", 'SMEAR')
421                         
422                 if brush:
423                         col = layout.column()
424                         col.itemR(brush, "color", text="")
425
426                         row = col.row(align=True)
427                         row.itemR(brush, "size", slider=True)
428                         row.itemR(brush, "use_size_pressure", toggle=True, text="")
429                         
430                         row = col.row(align=True)
431                         row.itemR(brush, "strength", slider=True)
432                         row.itemR(brush, "use_strength_pressure", toggle=True, text="")
433
434                         row = col.row(align=True)
435                         row.itemR(brush, "jitter", slider=True)
436                         row.itemR(brush, "use_jitter_pressure", toggle=True, text="")
437
438                         col.itemR(brush, "blend", text="Blend")
439
440 class IMAGE_PT_paint_stroke(bpy.types.Panel):
441         __space_type__ = 'IMAGE_EDITOR'
442         __region_type__ = 'UI'
443         __label__ = "Paint Stroke"
444         __default_closed__ = True
445
446         def poll(self, context):
447                 sima = context.space_data
448                 settings = context.tool_settings.image_paint
449                 return sima.show_paint and settings.brush
450
451         def draw(self, context):
452                 layout = self.layout
453                 
454                 settings = context.tool_settings.image_paint
455                 brush = settings.brush
456
457                 layout.itemR(brush, "use_airbrush")
458                 col = layout.column()
459                 col.active = brush.use_airbrush
460                 col.itemR(brush, "rate", slider=True)
461
462                 layout.itemR(brush, "use_space")
463                 row = layout.row(align=True)
464                 row.active = brush.use_space
465                 row.itemR(brush, "spacing", text="Distance", slider=True)
466                 row.itemR(brush, "use_spacing_pressure", toggle=True, text="")  
467
468 class IMAGE_PT_paint_curve(bpy.types.Panel):
469         __space_type__ = 'IMAGE_EDITOR'
470         __region_type__ = 'UI'
471         __label__ = "Paint Curve"
472         __default_closed__ = True
473
474         def poll(self, context):
475                 sima = context.space_data
476                 settings = context.tool_settings.image_paint
477                 return sima.show_paint and settings.brush
478
479         def draw(self, context):
480                 layout = self.layout
481                 
482                 settings = context.tool_settings.image_paint
483                 brush = settings.brush
484
485                 layout.template_curve_mapping(brush, "curve")
486                 layout.item_menu_enumO("brush.curve_preset", property="shape")
487
488 bpy.types.register(IMAGE_MT_view)
489 bpy.types.register(IMAGE_MT_select)
490 bpy.types.register(IMAGE_MT_image)
491 bpy.types.register(IMAGE_MT_uvs_showhide)
492 bpy.types.register(IMAGE_MT_uvs_transform)
493 bpy.types.register(IMAGE_MT_uvs_mirror)
494 bpy.types.register(IMAGE_MT_uvs_weldalign)
495 bpy.types.register(IMAGE_MT_uvs)
496 bpy.types.register(IMAGE_HT_header)
497 bpy.types.register(IMAGE_PT_image_properties)
498 bpy.types.register(IMAGE_PT_paint)
499 bpy.types.register(IMAGE_PT_paint_stroke)
500 bpy.types.register(IMAGE_PT_paint_curve)
501 bpy.types.register(IMAGE_PT_game_properties)
502 bpy.types.register(IMAGE_PT_view_properties)
503