diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/include/ED_uvedit.h | 12 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_buttons.c | 152 | ||||
-rw-r--r-- | source/blender/editors/space_image/space_image.c | 1 | ||||
-rw-r--r-- | source/blender/editors/uvedit/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_buttons.c | 233 |
5 files changed, 243 insertions, 156 deletions
diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h index b975be54f5f..f6106e62533 100644 --- a/source/blender/editors/include/ED_uvedit.h +++ b/source/blender/editors/include/ED_uvedit.h @@ -32,12 +32,13 @@ #ifndef ED_UVEDIT_H #define ED_UVEDIT_H -struct bContext; -struct Scene; -struct Object; -struct MTFace; +struct ARegionType; struct EditFace; struct Image; +struct MTFace; +struct Object; +struct Scene; +struct bContext; struct wmKeyConfig; /* uvedit_ops.c */ @@ -77,5 +78,8 @@ void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short sel) /* uvedit_draw.c */ void draw_uvedit_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene, struct Object *obedit); +/* uvedit_buttons.c */ +void ED_uvedit_buttons_register(struct ARegionType *art); + #endif /* ED_UVEDIT_H */ diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index fc20e2a744e..0fd7ac3e754 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -63,8 +63,6 @@ #include "ED_gpencil.h" #include "ED_image.h" #include "ED_screen.h" -#include "ED_uvedit.h" - #include "RNA_access.h" @@ -78,7 +76,6 @@ #define B_REDR 1 #define B_IMAGECHANGED 2 -#define B_TRANS_IMAGE 3 #define B_NOP 0 #define B_TWINANIM 5 #define B_SIMAGETILE 6 @@ -100,8 +97,6 @@ #define B_SIMACLONEDELETE 26 /* proto */ -static void image_editvertex_buts(const bContext *C, uiBlock *block); - static void do_image_panel_events(bContext *C, void *UNUSED(arg), int event) { @@ -110,9 +105,6 @@ static void do_image_panel_events(bContext *C, void *UNUSED(arg), int event) switch(event) { case B_REDR: break; - case B_TRANS_IMAGE: - image_editvertex_buts(C, NULL); - break; } /* all events now */ @@ -193,127 +185,6 @@ struct ImageUser *ntree_get_active_iuser(bNodeTree *ntree) /* ************ panel stuff ************* */ -/* this function gets the values for cursor and vertex number buttons */ -static void image_transform_but_attr(SpaceImage *sima, int *imx, int *imy, int *step, int *digits) /*, float *xcoord, float *ycoord)*/ -{ - ED_space_image_size(sima, imx, imy); - - if (sima->flag & SI_COORDFLOATS) { - *step= 1; - *digits= 3; - } - else { - *step= 100; - *digits= 2; - } -} - - -/* is used for both read and write... */ -static void image_editvertex_buts(const bContext *C, uiBlock *block) -{ - Scene *scene= CTX_data_scene(C); - SpaceImage *sima= CTX_wm_space_image(C); - Image *ima= sima->image; - Object *obedit= CTX_data_edit_object(C); - static float ocent[2]; - float cent[2]= {0.0, 0.0}; - int imx= 256, imy= 256; - int nactive= 0, step, digits; - EditMesh *em; - EditFace *efa; - MTFace *tf; - - image_transform_but_attr(sima, &imx, &imy, &step, &digits); - - em= BKE_mesh_get_editmesh((Mesh *)obedit->data); - for (efa= em->faces.first; efa; efa= efa->next) { - tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); - if (uvedit_face_visible(scene, ima, efa, tf)) { - - if (uvedit_uv_selected(scene, efa, tf, 0)) { - cent[0]+= tf->uv[0][0]; - cent[1]+= tf->uv[0][1]; - nactive++; - } - if (uvedit_uv_selected(scene, efa, tf, 1)) { - cent[0]+= tf->uv[1][0]; - cent[1]+= tf->uv[1][1]; - nactive++; - } - if (uvedit_uv_selected(scene, efa, tf, 2)) { - cent[0]+= tf->uv[2][0]; - cent[1]+= tf->uv[2][1]; - nactive++; - } - if (efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) { - cent[0]+= tf->uv[3][0]; - cent[1]+= tf->uv[3][1]; - nactive++; - } - } - } - - if(block) { // do the buttons - if (nactive) { - ocent[0]= cent[0]/nactive; - ocent[1]= cent[1]/nactive; - if (sima->flag & SI_COORDFLOATS) { - } else { - ocent[0] *= imx; - ocent[1] *= imy; - } - - uiBlockBeginAlign(block); - uiDefButF(block, NUM, B_TRANS_IMAGE, "X:", 10, 10, 145, 19, &ocent[0], -10*imx, 10.0*imx, step, digits, ""); - uiDefButF(block, NUM, B_TRANS_IMAGE, "Y:", 165, 10, 145, 19, &ocent[1], -10*imy, 10.0*imy, step, digits, ""); - uiBlockEndAlign(block); - } - } - else { // apply event - float delta[2]; - - cent[0]= cent[0]/nactive; - cent[1]= cent[1]/nactive; - - if (sima->flag & SI_COORDFLOATS) { - delta[0]= ocent[0]-cent[0]; - delta[1]= ocent[1]-cent[1]; - } - else { - delta[0]= ocent[0]/imx - cent[0]; - delta[1]= ocent[1]/imy - cent[1]; - } - - for (efa= em->faces.first; efa; efa= efa->next) { - tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); - if (uvedit_face_visible(scene, ima, efa, tf)) { - if (uvedit_uv_selected(scene, efa, tf, 0)) { - tf->uv[0][0]+= delta[0]; - tf->uv[0][1]+= delta[1]; - } - if (uvedit_uv_selected(scene, efa, tf, 1)) { - tf->uv[1][0]+= delta[0]; - tf->uv[1][1]+= delta[1]; - } - if (uvedit_uv_selected(scene, efa, tf, 2)) { - tf->uv[2][0]+= delta[0]; - tf->uv[2][1]+= delta[1]; - } - if (efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) { - tf->uv[3][0]+= delta[0]; - tf->uv[3][1]+= delta[1]; - } - } - } - - WM_event_add_notifier(C, NC_IMAGE, sima->image); - } - - BKE_mesh_end_editmesh(obedit->data, em); -} - - /* is used for both read and write... */ static int image_panel_poll(const bContext *C, PanelType *UNUSED(pt)) @@ -976,22 +847,6 @@ void uiTemplateImageLayers(uiLayout *layout, bContext *C, Image *ima, ImageUser } } -static int image_panel_uv_poll(const bContext *C, PanelType *UNUSED(pt)) -{ - Object *obedit= CTX_data_edit_object(C); - return ED_uvedit_test(obedit); -} - -static void image_panel_uv(const bContext *C, Panel *pa) -{ - uiBlock *block; - - block= uiLayoutAbsoluteBlock(pa->layout); - uiBlockSetHandleFunc(block, do_image_panel_events, NULL); - - image_editvertex_buts(C, block); -} - void image_buttons_register(ARegionType *art) { PanelType *pt; @@ -1009,13 +864,6 @@ void image_buttons_register(ARegionType *art) strcpy(pt->label, "Grease Pencil"); pt->draw= gpencil_panel_standard; BLI_addtail(&art->paneltypes, pt); - - pt= MEM_callocN(sizeof(PanelType), "spacetype image panel uv"); - strcpy(pt->idname, "IMAGE_PT_uv"); - strcpy(pt->label, "UV Vertex"); - pt->draw= image_panel_uv; - pt->poll= image_panel_uv_poll; - BLI_addtail(&art->paneltypes, pt); } static int image_properties(bContext *C, wmOperator *UNUSED(op)) diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 451e0e6e89b..e923ec5344f 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -989,6 +989,7 @@ void ED_spacetype_image(void) BLI_addhead(&st->regiontypes, art); image_buttons_register(art); + ED_uvedit_buttons_register(art); /* regions: statistics/scope buttons */ art= MEM_callocN(sizeof(ARegionType), "spacetype image region"); diff --git a/source/blender/editors/uvedit/CMakeLists.txt b/source/blender/editors/uvedit/CMakeLists.txt index 16e3536b646..60d730e8c52 100644 --- a/source/blender/editors/uvedit/CMakeLists.txt +++ b/source/blender/editors/uvedit/CMakeLists.txt @@ -33,6 +33,7 @@ set(INC ) set(SRC + uvedit_buttons.c uvedit_draw.c uvedit_ops.c uvedit_parametrizer.c diff --git a/source/blender/editors/uvedit/uvedit_buttons.c b/source/blender/editors/uvedit/uvedit_buttons.c new file mode 100644 index 00000000000..5380f514a73 --- /dev/null +++ b/source/blender/editors/uvedit/uvedit_buttons.c @@ -0,0 +1,233 @@ +/* + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * Contributor(s): Blender Foundation, 2002-2009 + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/uvedit/uvedit_buttons.c + * \ingroup eduv + */ + +#include <string.h> +#include <stdio.h> + +#include "MEM_guardedalloc.h" + +#include "DNA_meshdata_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_space_types.h" + +#include "BLI_blenlib.h" +#include "BLI_math.h" +#include "BLI_editVert.h" +#include "BLI_utildefines.h" + +#include "BKE_context.h" +#include "BKE_customdata.h" +#include "BKE_mesh.h" +#include "BKE_screen.h" + +#include "ED_image.h" +#include "ED_uvedit.h" + +#include "UI_interface.h" +#include "UI_resources.h" + +#include "WM_api.h" +#include "WM_types.h" + +#define B_UVEDIT_VERTEX 3 + +/* UV Utilities */ + +static int uvedit_center(Scene *scene, EditMesh *em, Image *ima, float center[2]) +{ + EditFace *efa; + MTFace *tf; + int tot= 0; + + zero_v2(center); + + for(efa= em->faces.first; efa; efa= efa->next) { + tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); + + if(uvedit_face_visible(scene, ima, efa, tf)) { + if(uvedit_uv_selected(scene, efa, tf, 0)) { + add_v2_v2(center, tf->uv[0]); + tot++; + } + if(uvedit_uv_selected(scene, efa, tf, 1)) { + add_v2_v2(center, tf->uv[1]); + tot++; + } + if(uvedit_uv_selected(scene, efa, tf, 2)) { + add_v2_v2(center, tf->uv[2]); + tot++; + } + if(efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) { + add_v2_v2(center, tf->uv[3]); + tot++; + } + } + } + + if(tot > 0) { + center[0] /= tot; + center[1] /= tot; + } + + return tot; +} + +static void uvedit_translate(Scene *scene, EditMesh *em, Image *ima, float delta[2]) +{ + EditFace *efa; + MTFace *tf; + + for(efa= em->faces.first; efa; efa= efa->next) { + tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); + + if(uvedit_face_visible(scene, ima, efa, tf)) { + if(uvedit_uv_selected(scene, efa, tf, 0)) + add_v2_v2(tf->uv[0], delta); + if(uvedit_uv_selected(scene, efa, tf, 1)) + add_v2_v2(tf->uv[1], delta); + if(uvedit_uv_selected(scene, efa, tf, 2)) + add_v2_v2(tf->uv[2], delta); + if(efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) + add_v2_v2(tf->uv[3], delta); + } + } +} + +/* Button Functions, using an evil static variable */ + +static float uvedit_old_center[2]; + +static void uvedit_vertex_buttons(const bContext *C, uiBlock *block) +{ + SpaceImage *sima= CTX_wm_space_image(C); + Scene *scene= CTX_data_scene(C); + Object *obedit= CTX_data_edit_object(C); + Image *ima= sima->image; + float center[2]; + int imx, imy, step, digits; + EditMesh *em; + + ED_space_image_size(sima, &imx, &imy); + + em= BKE_mesh_get_editmesh((Mesh *)obedit->data); + + if(uvedit_center(scene, em, ima, center)) { + copy_v2_v2(uvedit_old_center, center); + + if(!(sima->flag & SI_COORDFLOATS)) { + uvedit_old_center[0] *= imx; + uvedit_old_center[1] *= imy; + } + + if(sima->flag & SI_COORDFLOATS) { + step= 1; + digits= 3; + } + else { + step= 100; + digits= 2; + } + + uiBlockBeginAlign(block); + uiDefButF(block, NUM, B_UVEDIT_VERTEX, "X:", 10, 10, 145, 19, &uvedit_old_center[0], -10*imx, 10.0*imx, step, digits, ""); + uiDefButF(block, NUM, B_UVEDIT_VERTEX, "Y:", 165, 10, 145, 19, &uvedit_old_center[1], -10*imy, 10.0*imy, step, digits, ""); + uiBlockEndAlign(block); + } + + BKE_mesh_end_editmesh(obedit->data, em); +} + +static void do_uvedit_vertex(bContext *C, void *UNUSED(arg), int event) +{ + SpaceImage *sima= CTX_wm_space_image(C); + Scene *scene= CTX_data_scene(C); + Object *obedit= CTX_data_edit_object(C); + Image *ima= sima->image; + EditMesh *em; + float center[2], delta[2]; + int imx, imy; + + if(event != B_UVEDIT_VERTEX) + return; + + em= BKE_mesh_get_editmesh((Mesh *)obedit->data); + + ED_space_image_size(sima, &imx, &imy); + uvedit_center(scene, em, ima, center); + + if(sima->flag & SI_COORDFLOATS) { + delta[0]= uvedit_old_center[0] - center[0]; + delta[1]= uvedit_old_center[1] - center[1]; + } + else { + delta[0]= uvedit_old_center[0]/imx - center[0]; + delta[1]= uvedit_old_center[1]/imy - center[1]; + } + + uvedit_translate(scene, em, ima, delta); + + BKE_mesh_end_editmesh(obedit->data, em); + + WM_event_add_notifier(C, NC_IMAGE, sima->image); +} + +/* Panels */ + +static int image_panel_uv_poll(const bContext *C, PanelType *UNUSED(pt)) +{ + Object *obedit= CTX_data_edit_object(C); + return ED_uvedit_test(obedit); +} + +static void image_panel_uv(const bContext *C, Panel *pa) +{ + uiBlock *block; + + block= uiLayoutAbsoluteBlock(pa->layout); + uiBlockSetHandleFunc(block, do_uvedit_vertex, NULL); + + uvedit_vertex_buttons(C, block); +} + +void ED_uvedit_buttons_register(ARegionType *art) +{ + PanelType *pt; + + pt= MEM_callocN(sizeof(PanelType), "spacetype image panel uv"); + strcpy(pt->idname, "IMAGE_PT_uv"); + strcpy(pt->label, "UV Vertex"); + pt->draw= image_panel_uv; + pt->poll= image_panel_uv_poll; + BLI_addtail(&art->paneltypes, pt); +} + |