RNA:
[blender.git] / source / blender / editors / space_image / space_image.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_image_types.h"
33 #include "DNA_mesh_types.h"
34 #include "DNA_meshdata_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_space_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_screen_types.h"
39
40 #include "MEM_guardedalloc.h"
41
42 #include "BLI_blenlib.h"
43 #include "BLI_arithb.h"
44 #include "BLI_editVert.h"
45 #include "BLI_rand.h"
46
47 #include "BKE_colortools.h"
48 #include "BKE_context.h"
49 #include "BKE_image.h"
50 #include "BKE_screen.h"
51 #include "BKE_utildefines.h"
52
53 #include "IMB_imbuf.h"
54 #include "IMB_imbuf_types.h"
55
56 #include "ED_image.h"
57 #include "ED_mesh.h"
58 #include "ED_space_api.h"
59 #include "ED_screen.h"
60 #include "ED_uvedit.h"
61
62 #include "BIF_gl.h"
63 #include "BIF_glutil.h"
64
65 #include "RNA_access.h"
66
67 #include "WM_api.h"
68 #include "WM_types.h"
69
70 #include "UI_interface.h"
71 #include "UI_resources.h"
72 #include "UI_view2d.h"
73
74 #include "image_intern.h"
75
76 /* ******************** default callbacks for image space ***************** */
77
78 static SpaceLink *image_new(const bContext *C)
79 {
80         ARegion *ar;
81         SpaceImage *simage;
82         
83         simage= MEM_callocN(sizeof(SpaceImage), "initimage");
84         simage->spacetype= SPACE_IMAGE;
85         simage->zoom= 1;
86         
87         simage->iuser.ok= 1;
88         simage->iuser.fie_ima= 2;
89         simage->iuser.frames= 100;
90         
91         /* header */
92         ar= MEM_callocN(sizeof(ARegion), "header for image");
93         
94         BLI_addtail(&simage->regionbase, ar);
95         ar->regiontype= RGN_TYPE_HEADER;
96         ar->alignment= RGN_ALIGN_BOTTOM;
97         
98         /* main area */
99         ar= MEM_callocN(sizeof(ARegion), "main area for image");
100         
101         BLI_addtail(&simage->regionbase, ar);
102         ar->regiontype= RGN_TYPE_WINDOW;
103         
104         return (SpaceLink *)simage;
105 }
106
107 /* not spacelink itself */
108 static void image_free(SpaceLink *sl)
109 {       
110         SpaceImage *simage= (SpaceImage*) sl;
111         
112         if(simage->cumap)
113                 curvemapping_free(simage->cumap);
114 //      if(simage->gpd)
115 // XXX          free_gpencil_data(simage->gpd);
116         
117 }
118
119
120 /* spacetype; init callback */
121 static void image_init(struct wmWindowManager *wm, ScrArea *sa)
122 {
123
124 }
125
126 static SpaceLink *image_duplicate(SpaceLink *sl)
127 {
128         SpaceImage *simagen= MEM_dupallocN(sl);
129         
130         /* clear or remove stuff from old */
131         if(simagen->cumap)
132                 simagen->cumap= curvemapping_copy(simagen->cumap);
133         
134         return (SpaceLink *)simagen;
135 }
136
137 void image_operatortypes(void)
138 {
139         WM_operatortype_append(IMAGE_OT_view_all);
140         WM_operatortype_append(IMAGE_OT_view_pan);
141         WM_operatortype_append(IMAGE_OT_view_selected);
142         WM_operatortype_append(IMAGE_OT_view_zoom);
143         WM_operatortype_append(IMAGE_OT_view_zoom_in);
144         WM_operatortype_append(IMAGE_OT_view_zoom_out);
145         WM_operatortype_append(IMAGE_OT_view_zoom_ratio);
146
147         WM_operatortype_append(IMAGE_OT_new);
148         WM_operatortype_append(IMAGE_OT_open);
149         WM_operatortype_append(IMAGE_OT_replace);
150         WM_operatortype_append(IMAGE_OT_reload);
151         WM_operatortype_append(IMAGE_OT_save);
152         WM_operatortype_append(IMAGE_OT_save_as);
153         WM_operatortype_append(IMAGE_OT_save_sequence);
154         WM_operatortype_append(IMAGE_OT_pack);
155         WM_operatortype_append(IMAGE_OT_unpack);
156
157         WM_operatortype_append(IMAGE_OT_sample);
158         WM_operatortype_append(IMAGE_OT_set_curves_point);
159
160         WM_operatortype_append(IMAGE_OT_record_composite);
161
162         WM_operatortype_append(IMAGE_OT_toolbox);
163 }
164
165 void image_keymap(struct wmWindowManager *wm)
166 {
167         ListBase *keymap= WM_keymap_listbase(wm, "Image", SPACE_IMAGE, 0);
168         
169         WM_keymap_add_item(keymap, "IMAGE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
170         WM_keymap_add_item(keymap, "IMAGE_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
171         WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
172
173         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
174         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0);
175         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
176         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_out", PADMINUS, KM_PRESS, 0, 0);
177         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
178
179         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f);
180         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f);
181         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f);
182         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
183         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f);
184         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f);
185         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
186
187         WM_keymap_add_item(keymap, "IMAGE_OT_new", NKEY, KM_PRESS, KM_ALT, 0);
188         WM_keymap_add_item(keymap, "IMAGE_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
189         WM_keymap_add_item(keymap, "IMAGE_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
190         WM_keymap_add_item(keymap, "IMAGE_OT_save", SKEY, KM_PRESS, KM_ALT, 0);
191
192         WM_keymap_add_item(keymap, "IMAGE_OT_sample", ACTIONMOUSE, KM_PRESS, 0, 0);
193         RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_set_curves_point", ACTIONMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "point", 0);
194         RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_set_curves_point", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "point", 1);
195
196         WM_keymap_add_item(keymap, "IMAGE_OT_toolbox", SPACEKEY, KM_PRESS, 0, 0);
197 }
198
199 static void image_refresh(const bContext *C, ScrArea *sa)
200 {
201         SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
202         Object *obedit= CTX_data_edit_object(C);
203         Image *ima;
204
205         ima= ED_space_image(sima);
206
207         /* check if we have to set the image from the editmesh */
208         if(ima && (ima->source==IMA_SRC_VIEWER || sima->pin));
209         else if(obedit && obedit->type == OB_MESH) {
210                 Mesh *me= (Mesh*)obedit->data;
211                 EditMesh *em= me->edit_mesh;
212                 MTFace *tf;
213                 
214                 if(em && EM_texFaceCheck(em)) {
215                         sima->image= ima= NULL;
216                         
217                         tf = EM_get_active_mtface(em, NULL, NULL, 1); /* partially selected face is ok */
218                         
219                         if(tf && (tf->mode & TF_TEX)) {
220                                 /* don't need to check for pin here, see above */
221                                 sima->image= ima= tf->tpage;
222                                 
223                                 if(sima->flag & SI_EDITTILE);
224                                 else sima->curtile= tf->tile;
225                                 
226                                 if(ima) {
227                                         if(tf->mode & TF_TILES)
228                                                 ima->tpageflag |= IMA_TILES;
229                                         else
230                                                 ima->tpageflag &= ~IMA_TILES;
231                                 }
232                         }
233                 }
234         }
235 }
236
237 static void image_listener(ScrArea *sa, wmNotifier *wmn)
238 {
239         SpaceImage *sima= sa->spacedata.first;
240
241         /* context changes */
242         switch(wmn->category) {
243                 case NC_SCENE:
244                         switch(wmn->data) {
245                                 case ND_MODE:
246                                 case ND_RENDER_RESULT:
247                                 case ND_COMPO_RESULT:
248                                         ED_area_tag_refresh(sa);
249                                         ED_area_tag_redraw(sa);
250                                         break;
251                         }
252                         break;
253                 case NC_IMAGE:  
254                         if(!wmn->reference || wmn->reference == sima->image)
255                                 ED_area_tag_redraw(sa);
256                         break;
257         }
258 }
259
260 static int image_context(const bContext *C, bContextDataMember member, bContextDataResult *result)
261 {
262         SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
263
264         if(member == CTX_DATA_EDIT_IMAGE) {
265                 CTX_data_pointer_set(result, ED_space_image(sima));
266                 return 1;
267         }
268         else if(member == CTX_DATA_EDIT_IMAGE_BUFFER) {
269                 CTX_data_pointer_set(result, ED_space_image_buffer(sima));
270                 return 1;
271         }
272
273         return 0;
274 }
275
276 /************************** main region ***************************/
277
278 /* sets up the fields of the View2D from zoom and offset */
279 static void image_main_area_set_view2d(SpaceImage *sima, ARegion *ar, Scene *scene)
280 {
281         Image *ima= ED_space_image(sima);
282         float x1, y1, w, h;
283         int width, height, winx, winy;
284         
285 #if 0
286         if(image_preview_active(curarea, &width, &height));
287 #endif
288         if(sima->image) {
289                 ImBuf *ibuf= ED_space_image_buffer(sima);
290                 float xuser_asp, yuser_asp;
291                 
292                 ED_image_aspect(sima->image, &xuser_asp, &yuser_asp);
293                 if(ibuf) {
294                         width= ibuf->x*xuser_asp;
295                         height= ibuf->y*yuser_asp;
296                 }
297                 else if(sima->image->type==IMA_TYPE_R_RESULT) {
298                         /* not very important, just nice */
299                         width= (scene->r.xsch*scene->r.size)/100;
300                         height= (scene->r.ysch*scene->r.size)/100;
301                 }
302                 else
303                         ED_space_image_size(sima, &width, &height);
304         }
305         else
306                 ED_space_image_size(sima, &width, &height);
307
308         w= width;
309         h= height;
310         
311         if(ima)
312                 h *= ima->aspy/ima->aspx;
313
314         winx= ar->winrct.xmax - ar->winrct.xmin + 1;
315         winy= ar->winrct.ymax - ar->winrct.ymin + 1;
316                 
317         ar->v2d.tot.xmin= 0;
318         ar->v2d.tot.ymin= 0;
319         ar->v2d.tot.xmax= w;
320         ar->v2d.tot.ymax= h;
321         
322         ar->v2d.mask.xmin= ar->v2d.mask.ymin= 0;
323         ar->v2d.mask.xmax= winx;
324         ar->v2d.mask.ymax= winy;
325
326         /* which part of the image space do we see? */
327         /* same calculation as in lrectwrite: area left and down*/
328         x1= ar->winrct.xmin+(winx-sima->zoom*w)/2;
329         y1= ar->winrct.ymin+(winy-sima->zoom*h)/2;
330
331         x1-= sima->zoom*sima->xof;
332         y1-= sima->zoom*sima->yof;
333         
334         /* relative display right */
335         ar->v2d.cur.xmin= ((ar->winrct.xmin - (float)x1)/sima->zoom);
336         ar->v2d.cur.xmax= ar->v2d.cur.xmin + ((float)winx/sima->zoom);
337         
338         /* relative display left */
339         ar->v2d.cur.ymin= ((ar->winrct.ymin-(float)y1)/sima->zoom);
340         ar->v2d.cur.ymax= ar->v2d.cur.ymin + ((float)winy/sima->zoom);
341         
342         /* normalize 0.0..1.0 */
343         ar->v2d.cur.xmin /= w;
344         ar->v2d.cur.xmax /= w;
345         ar->v2d.cur.ymin /= h;
346         ar->v2d.cur.ymax /= h;
347 }
348
349 /* add handlers, stuff you only do once or on area/region changes */
350 static void image_main_area_init(wmWindowManager *wm, ARegion *ar)
351 {
352         ListBase *keymap;
353         
354         // image space manages own v2d
355         // UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
356         
357         /* own keymap */
358         keymap= WM_keymap_listbase(wm, "Image", SPACE_IMAGE, 0);
359         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
360 }
361
362 static void image_main_area_draw(const bContext *C, ARegion *ar)
363 {
364         /* draw entirely, view changes should be handled here */
365         SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
366         Object *obedit= CTX_data_edit_object(C);
367         Scene *scene= CTX_data_scene(C);
368         View2D *v2d= &ar->v2d;
369         //View2DScrollers *scrollers;
370         float col[3];
371         
372         /* clear and setup matrix */
373         UI_GetThemeColor3fv(TH_BACK, col);
374         glClearColor(col[0], col[1], col[2], 0.0);
375         glClear(GL_COLOR_BUFFER_BIT);
376         
377         /* we set view2d from own zoom and offset each time */
378         image_main_area_set_view2d(sima, ar, scene);
379                 
380         /* we draw image in pixelspace */
381         draw_image_main(sima, ar, scene);
382
383         /* and uvs in 0.0-1.0 space */
384         UI_view2d_view_ortho(C, v2d);
385         draw_uvedit_main(sima, ar, scene, obedit);
386         ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST);
387         UI_view2d_view_restore(C);
388         
389         /* scrollers? */
390         /*scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
391         UI_view2d_scrollers_draw(C, v2d, scrollers);
392         UI_view2d_scrollers_free(scrollers);*/
393 }
394
395 static void image_modal_keymaps(wmWindowManager *wm, ARegion *ar, int stype)
396 {
397         ListBase *keymap;
398         
399         keymap= WM_keymap_listbase(wm, "UVEdit", 0, 0);
400
401         if(stype==NS_EDITMODE_MESH)
402                 WM_event_add_keymap_handler(&ar->handlers, keymap);
403         else
404                 WM_event_remove_keymap_handler(&ar->handlers, keymap);
405 }
406
407 static void image_main_area_listener(ARegion *ar, wmNotifier *wmn)
408 {
409         /* context changes */
410         switch(wmn->category) {
411                 case NC_SCENE:
412                         switch(wmn->data) {
413                                 case ND_MODE:
414                                         image_modal_keymaps(wmn->wm, ar, wmn->subtype);
415                                         break;
416                         }
417                         break;
418                 case NC_OBJECT:
419                         switch(wmn->data) {
420                                 case ND_GEOM_SELECT:
421                                 case ND_GEOM_DATA:
422                                         ED_region_tag_redraw(ar);
423                                         break;
424                         }
425         }
426 }
427
428 /************************* header region **************************/
429
430 /* add handlers, stuff you only do once or on area/region changes */
431 static void image_header_area_init(wmWindowManager *wm, ARegion *ar)
432 {
433         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
434 }
435
436 static void image_header_area_draw(const bContext *C, ARegion *ar)
437 {
438         float col[3];
439         
440         /* clear */
441         if(ED_screen_area_active(C))
442                 UI_GetThemeColor3fv(TH_HEADER, col);
443         else
444                 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
445         
446         glClearColor(col[0], col[1], col[2], 0.0);
447         glClear(GL_COLOR_BUFFER_BIT);
448         
449         /* set view2d view matrix for scrolling (without scrollers) */
450         UI_view2d_view_ortho(C, &ar->v2d);
451         
452         image_header_buttons(C, ar);
453         
454         /* restore view matrix? */
455         UI_view2d_view_restore(C);
456 }
457
458 /**************************** spacetype *****************************/
459
460 /* only called once, from space/spacetypes.c */
461 void ED_spacetype_image(void)
462 {
463         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype image");
464         ARegionType *art;
465         
466         st->spaceid= SPACE_IMAGE;
467         
468         st->new= image_new;
469         st->free= image_free;
470         st->init= image_init;
471         st->duplicate= image_duplicate;
472         st->operatortypes= image_operatortypes;
473         st->keymap= image_keymap;
474         st->refresh= image_refresh;
475         st->listener= image_listener;
476         st->context= image_context;
477         
478         /* regions: main window */
479         art= MEM_callocN(sizeof(ARegionType), "spacetype image region");
480         art->regionid = RGN_TYPE_WINDOW;
481         art->keymapflag= ED_KEYMAP_FRAMES;
482         art->init= image_main_area_init;
483         art->draw= image_main_area_draw;
484         art->listener= image_main_area_listener;
485         art->keymapflag= 0;
486
487         BLI_addhead(&st->regiontypes, art);
488         
489         /* regions: header */
490         art= MEM_callocN(sizeof(ARegionType), "spacetype image region");
491         art->regionid = RGN_TYPE_HEADER;
492         art->minsizey= HEADERY;
493         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES;
494         
495         art->init= image_header_area_init;
496         art->draw= image_header_area_draw;
497         
498         BLI_addhead(&st->regiontypes, art);
499         
500         
501         BKE_spacetype_register(st);
502 }
503
504 /**************************** common state *****************************/
505
506 Image *ED_space_image(SpaceImage *sima)
507 {
508         return sima->image;
509 }
510
511 /* called to assign images to UV faces */
512 void ED_space_image_set(bContext *C, SpaceImage *sima, Scene *scene, Object *obedit, Image *ima)
513 {
514         ED_uvedit_assign_image(scene, obedit, ima, sima->image);
515
516         /* change the space ima after because uvedit_face_visible uses the space ima
517          * to check if the face is displayed in UV-localview */
518         sima->image= ima;
519
520         if(ima == NULL || ima->type==IMA_TYPE_R_RESULT || ima->type==IMA_TYPE_COMPOSITE)
521                 sima->flag &= ~SI_DRAWTOOL;
522
523         if(sima->image)
524                 BKE_image_signal(sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE);
525
526         if(sima->image && sima->image->id.us==0)
527                 sima->image->id.us= 1;
528
529         if(obedit)
530                 WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, obedit);
531
532         ED_area_tag_redraw(CTX_wm_area(C));
533 }
534
535 ImBuf *ED_space_image_buffer(SpaceImage *sima)
536 {
537         ImBuf *ibuf;
538
539         if(sima->image) {
540 #if 0
541                 if(sima->image->type==IMA_TYPE_R_RESULT && BIF_show_render_spare())
542                         return BIF_render_spare_imbuf();
543                 else
544 #endif
545                         ibuf= BKE_image_get_ibuf(sima->image, &sima->iuser);
546
547                 if(ibuf && (ibuf->rect || ibuf->rect_float))
548                         return ibuf;
549         }
550
551         return NULL;
552 }
553
554 void ED_image_size(Image *ima, int *width, int *height)
555 {
556         ImBuf *ibuf;
557
558         ibuf= (ima)? BKE_image_get_ibuf(ima, NULL): NULL;
559
560         if(ibuf && ibuf->x > 0 && ibuf->y > 0) {
561                 *width= ibuf->x;
562                 *height= ibuf->y;
563         }
564         else {
565                 *width= 256;
566                 *height= 256;
567         }
568 }
569
570 void ED_space_image_size(SpaceImage *sima, int *width, int *height)
571 {
572         ImBuf *ibuf;
573
574         ibuf= ED_space_image_buffer(sima);
575
576         if(ibuf && ibuf->x > 0 && ibuf->y > 0) {
577                 *width= ibuf->x;
578                 *height= ibuf->y;
579         }
580         /* I know a bit weak... but preview uses not actual image size */
581         // XXX else if(image_preview_active(sima, width, height));
582         else {
583                 *width= 256;
584                 *height= 256;
585         }
586 }
587
588 void ED_image_aspect(Image *ima, float *aspx, float *aspy)
589 {
590         *aspx= *aspy= 1.0;
591
592         if((ima == NULL) || (ima->type == IMA_TYPE_R_RESULT) || (ima->type == IMA_TYPE_COMPOSITE) ||
593            (ima->tpageflag & IMA_TILES) || (ima->aspx==0.0 || ima->aspy==0.0))
594                 return;
595
596         /* x is always 1 */
597         *aspy = ima->aspy/ima->aspx;
598 }
599
600 void ED_space_image_aspect(SpaceImage *sima, float *aspx, float *aspy)
601 {
602         ED_image_aspect(ED_space_image(sima), aspx, aspy);
603 }
604
605 void ED_space_image_zoom(SpaceImage *sima, ARegion *ar, float *zoomx, float *zoomy)
606 {
607         int width, height;
608
609         ED_space_image_size(sima, &width, &height);
610
611         *zoomx= (float)(ar->winrct.xmax - ar->winrct.xmin)/(float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin)*width);
612         *zoomy= (float)(ar->winrct.ymax - ar->winrct.ymin)/(float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin)*height);
613 }
614
615 void ED_space_image_uv_aspect(SpaceImage *sima, float *aspx, float *aspy)
616 {
617         int w, h;
618
619         ED_space_image_aspect(sima, aspx, aspy);
620         ED_space_image_size(sima, &w, &h);
621
622         *aspx *= (float)w/256.0f;
623         *aspy *= (float)h/256.0f;
624 }
625
626 void ED_image_uv_aspect(Image *ima, float *aspx, float *aspy)
627 {
628         int w, h;
629
630         ED_image_aspect(ima, aspx, aspy);
631         ED_image_size(ima, &w, &h);
632
633         *aspx *= (float)w;
634         *aspy *= (float)h;
635 }
636
637 int ED_space_image_show_render(SpaceImage *sima)
638 {
639         return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE));
640 }
641
642 int ED_space_image_show_paint(SpaceImage *sima)
643 {
644         if(ED_space_image_show_render(sima))
645                 return 0;
646
647         return (sima->flag & SI_DRAWTOOL);
648 }
649
650 int ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit)
651 {
652         if(ED_space_image_show_render(sima))
653                 return 0;
654         if(ED_space_image_show_paint(sima))
655                 return 0;
656
657         if(obedit && obedit->type == OB_MESH)
658                 return EM_texFaceCheck(((Mesh*)obedit->data)->edit_mesh);
659
660         return 0;
661 }
662
663 int ED_space_image_show_uvshadow(SpaceImage *sima, Object *obedit)
664 {
665         if(ED_space_image_show_render(sima))
666                 return 0;
667
668         if(ED_space_image_show_paint(sima))
669                 if(obedit && obedit->type == OB_MESH)
670                         return EM_texFaceCheck(((Mesh*)obedit->data)->edit_mesh);
671
672         return 0;
673 }
674