4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * Contributor(s): Blender Foundation, 2002-2009
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/editors/space_image/image_buttons.c
37 #include "DNA_meshdata_types.h"
38 #include "DNA_object_types.h"
39 #include "DNA_node_types.h"
40 #include "DNA_scene_types.h"
42 #include "MEM_guardedalloc.h"
44 #include "BLI_blenlib.h"
46 #include "BLI_editVert.h"
48 #include "BLI_utildefines.h"
50 #include "BKE_colortools.h"
51 #include "BKE_context.h"
52 #include "BKE_customdata.h"
53 #include "BKE_image.h"
56 #include "BKE_screen.h"
58 #include "RE_pipeline.h"
60 #include "IMB_imbuf.h"
61 #include "IMB_imbuf_types.h"
63 #include "ED_gpencil.h"
65 #include "ED_screen.h"
66 #include "ED_uvedit.h"
69 #include "RNA_access.h"
74 #include "UI_interface.h"
75 #include "UI_resources.h"
77 #include "image_intern.h"
80 #define B_IMAGECHANGED 2
81 #define B_TRANS_IMAGE 3
84 #define B_SIMAGETILE 6
86 #define B_FACESEL_PAINT_TEST 11
87 #define B_SIMA_RECORD 12
88 #define B_SIMA_PLAY 13
90 #define B_SIMANOTHING 16
91 #define B_SIMABRUSHCHANGE 17
92 #define B_SIMABRUSHBROWSE 18
93 #define B_SIMABRUSHLOCAL 19
94 #define B_SIMABRUSHDELETE 20
96 #define B_SIMABTEXBROWSE 22
97 #define B_SIMABTEXDELETE 23
99 #define B_SIMACLONEBROWSE 25
100 #define B_SIMACLONEDELETE 26
103 static void image_editvertex_buts(const bContext *C, uiBlock *block);
106 static void do_image_panel_events(bContext *C, void *UNUSED(arg), int event)
108 SpaceImage *sima= CTX_wm_space_image(C);
114 image_editvertex_buts(C, NULL);
119 WM_event_add_notifier(C, NC_IMAGE, sima->image);
122 static void image_info(Image *ima, ImBuf *ibuf, char *str)
128 if(ima==NULL) return;
130 sprintf(str, "Can not get an image");
134 if(ima->source==IMA_SRC_MOVIE) {
135 ofs= sprintf(str, "Movie");
137 ofs+= sprintf(str+ofs, "%d frs", IMB_anim_get_duration(ima->anim));
140 ofs= sprintf(str, "Image");
142 ofs+= sprintf(str+ofs, ": size %d x %d,", ibuf->x, ibuf->y);
144 if(ibuf->rect_float) {
145 if(ibuf->channels!=4) {
146 ofs+= sprintf(str+ofs, "%d float channel(s)", ibuf->channels);
148 else if(ibuf->depth==32)
149 ofs+= sprintf(str+ofs, " RGBA float");
151 ofs+= sprintf(str+ofs, " RGB float");
155 ofs+= sprintf(str+ofs, " RGBA byte");
157 ofs+= sprintf(str+ofs, " RGB byte");
159 if(ibuf->zbuf || ibuf->zbuf_float)
160 ofs+= sprintf(str+ofs, " + Z");
162 if(ima->source==IMA_SRC_SEQUENCE) {
163 char *file= BLI_last_slash(ibuf->name);
164 if(file==NULL) file= ibuf->name;
166 sprintf(str+ofs, ", %s", file);
171 /* gets active viewer user */
172 struct ImageUser *ntree_get_active_iuser(bNodeTree *ntree)
177 for(node= ntree->nodes.first; node; node= node->next)
178 if( ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))
179 if(node->flag & NODE_DO_OUTPUT)
180 return node->storage;
185 /* ************ panel stuff ************* */
187 /* this function gets the values for cursor and vertex number buttons */
188 static void image_transform_but_attr(SpaceImage *sima, int *imx, int *imy, int *step, int *digits) /*, float *xcoord, float *ycoord)*/
190 ED_space_image_size(sima, imx, imy);
192 if (sima->flag & SI_COORDFLOATS) {
203 /* is used for both read and write... */
204 static void image_editvertex_buts(const bContext *C, uiBlock *block)
206 Scene *scene= CTX_data_scene(C);
207 SpaceImage *sima= CTX_wm_space_image(C);
208 Image *ima= sima->image;
209 Object *obedit= CTX_data_edit_object(C);
210 static float ocent[2];
211 float cent[2]= {0.0, 0.0};
212 int imx= 256, imy= 256;
213 int nactive= 0, step, digits;
218 image_transform_but_attr(sima, &imx, &imy, &step, &digits);
220 em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
221 for (efa= em->faces.first; efa; efa= efa->next) {
222 tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
223 if (uvedit_face_visible(scene, ima, efa, tf)) {
225 if (uvedit_uv_selected(scene, efa, tf, 0)) {
226 cent[0]+= tf->uv[0][0];
227 cent[1]+= tf->uv[0][1];
230 if (uvedit_uv_selected(scene, efa, tf, 1)) {
231 cent[0]+= tf->uv[1][0];
232 cent[1]+= tf->uv[1][1];
235 if (uvedit_uv_selected(scene, efa, tf, 2)) {
236 cent[0]+= tf->uv[2][0];
237 cent[1]+= tf->uv[2][1];
240 if (efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) {
241 cent[0]+= tf->uv[3][0];
242 cent[1]+= tf->uv[3][1];
248 if(block) { // do the buttons
250 ocent[0]= cent[0]/nactive;
251 ocent[1]= cent[1]/nactive;
252 if (sima->flag & SI_COORDFLOATS) {
258 //uiBlockBeginAlign(block);
260 uiDefButF(block, NUM, B_TRANS_IMAGE, "Vertex X:", 10, 10, 145, 19, &ocent[0], -10*imx, 10.0*imx, step, digits, "");
261 uiDefButF(block, NUM, B_TRANS_IMAGE, "Vertex Y:", 165, 10, 145, 19, &ocent[1], -10*imy, 10.0*imy, step, digits, "");
264 uiDefButF(block, NUM, B_TRANS_IMAGE, "Median X:", 10, 10, 145, 19, &ocent[0], -10*imx, 10.0*imx, step, digits, "");
265 uiDefButF(block, NUM, B_TRANS_IMAGE, "Median Y:", 165, 10, 145, 19, &ocent[1], -10*imy, 10.0*imy, step, digits, "");
267 //uiBlockEndAlign(block);
270 else { // apply event
273 cent[0]= cent[0]/nactive;
274 cent[1]= cent[1]/nactive;
276 if (sima->flag & SI_COORDFLOATS) {
277 delta[0]= ocent[0]-cent[0];
278 delta[1]= ocent[1]-cent[1];
281 delta[0]= ocent[0]/imx - cent[0];
282 delta[1]= ocent[1]/imy - cent[1];
285 for (efa= em->faces.first; efa; efa= efa->next) {
286 tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
287 if (uvedit_face_visible(scene, ima, efa, tf)) {
288 if (uvedit_uv_selected(scene, efa, tf, 0)) {
289 tf->uv[0][0]+= delta[0];
290 tf->uv[0][1]+= delta[1];
292 if (uvedit_uv_selected(scene, efa, tf, 1)) {
293 tf->uv[1][0]+= delta[0];
294 tf->uv[1][1]+= delta[1];
296 if (uvedit_uv_selected(scene, efa, tf, 2)) {
297 tf->uv[2][0]+= delta[0];
298 tf->uv[2][1]+= delta[1];
300 if (efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) {
301 tf->uv[3][0]+= delta[0];
302 tf->uv[3][1]+= delta[1];
307 WM_event_add_notifier(C, NC_IMAGE, sima->image);
310 BKE_mesh_end_editmesh(obedit->data, em);
314 /* is used for both read and write... */
316 static int image_panel_poll(const bContext *C, PanelType *UNUSED(pt))
318 SpaceImage *sima= CTX_wm_space_image(C);
323 ibuf= ED_space_image_acquire_buffer(sima, &lock);
324 result= ibuf && ibuf->rect_float;
325 ED_space_image_release_buffer(sima, lock);
330 static void image_panel_curves(const bContext *C, Panel *pa)
332 bScreen *sc= CTX_wm_screen(C);
333 SpaceImage *sima= CTX_wm_space_image(C);
339 ibuf= ED_space_image_acquire_buffer(sima, &lock);
342 if(sima->cumap==NULL)
343 sima->cumap= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
345 /* curvemap black/white levels only works for RGBA */
346 levels= (ibuf->channels==4);
348 RNA_pointer_create(&sc->id, &RNA_SpaceImageEditor, sima, &simaptr);
349 uiTemplateCurveMapping(pa->layout, &simaptr, "curves", 'c', levels, 0);
352 ED_space_image_release_buffer(sima, lock);
356 /* 0: disable preview
357 otherwise refresh preview
359 XXX if you put this back, also check XXX in image_main_area_draw() */
361 void image_preview_event(int event)
366 G.scene->r.scemode &= ~R_COMP_CROP;
370 if(image_preview_active(curarea, NULL, NULL)) {
371 G.scene->r.scemode |= R_COMP_CROP;
375 G.scene->r.scemode &= ~R_COMP_CROP;
378 if(exec && G.scene->nodetree) {
379 /* should work when no node editor in screen..., so we execute right away */
381 ntreeCompositTagGenerators(G.scene->nodetree);
384 G.scene->nodetree->timecursor= set_timecursor;
385 G.scene->nodetree->test_break= blender_test_break;
389 ntreeCompositExecTree(G.scene->nodetree, &G.scene->r, 1); /* 1 is do_previews */
391 G.scene->nodetree->timecursor= NULL;
392 G.scene->nodetree->test_break= NULL;
394 scrarea_do_windraw(curarea);
397 WM_event_add_notifier(C, NC_IMAGE, ima_v);
402 /* nothing drawn here, we use it to store values */
403 static void preview_cb(struct ScrArea *sa, struct uiBlock *block)
405 SpaceImage *sima= sa->spacedata.first;
407 rcti *disprect= &G.scene->r.disprect;
408 int winx= (G.scene->r.size*G.scene->r.xsch)/100;
409 int winy= (G.scene->r.size*G.scene->r.ysch)/100;
412 if(G.scene->r.mode & R_BORDER) {
413 winx*= (G.scene->r.border.xmax - G.scene->r.border.xmin);
414 winy*= (G.scene->r.border.ymax - G.scene->r.border.ymin);
417 /* while dragging we need to update the rects, otherwise it doesn't end with correct one */
419 BLI_init_rctf(&dispf, 15.0f, (block->maxx - block->minx)-15.0f, 15.0f, (block->maxy - block->miny)-15.0f);
420 ui_graphics_to_window_rct(sa->win, &dispf, disprect);
422 /* correction for gla draw */
423 BLI_translate_rcti(disprect, -curarea->winrct.xmin, -curarea->winrct.ymin);
425 calc_image_view(sima, 'p');
426 // printf("winrct %d %d %d %d\n", disprect->xmin, disprect->ymin,disprect->xmax, disprect->ymax);
427 /* map to image space coordinates */
428 mval[0]= disprect->xmin; mval[1]= disprect->ymin;
429 areamouseco_to_ipoco(v2d, mval, &dispf.xmin, &dispf.ymin);
430 mval[0]= disprect->xmax; mval[1]= disprect->ymax;
431 areamouseco_to_ipoco(v2d, mval, &dispf.xmax, &dispf.ymax);
433 /* map to render coordinates */
434 disprect->xmin= dispf.xmin;
435 disprect->xmax= dispf.xmax;
436 disprect->ymin= dispf.ymin;
437 disprect->ymax= dispf.ymax;
439 CLAMP(disprect->xmin, 0, winx);
440 CLAMP(disprect->xmax, 0, winx);
441 CLAMP(disprect->ymin, 0, winy);
442 CLAMP(disprect->ymax, 0, winy);
443 // printf("drawrct %d %d %d %d\n", disprect->xmin, disprect->ymin,disprect->xmax, disprect->ymax);
447 static int is_preview_allowed(ScrArea *cur)
449 SpaceImage *sima= cur->spacedata.first;
452 /* check if another areawindow has preview set */
453 for(sa=G.curscreen->areabase.first; sa; sa= sa->next) {
454 if(sa!=cur && sa->spacetype==SPACE_IMAGE) {
455 if(image_preview_active(sa, NULL, NULL))
459 /* check image type */
460 if(sima->image==NULL || sima->image->type!=IMA_TYPE_COMPOSITE)
467 static void image_panel_preview(ScrArea *sa, short cntrl) // IMAGE_HANDLER_PREVIEW
470 SpaceImage *sima= sa->spacedata.first;
473 if(is_preview_allowed(sa)==0) {
474 rem_blockhandler(sa, IMAGE_HANDLER_PREVIEW);
475 G.scene->r.scemode &= ~R_COMP_CROP; /* quite weak */
479 block= uiBeginBlock(C, ar, "image_panel_preview", UI_EMBOSS);
480 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl);
481 uiSetPanelHandler(IMAGE_HANDLER_PREVIEW); // for close and esc
483 ofsx= -150+(sa->winx/2)/sima->blockscale;
484 ofsy= -100+(sa->winy/2)/sima->blockscale;
485 if(uiNewPanel(C, ar, block, "Preview", "Image", ofsx, ofsy, 300, 200)==0) return;
487 uiBlockSetDrawExtraFunc(block, preview_cb);
493 /* ********************* callbacks for standard image buttons *************** */
495 static char *slot_menu(void)
500 str= MEM_callocN(IMA_MAX_RENDER_SLOT*32, "menu slots");
502 strcpy(str, "Slot %t");
505 for(slot=0; slot<IMA_MAX_RENDER_SLOT; slot++)
506 a += sprintf(str+a, "|Slot %d %%x%d", slot+1, slot);
511 /* TODO, curlay should be removed? */
512 static char *layer_menu(RenderResult *rr, short *UNUSED(curlay))
515 int len= 64 + 32*BLI_countlist(&rr->layers);
517 char *str= MEM_callocN(len, "menu layers");
519 strcpy(str, "Layer %t");
524 a+= sprintf(str+a, "|Composite %%x0");
527 for(rl= rr->layers.first; rl; rl= rl->next, nr++) {
528 a+= sprintf(str+a, "|%s %%x%d", rl->name, nr);
531 /* no curlay clip here, on render (redraws) the amount of layers can be 1 fir single-layer render */
536 /* rl==NULL means composite result */
537 static char *pass_menu(RenderLayer *rl, short *curpass)
540 int len= 64 + 32*(rl?BLI_countlist(&rl->passes):1);
542 char *str= MEM_callocN(len, "menu layers");
544 strcpy(str, "Pass %t");
547 /* rendered results don't have a Combined pass */
548 if(rl==NULL || rl->rectf) {
549 a+= sprintf(str+a, "|Combined %%x0");
554 for(rpass= rl->passes.first; rpass; rpass= rpass->next, nr++)
555 a+= sprintf(str+a, "|%s %%x%d", rpass->name, nr);
563 static void set_frames_cb(bContext *C, void *ima_v, void *iuser_v)
565 Scene *scene= CTX_data_scene(C);
567 ImageUser *iuser= iuser_v;
570 iuser->frames = IMB_anim_get_duration(ima->anim);
571 BKE_image_user_calc_frame(iuser, scene->r.cfra, 0);
575 /* 5 layer button callbacks... */
576 static void image_multi_cb(bContext *C, void *rr_v, void *iuser_v)
578 ImageUser *iuser= iuser_v;
580 BKE_image_multilayer_index(rr_v, iuser);
581 WM_event_add_notifier(C, NC_IMAGE|ND_DRAW, NULL);
583 static void image_multi_inclay_cb(bContext *C, void *rr_v, void *iuser_v)
585 RenderResult *rr= rr_v;
586 ImageUser *iuser= iuser_v;
587 int tot= BLI_countlist(&rr->layers) + (rr->rectf?1:0); /* fake compo result layer */
589 if(iuser->layer<tot-1) {
591 BKE_image_multilayer_index(rr, iuser);
592 WM_event_add_notifier(C, NC_IMAGE|ND_DRAW, NULL);
595 static void image_multi_declay_cb(bContext *C, void *rr_v, void *iuser_v)
597 ImageUser *iuser= iuser_v;
601 BKE_image_multilayer_index(rr_v, iuser);
602 WM_event_add_notifier(C, NC_IMAGE|ND_DRAW, NULL);
605 static void image_multi_incpass_cb(bContext *C, void *rr_v, void *iuser_v)
607 RenderResult *rr= rr_v;
608 ImageUser *iuser= iuser_v;
609 RenderLayer *rl= BLI_findlink(&rr->layers, iuser->layer);
612 int tot= BLI_countlist(&rl->passes) + (rl->rectf?1:0); /* builtin render result has no combined pass in list */
613 if(iuser->pass<tot-1) {
615 BKE_image_multilayer_index(rr, iuser);
616 WM_event_add_notifier(C, NC_IMAGE|ND_DRAW, NULL);
620 static void image_multi_decpass_cb(bContext *C, void *rr_v, void *iuser_v)
622 ImageUser *iuser= iuser_v;
626 BKE_image_multilayer_index(rr_v, iuser);
627 WM_event_add_notifier(C, NC_IMAGE|ND_DRAW, NULL);
632 static void image_pack_cb(bContext *C, void *ima_v, void *iuser_v)
636 if(ima->source!=IMA_SRC_SEQUENCE && ima->source!=IMA_SRC_MOVIE) {
637 if (ima->packedfile) {
638 if (G.fileflags & G_AUTOPACK) {
639 if (okee("Disable AutoPack ?")) {
640 G.fileflags &= ~G_AUTOPACK;
644 if ((G.fileflags & G_AUTOPACK) == 0) {
645 unpackImage(NULL, ima, PF_ASK); /* XXX report errors */
646 ED_undo_push(C, "Unpack image");
650 ImBuf *ibuf= BKE_image_get_ibuf(ima, iuser_v);
651 if (ibuf && (ibuf->userflags & IB_BITMAPDIRTY)) {
652 // XXX error("Can't pack painted image. Save image or use Repack as PNG.");
654 ima->packedfile = newPackedFile(NULL, ima->name); /* XXX report errors */
655 ED_undo_push(C, "Pack image");
664 static void image_freecache_cb(bContext *C, void *ima_v, void *unused)
666 Scene *scene= CTX_data_scene(C);
667 BKE_image_free_anim_ibufs(ima_v, scene->r.cfra);
668 WM_event_add_notifier(C, NC_IMAGE, ima_v);
673 static void image_user_change(bContext *C, void *iuser_v, void *unused)
675 Scene *scene= CTX_data_scene(C);
676 BKE_image_user_calc_imanr(iuser_v, scene->r.cfra, 0);
680 static void uiblock_layer_pass_buttons(uiLayout *layout, RenderResult *rr, ImageUser *iuser, int w, short *render_slot)
682 uiBlock *block= uiLayoutGetBlock(layout);
684 RenderLayer *rl= NULL;
685 int wmenu1, wmenu2, wmenu3;
688 uiLayoutRow(layout, 1);
690 /* layer menu is 1/3 larger than pass */
698 but= uiDefButS(block, MENU, 0, strp, 0, 0, wmenu1, 20, render_slot, 0,0,0,0, "Select Slot");
699 uiButSetFunc(but, image_multi_cb, rr, iuser);
704 strp= layer_menu(rr, &iuser->layer);
705 but= uiDefButS(block, MENU, 0, strp, 0, 0, wmenu2, 20, &iuser->layer, 0,0,0,0, "Select Layer");
706 uiButSetFunc(but, image_multi_cb, rr, iuser);
709 rl= BLI_findlink(&rr->layers, iuser->layer - (rr->rectf?1:0)); /* fake compo layer, return NULL is meant to be */
710 strp= pass_menu(rl, &iuser->pass);
711 but= uiDefButS(block, MENU, 0, strp, 0, 0, wmenu3, 20, &iuser->pass, 0,0,0,0, "Select Pass");
712 uiButSetFunc(but, image_multi_cb, rr, iuser);
717 static void uiblock_layer_pass_arrow_buttons(uiLayout *layout, RenderResult *rr, ImageUser *iuser, short *render_slot)
719 uiBlock *block= uiLayoutGetBlock(layout);
723 row= uiLayoutRow(layout, 1);
725 if(rr==NULL || iuser==NULL)
727 if(rr->layers.first==NULL) {
728 uiItemL(row, "No Layers in Render Result.", ICON_NONE);
732 /* decrease, increase arrows */
733 but= uiDefIconBut(block, BUT, 0, ICON_TRIA_LEFT, 0,0,17,20, NULL, 0, 0, 0, 0, "Previous Layer");
734 uiButSetFunc(but, image_multi_declay_cb, rr, iuser);
735 but= uiDefIconBut(block, BUT, 0, ICON_TRIA_RIGHT, 0,0,18,20, NULL, 0, 0, 0, 0, "Next Layer");
736 uiButSetFunc(but, image_multi_inclay_cb, rr, iuser);
738 uiblock_layer_pass_buttons(row, rr, iuser, 230, render_slot);
740 /* decrease, increase arrows */
741 but= uiDefIconBut(block, BUT, 0, ICON_TRIA_LEFT, 0,0,17,20, NULL, 0, 0, 0, 0, "Previous Pass");
742 uiButSetFunc(but, image_multi_decpass_cb, rr, iuser);
743 but= uiDefIconBut(block, BUT, 0, ICON_TRIA_RIGHT, 0,0,18,20, NULL, 0, 0, 0, 0, "Next Pass");
744 uiButSetFunc(but, image_multi_incpass_cb, rr, iuser);
746 uiBlockEndAlign(block);
750 // static int packdummy=0;
752 typedef struct RNAUpdateCb {
758 static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
760 RNAUpdateCb *cb= (RNAUpdateCb*)arg_cb;
762 /* ideally this would be done by RNA itself, but there we have
763 no image user available, so we just update this flag here */
766 /* we call update here on the pointer property, this way the
767 owner of the image pointer can still define it's own update
769 RNA_property_update(C, &cb->ptr, cb->prop);
772 void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *userptr, int compact)
780 Scene *scene= CTX_data_scene(C);
781 uiLayout *row, *split, *col;
790 prop= RNA_struct_find_property(ptr, propname);
792 printf("uiTemplateImage: property not found: %s.%s\n", RNA_struct_identifier(ptr->type), propname);
796 if(RNA_property_type(prop) != PROP_POINTER) {
797 printf("uiTemplateImage: expected pointer property for %s.%s\n", RNA_struct_identifier(ptr->type), propname);
801 block= uiLayoutGetBlock(layout);
804 imaptr= RNA_property_pointer_get(ptr, prop);
806 iuser= userptr->data;
808 cb= MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
813 uiLayoutSetContextPointer(layout, "edit_image", &imaptr);
816 uiTemplateID(layout, C, ptr, propname, "IMAGE_OT_new", "IMAGE_OT_open", NULL);
818 // XXX missing: reload, pack
821 uiBlockSetNFunc(block, rna_update_cb, MEM_dupallocN(cb), NULL);
823 if(ima->source == IMA_SRC_VIEWER) {
824 ibuf= BKE_image_acquire_ibuf(ima, iuser, &lock);
825 image_info(ima, ibuf, str);
826 BKE_image_release_ibuf(ima, lock);
828 uiItemL(layout, ima->id.name+2, ICON_NONE);
829 uiItemL(layout, str, ICON_NONE);
831 if(ima->type==IMA_TYPE_COMPOSITE) {
832 // XXX not working yet
834 iuser= ntree_get_active_iuser(scene->nodetree);
836 uiBlockBeginAlign(block);
837 uiDefIconTextBut(block, BUT, B_SIMA_RECORD, ICON_REC, "Record", 10,120,100,20, 0, 0, 0, 0, 0, "");
838 uiDefIconTextBut(block, BUT, B_SIMA_PLAY, ICON_PLAY, "Play", 110,120,100,20, 0, 0, 0, 0, 0, "");
839 but= uiDefBut(block, BUT, B_NOP, "Free Cache", 210,120,100,20, 0, 0, 0, 0, 0, "");
840 uiButSetFunc(but, image_freecache_cb, ima, NULL);
843 sprintf(str, "(%d) Frames:", iuser->framenr);
844 else strcpy(str, "Frames:");
845 uiBlockBeginAlign(block);
846 uiDefButI(block, NUM, imagechanged, str, 10, 90,150, 20, &iuser->frames, 0.0, MAXFRAMEF, 0, 0, "Sets the number of images of a movie to use");
847 uiDefButI(block, NUM, imagechanged, "StartFr:", 160,90,150,20, &iuser->sfra, 1.0, MAXFRAMEF, 0, 0, "Sets the global starting frame of the movie");
851 else if(ima->type==IMA_TYPE_R_RESULT) {
852 /* browse layer/passes */
853 Render *re= RE_GetRender(scene->id.name);
854 RenderResult *rr= RE_AcquireResultRead(re);
855 uiblock_layer_pass_arrow_buttons(layout, rr, iuser, &ima->render_slot);
856 RE_ReleaseResult(re);
860 row= uiLayoutRow(layout, 0);
861 uiItemR(row, &imaptr, "source", 0, NULL, ICON_NONE);
863 if(ima->source != IMA_SRC_GENERATED) {
864 row= uiLayoutRow(layout, 1);
865 split = uiLayoutSplit(row, 0.0, 0);
867 uiItemO(split, "", ICON_PACKAGE, "image.unpack");
869 uiItemO(split, "", ICON_UGLYPACKAGE, "image.pack");
871 split = uiLayoutSplit(row, 0.0, 0);
872 row= uiLayoutRow(split, 1);
873 uiLayoutSetEnabled(row, ima->packedfile==NULL);
875 uiItemR(row, &imaptr, "filepath", 0, "", ICON_NONE);
876 uiItemO(row, "", ICON_FILE_REFRESH, "image.reload");
879 // XXX what was this for?
881 /* check for re-render, only buttons */
882 if(imagechanged==B_IMAGECHANGED) {
883 if(iuser->flag & IMA_ANIM_REFRESHED) {
884 iuser->flag &= ~IMA_ANIM_REFRESHED;
885 WM_event_add_notifier(C, NC_IMAGE, ima);
891 if(ima->type==IMA_TYPE_MULTILAYER && ima->rr) {
892 uiblock_layer_pass_arrow_buttons(layout, ima->rr, iuser, NULL);
894 else if(ima->source != IMA_SRC_GENERATED) {
896 ibuf= BKE_image_acquire_ibuf(ima, iuser, &lock);
897 image_info(ima, ibuf, str);
898 BKE_image_release_ibuf(ima, lock);
899 uiItemL(layout, str, ICON_NONE);
903 if(ima->source != IMA_SRC_GENERATED) {
904 if(compact == 0) { /* background image view doesnt need these */
907 split= uiLayoutSplit(layout, 0, 0);
909 col= uiLayoutColumn(split, 0);
910 uiItemR(col, &imaptr, "use_fields", 0, NULL, ICON_NONE);
911 row= uiLayoutRow(col, 0);
912 uiItemR(row, &imaptr, "field_order", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
913 uiLayoutSetActive(row, RNA_boolean_get(&imaptr, "use_fields"));
915 col= uiLayoutColumn(split, 0);
916 uiItemR(col, &imaptr, "use_premultiply", 0, NULL, ICON_NONE);
920 if(ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
923 split= uiLayoutSplit(layout, 0, 0);
925 col= uiLayoutColumn(split, 0);
927 sprintf(str, "(%d) Frames", iuser->framenr);
928 row= uiLayoutRow(col, 1);
929 uiItemR(col, userptr, "frame_duration", 0, str, ICON_NONE);
931 block= uiLayoutGetBlock(row);
932 but= uiDefBut(block, BUT, 0, "Match Movie Length", 0, 0, UI_UNIT_X*2, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Set the number of frames to match the movie or sequence.");
933 uiButSetFunc(but, set_frames_cb, ima, iuser);
936 uiItemR(col, userptr, "frame_start", 0, "Start", ICON_NONE);
937 uiItemR(col, userptr, "frame_offset", 0, NULL, ICON_NONE);
939 col= uiLayoutColumn(split, 0);
940 uiItemR(col, userptr, "fields_per_frame", 0, "Fields", ICON_NONE);
941 uiItemR(col, userptr, "use_auto_refresh", 0, NULL, ICON_NONE);
942 uiItemR(col, userptr, "use_cyclic", 0, NULL, ICON_NONE);
944 else if(ima->source==IMA_SRC_GENERATED) {
945 split= uiLayoutSplit(layout, 0, 0);
947 col= uiLayoutColumn(split, 1);
948 uiItemR(col, &imaptr, "generated_width", 0, "X", ICON_NONE);
949 uiItemR(col, &imaptr, "generated_height", 0, "Y", ICON_NONE);
951 col= uiLayoutColumn(split, 0);
952 uiItemR(col, &imaptr, "generated_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
957 uiBlockSetNFunc(block, NULL, NULL, NULL);
963 void uiTemplateImageLayers(uiLayout *layout, bContext *C, Image *ima, ImageUser *iuser)
965 Scene *scene= CTX_data_scene(C);
968 /* render layers and passes */
970 rr= BKE_image_acquire_renderresult(scene, ima);
971 uiblock_layer_pass_buttons(layout, rr, iuser, 160, (ima->type==IMA_TYPE_R_RESULT)? &ima->render_slot: NULL);
972 BKE_image_release_renderresult(scene, ima);
976 static int image_panel_uv_poll(const bContext *C, PanelType *UNUSED(pt))
978 Object *obedit= CTX_data_edit_object(C);
979 return ED_uvedit_test(obedit);
982 static void image_panel_uv(const bContext *C, Panel *pa)
986 block= uiLayoutAbsoluteBlock(pa->layout);
987 uiBlockSetHandleFunc(block, do_image_panel_events, NULL);
989 image_editvertex_buts(C, block);
992 void image_buttons_register(ARegionType *art)
996 /* editvertex_buts not working atm */
998 pt= MEM_callocN(sizeof(PanelType), "spacetype image panel uv");
999 strcpy(pt->idname, "IMAGE_PT_uv");
1000 strcpy(pt->label, "UV");
1001 pt->draw= image_panel_uv;
1002 pt->poll= image_panel_uv_poll;
1003 BLI_addtail(&art->paneltypes, pt);
1006 pt= MEM_callocN(sizeof(PanelType), "spacetype image panel curves");
1007 strcpy(pt->idname, "IMAGE_PT_curves");
1008 strcpy(pt->label, "Curves");
1009 pt->draw= image_panel_curves;
1010 pt->poll= image_panel_poll;
1011 pt->flag |= PNL_DEFAULT_CLOSED;
1012 BLI_addtail(&art->paneltypes, pt);
1014 pt= MEM_callocN(sizeof(PanelType), "spacetype image panel gpencil");
1015 strcpy(pt->idname, "IMAGE_PT_gpencil");
1016 strcpy(pt->label, "Grease Pencil");
1017 pt->draw= gpencil_panel_standard;
1018 BLI_addtail(&art->paneltypes, pt);
1021 static int image_properties(bContext *C, wmOperator *UNUSED(op))
1023 ScrArea *sa= CTX_wm_area(C);
1024 ARegion *ar= image_has_buttons_region(sa);
1027 ED_region_toggle_hidden(C, ar);
1029 return OPERATOR_FINISHED;
1032 void IMAGE_OT_properties(wmOperatorType *ot)
1034 ot->name= "Properties";
1035 ot->idname= "IMAGE_OT_properties";
1036 ot->description= "Toggle display properties panel";
1038 ot->exec= image_properties;
1039 ot->poll= ED_operator_image_active;
1045 static int image_scopes(bContext *C, wmOperator *UNUSED(op))
1047 ScrArea *sa= CTX_wm_area(C);
1048 ARegion *ar= image_has_scope_region(sa);
1051 ED_region_toggle_hidden(C, ar);
1053 return OPERATOR_FINISHED;
1056 void IMAGE_OT_scopes(wmOperatorType *ot)
1059 ot->idname= "IMAGE_OT_scopes";
1060 ot->description= "Toggle display scopes panel";
1062 ot->exec= image_scopes;
1063 ot->poll= ED_operator_image_active;