#include "BLI_math.h"
#include "BLI_rand.h"
-#include "BKE_action.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "BKE_image.h"
+#include "BKE_library.h"
#include "BKE_object.h"
-#include "BKE_global.h"
#include "BKE_paint.h"
#include "BKE_report.h"
#include "BKE_scene.h"
-#include "BKE_screen.h"
-#include "BKE_utildefines.h"
#include "BIF_gl.h"
static int view3d_rotate_poll(bContext *C)
{
- if (!ED_operator_view3d_active(C)) {
+ if (!ED_operator_region_view3d_active(C)) {
return 0;
} else {
RegionView3D *rv3d= CTX_wm_region_view3d(C);
static void viewmove_apply(ViewOpsData *vod, int x, int y)
{
if(vod->rv3d->persp==RV3D_CAMOB) {
- float max= (float)MAX2(vod->ar->winx, vod->ar->winy);
+ float zoomfac= (M_SQRT2 + vod->rv3d->camzoom/50.0);
+ zoomfac= (zoomfac*zoomfac)*0.5;
- vod->rv3d->camdx += (vod->oldx - x)/(max);
- vod->rv3d->camdy += (vod->oldy - y)/(max);
+ vod->rv3d->camdx += (vod->oldx - x)/(vod->ar->winx * zoomfac);
+ vod->rv3d->camdy += (vod->oldy - y)/(vod->ar->winy * zoomfac);
CLAMP(vod->rv3d->camdx, -1.0f, 1.0f);
CLAMP(vod->rv3d->camdy, -1.0f, 1.0f);
// XXX preview3d_event= 0;
/* this min and max is also in viewmove() */
if(rv3d->persp==RV3D_CAMOB) {
rv3d->camzoom-= 10;
- if(rv3d->camzoom<-30) rv3d->camzoom= -30;
+ if(rv3d->camzoom < RV3D_CAMZOOM_MIN) rv3d->camzoom= RV3D_CAMZOOM_MIN;
}
else if(rv3d->dist<10.0*v3d->far) {
view_zoom_mouseloc(CTX_wm_region(C), 1.2f, mx, my);
else {
if(rv3d->persp==RV3D_CAMOB) {
rv3d->camzoom+= 10;
- if(rv3d->camzoom>600) rv3d->camzoom= 600;
+ if(rv3d->camzoom > RV3D_CAMZOOM_MAX) rv3d->camzoom= RV3D_CAMZOOM_MAX;
}
else if(rv3d->dist> 0.001*v3d->grid) {
view_zoom_mouseloc(CTX_wm_region(C), .83333f, mx, my);
ot->invoke= viewzoom_invoke;
ot->exec= viewzoom_exec;
ot->modal= viewzoom_modal;
- ot->poll= ED_operator_view3d_active;
+ ot->poll= ED_operator_region_view3d_active;
/* flags */
ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
RNA_def_int(ot->srna, "my", 0, 0, INT_MAX, "Zoom Position Y", "", 0, INT_MAX);
}
-static int viewhome_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2.4x */
+static int view3d_all_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2.4x */
{
ARegion *ar= CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
int ok= 1, onedone=0;
if(center) {
- min[0]= min[1]= min[2]= 0.0f;
- max[0]= max[1]= max[2]= 0.0f;
-
/* in 2.4x this also move the cursor to (0, 0, 0) (with shift+c). */
curs= give_cursor(scene, v3d);
- curs[0]= curs[1]= curs[2]= 0.0;
+ zero_v3(min);
+ zero_v3(max);
+ zero_v3(curs);
}
else {
INIT_MINMAX(min, max);
return OPERATOR_FINISHED;
}
- afm[0]= (max[0]-min[0]);
- afm[1]= (max[1]-min[1]);
- afm[2]= (max[2]-min[2]);
+ sub_v3_v3v3(afm, max, min);
size= 0.7f*MAX3(afm[0], afm[1], afm[2]);
if(size==0.0) ok= 0;
if (rv3d->persp==RV3D_CAMOB) {
rv3d->persp= RV3D_PERSP;
- smooth_view(C, NULL, v3d->camera, new_ofs, NULL, &new_dist, NULL);
+ smooth_view(C, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL);
}
else {
smooth_view(C, NULL, NULL, new_ofs, NULL, &new_dist, NULL);
return OPERATOR_FINISHED;
}
-static int viewhome_poll(bContext *C)
-{
- if(ED_operator_view3d_active(C)) {
- RegionView3D *rv3d= CTX_wm_region_view3d(C); //XXX, when accessed from a header menu this doesnt work!
- if(rv3d && rv3d->persp!=RV3D_CAMOB) {
- return 1;
- }
- }
-
- return 0;
-}
void VIEW3D_OT_view_all(wmOperatorType *ot)
{
ot->idname= "VIEW3D_OT_view_all";
/* api callbacks */
- ot->exec= viewhome_exec;
- ot->poll= viewhome_poll;
+ ot->exec= view3d_all_exec;
+ ot->poll= ED_operator_view3d_active;
/* flags */
ot->flag= 0;
/* api callbacks */
ot->exec= viewselected_exec;
- ot->poll= ED_operator_view3d_active;
+ ot->poll= ED_operator_region_view3d_active;
/* flags */
ot->flag= 0;
rect.ymax= RNA_int_get(op->ptr, "ymax");
/* calculate range */
- calc_viewborder(scene, ar, rv3d, v3d, &vb);
+ view3d_calc_camera_border(scene, ar, rv3d, v3d, &vb);
scene->r.border.xmin= ((float)rect.xmin-vb.xmin)/(vb.xmax-vb.xmin);
scene->r.border.ymin= ((float)rect.ymin-vb.ymin)/(vb.ymax-vb.ymin);
void VIEW3D_OT_zoom_border(wmOperatorType *ot)
{
-
/* identifiers */
ot->name= "Border Zoom";
ot->description = "Zoom in the view to the nearest object contained in the border";
ot->exec= view3d_zoom_border_exec;
ot->modal= WM_border_select_modal;
- ot->poll= ED_operator_view3d_active;
+ ot->poll= ED_operator_region_view3d_active;
/* flags */
ot->flag= 0;
if (rv3d->persp==RV3D_CAMOB && v3d->camera) {
- if (U.uiflag & USER_AUTOPERSP) rv3d->persp= RV3D_ORTHO;
+ if (U.uiflag & USER_AUTOPERSP) rv3d->persp= view ? RV3D_ORTHO : RV3D_PERSP;
else if(rv3d->persp==RV3D_CAMOB) rv3d->persp= perspo;
smooth_view(C, v3d->camera, NULL, rv3d->ofs, new_quat, NULL, NULL);
}
else {
- if (U.uiflag & USER_AUTOPERSP) rv3d->persp= RV3D_ORTHO;
+ if (U.uiflag & USER_AUTOPERSP) rv3d->persp= view ? RV3D_ORTHO : RV3D_PERSP;
else if(rv3d->persp==RV3D_CAMOB) rv3d->persp= perspo;
smooth_view(C, NULL, NULL, NULL, new_quat, NULL, NULL);
/* api callbacks */
ot->exec= viewnumpad_exec;
- ot->poll= ED_operator_view3d_active;
+ ot->poll= ED_operator_region_view3d_active;
/* flags */
ot->flag= 0;
pandir = RNA_enum_get(op->ptr, "type");
initgrabz(rv3d, 0.0, 0.0, 0.0);
-
if(pandir == V3D_VIEW_PANRIGHT) window_to_3d_delta(ar, vec, -32, 0);
else if(pandir == V3D_VIEW_PANLEFT) window_to_3d_delta(ar, vec, 32, 0);
else if(pandir == V3D_VIEW_PANUP) window_to_3d_delta(ar, vec, 0, -25);
else if(pandir == V3D_VIEW_PANDOWN) window_to_3d_delta(ar, vec, 0, 25);
- rv3d->ofs[0]+= vec[0];
- rv3d->ofs[1]+= vec[1];
- rv3d->ofs[2]+= vec[2];
+ add_v3_v3(rv3d->ofs, vec);
if(rv3d->viewlock & RV3D_BOXVIEW)
view3d_boxview_sync(CTX_wm_area(C), ar);
/* api callbacks */
ot->exec= viewpan_exec;
- ot->poll= ED_operator_view3d_active;
+ ot->poll= ED_operator_region_view3d_active;
/* flags */
ot->flag= 0;
/* api callbacks */
ot->exec= viewpersportho_exec;
- ot->poll= ED_operator_view3d_active;
+ ot->poll= ED_operator_region_view3d_active;
/* flags */
ot->flag= 0;
/* ******************** add background image operator **************** */
-static int add_background_image_exec(bContext *C, wmOperator *op)
+static BGpic *add_background_image(bContext *C)
{
View3D *v3d= CTX_wm_view3d(C);
-
+
BGpic *bgpic= MEM_callocN(sizeof(BGpic), "Background Image");
bgpic->size= 5.0;
bgpic->blend= 0.5;
bgpic->iuser.fie_ima= 2;
bgpic->iuser.ok= 1;
bgpic->view= 0; /* 0 for all */
-
+
BLI_addtail(&v3d->bgpicbase, bgpic);
+
+ return bgpic;
+}
- //ED_region_tag_redraw(v3d);
+static int add_background_image_exec(bContext *C, wmOperator *op)
+{
+ add_background_image(C);
return OPERATOR_FINISHED;
}
static int add_background_image_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
- return add_background_image_exec(C, op);
+ Scene *scene= CTX_data_scene(C);
+ View3D *v3d= CTX_wm_view3d(C);
+ Image *ima= NULL;
+ BGpic *bgpic;
+ char name[32];
+
+ /* check input variables */
+ if(RNA_property_is_set(op->ptr, "filepath")) {
+ char path[FILE_MAX];
+
+ RNA_string_get(op->ptr, "filepath", path);
+ ima= BKE_add_image_file(path, scene ? scene->r.cfra : 1);
+ }
+ else if(RNA_property_is_set(op->ptr, "name")) {
+ RNA_string_get(op->ptr, "name", name);
+ ima= (Image *)find_id("IM", name);
+ }
+
+ bgpic = add_background_image(C);
+
+ if (ima) {
+ bgpic->ima = ima;
+
+ if(ima->id.us==0) id_us_plus(&ima->id);
+ else id_lib_extern(&ima->id);
+
+ if (!(v3d->flag & V3D_DISPBGPICS))
+ v3d->flag |= V3D_DISPBGPICS;
+ }
+
+ WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, v3d);
+
+ return OPERATOR_FINISHED;
}
void VIEW3D_OT_add_background_image(wmOperatorType *ot)
/* flags */
ot->flag = 0;
+
+ /* properties */
+ RNA_def_string(ot->srna, "name", "Image", 24, "Name", "Image name to assign.");
+ RNA_def_string(ot->srna, "filepath", "Path", FILE_MAX, "Filepath", "Path to image file");
}
+
/* ***** remove image operator ******* */
static int remove_background_image_exec(bContext *C, wmOperator *op)
{
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Background image index to remove ", 0, INT_MAX);
}
+
/* ********************* set clipping operator ****************** */
static void calc_clipping_plane(float clip[6][4], BoundBox *clipbb)
ot->exec= view3d_clipping_exec;
ot->modal= WM_border_select_modal;
- ot->poll= ED_operator_view3d_active;
+ ot->poll= ED_operator_region_view3d_active;
/* flags */
ot->flag= 0;
float dx, dy, fz, *fp = NULL, dvec[3], oldcurs[3];
short mx, my, mval[2];
// short ctrl= 0; // XXX
-
+ int flip;
fp= give_cursor(scene, v3d);
// if(obedit && ctrl) lr_click= 1;
mx= event->x - ar->winrct.xmin;
my= event->y - ar->winrct.ymin;
+
project_short_noclip(ar, fp, mval);
+ flip= initgrabz(rv3d, fp[0], fp[1], fp[2]);
+
+ /* reset the depth based on the view offset */
+ if(flip) {
+ negate_v3_v3(fp, rv3d->ofs);
- initgrabz(rv3d, fp[0], fp[1], fp[2]);
+ /* re initialize */
+ project_short_noclip(ar, fp, mval);
+ flip= initgrabz(rv3d, fp[0], fp[1], fp[2]);
+ }
if(mval[0]!=IS_CLIPPED) {
short depth_used = 0;