[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36434] trunk/blender/source/blender/ editors: UV Edit: move uv vertex buttons code to uvedit module.

Brecht Van Lommel brechtvanlommel at pandora.be
Mon May 2 13:11:57 CEST 2011


Revision: 36434
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36434
Author:   blendix
Date:     2011-05-02 11:11:57 +0000 (Mon, 02 May 2011)
Log Message:
-----------
UV Edit: move uv vertex buttons code to uvedit module. 

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_uvedit.h
    trunk/blender/source/blender/editors/space_image/image_buttons.c
    trunk/blender/source/blender/editors/space_image/space_image.c
    trunk/blender/source/blender/editors/uvedit/CMakeLists.txt

Added Paths:
-----------
    trunk/blender/source/blender/editors/uvedit/uvedit_buttons.c

Modified: trunk/blender/source/blender/editors/include/ED_uvedit.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_uvedit.h	2011-05-02 10:22:49 UTC (rev 36433)
+++ trunk/blender/source/blender/editors/include/ED_uvedit.h	2011-05-02 11:11:57 UTC (rev 36434)
@@ -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 @@
 /* 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 */
 

Modified: trunk/blender/source/blender/editors/space_image/image_buttons.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_buttons.c	2011-05-02 10:22:49 UTC (rev 36433)
+++ trunk/blender/source/blender/editors/space_image/image_buttons.c	2011-05-02 11:11:57 UTC (rev 36434)
@@ -63,9 +63,7 @@
 #include "ED_gpencil.h"
 #include "ED_image.h"
 #include "ED_screen.h"
-#include "ED_uvedit.h"
 
-
 #include "RNA_access.h"
 
 #include "WM_api.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,9 +97,7 @@
 #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)
 {
 	SpaceImage *sima= CTX_wm_space_image(C);
@@ -110,9 +105,6 @@
 	switch(event) {
 		case B_REDR:
 			break;
-		case B_TRANS_IMAGE:
-			image_editvertex_buts(C, NULL);
-			break;
 	}
 
 	/* all events now */
@@ -193,129 +185,8 @@
 
 /* ************ 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))
 {
 	SpaceImage *sima= CTX_wm_space_image(C);
@@ -976,22 +847,6 @@
 	}
 }
 
-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 @@
 	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))

Modified: trunk/blender/source/blender/editors/space_image/space_image.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/space_image.c	2011-05-02 10:22:49 UTC (rev 36433)
+++ trunk/blender/source/blender/editors/space_image/space_image.c	2011-05-02 11:11:57 UTC (rev 36434)
@@ -989,6 +989,7 @@
 	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");

Modified: trunk/blender/source/blender/editors/uvedit/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/editors/uvedit/CMakeLists.txt	2011-05-02 10:22:49 UTC (rev 36433)
+++ trunk/blender/source/blender/editors/uvedit/CMakeLists.txt	2011-05-02 11:11:57 UTC (rev 36434)
@@ -33,6 +33,7 @@
 )
 
 set(SRC
+	uvedit_buttons.c
 	uvedit_draw.c
 	uvedit_ops.c
 	uvedit_parametrizer.c

Copied: trunk/blender/source/blender/editors/uvedit/uvedit_buttons.c (from rev 36429, trunk/blender/source/blender/editors/space_image/image_buttons.c)
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_buttons.c	                        (rev 0)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_buttons.c	2011-05-02 11:11:57 UTC (rev 36434)
@@ -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);
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list