Added a brush cursor to sculpt mode.

This commit is contained in:
Nicholas Bishop
2009-01-17 03:31:56 +00:00
parent 44e5b7788b
commit 9b558b2116
5 changed files with 47 additions and 16 deletions

View File

@@ -55,7 +55,9 @@ typedef struct SculptSession {
/* Used to cache the render of the active texture */
unsigned int texcache_w, texcache_h, *texcache;
void *cursor; /* wm handle */
struct RadialControl *radialcontrol;
struct SculptStroke *stroke;

View File

@@ -59,9 +59,11 @@ float *give_cursor(struct Scene *scene, struct View3D *v3d);
void initgrabz(struct View3D *v3d, float x, float y, float z);
void window_to_3d(struct ARegion *ar, struct View3D *v3d, float *vec, short mx, short my);
/* Projection */
/* Depth buffer */
float read_cached_depth(struct ViewContext *vc, int x, int y);
void request_depth_update(struct ViewContext *vc);
/* Projection */
void project_short(struct ARegion *ar, struct View3D *v3d, float *vec, short *adr);
void project_short_noclip(struct ARegion *ar, struct View3D *v3d, float *vec, short *adr);
@@ -97,7 +99,9 @@ unsigned int view3d_sample_backbuf(struct ViewContext *vc, int x, int y);
/* select */
#define MAXPICKBUF 10000
short view3d_opengl_select(struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, rcti *input);
void view3d_set_viewcontext(struct bContext *C, struct ViewContext *vc);
void view3d_operator_needs_opengl(const struct bContext *C);
/* XXX should move to arithb.c */
int edge_inside_circle(short centx, short centy, short rad, short x1, short y1, short x2, short y2);

View File

@@ -28,8 +28,6 @@
*
* Implements the Sculpt Mode tools
*
* BDR_sculptmode.h
*
*/
#include "MEM_guardedalloc.h"
@@ -79,8 +77,8 @@
#include "ED_screen.h"
#include "ED_sculpt.h"
#include "ED_space_api.h"
#include "ED_view3d.h"
#include "sculpt_intern.h"
#include "../space_view3d/view3d_intern.h" /* XXX: oh no, the next generation of bad level call! should move ViewDepths perhaps (also used for view matrices) */
#include "RNA_access.h"
#include "RNA_define.h"
@@ -1714,10 +1712,6 @@ static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *even
{
SculptData *sd = &CTX_data_scene(C)->sculptdata;
// XXX: temporary, much of sculptsession data should be in rna properties
sd->session = MEM_callocN(sizeof(SculptSession), "test sculpt session");
sd->session->cache = MEM_callocN(sizeof(StrokeCache), "stroke cache");
view3d_operator_needs_opengl(C);
sculpt_brush_stroke_init_properties(C, op, event, sd->session);
@@ -1781,9 +1775,7 @@ static int sculpt_brush_stroke_modal(bContext *C, wmOperator *op, wmEvent *event
/* Finished */
if(event->type == LEFTMOUSE && event->val == 0) {
View3D *v3d = ((View3D*)CTX_wm_area(C)->spacedata.first);
if(v3d->depths)
v3d->depths->damaged= 1;
request_depth_update(&sd->session->cache->vc);
sculpt_cache_free(sd->session->cache);
@@ -1858,19 +1850,48 @@ static void SCULPT_OT_brush_stroke(wmOperatorType *ot)
/**** Toggle operator for turning sculpt mode on or off ****/
/* XXX: The code for drawing all the paint cursors is really the same, would be better to unify them */
static void draw_paint_cursor(bContext *C, int x, int y)
{
SculptData *sd= &CTX_data_scene(C)->sculptdata;
glTranslatef((float)x, (float)y, 0.0f);
glColor4ub(255, 100, 100, 128);
glEnable( GL_LINE_SMOOTH );
glEnable(GL_BLEND);
glutil_draw_lined_arc(0.0, M_PI*2.0, sd->brush->size, 40);
glDisable(GL_BLEND);
glDisable( GL_LINE_SMOOTH );
glTranslatef((float)-x, (float)-y, 0.0f);
}
static int sculpt_toggle_mode(bContext *C, wmOperator *op)
{
Scene *sce = CTX_data_scene(C);
if(G.f & G_SCULPTMODE) {
/* Leave sculptmode */
G.f &= ~G_SCULPTMODE;
WM_paint_cursor_end(CTX_wm_manager(C), sce->sculptdata.session->cursor);
sculptsession_free(sce);
}
else {
/* Enter sculptmode */
G.f |= G_SCULPTMODE;
sce->sculptdata.session = MEM_callocN(sizeof(SculptSession), "sculpt session");
/* Needed for testing, if there's no brush then create one */
CTX_data_scene(C)->sculptdata.brush = add_brush("test brush");
sce->sculptdata.brush = add_brush("test brush");
/* Activate visible brush */
sce->sculptdata.session->cursor =
WM_paint_cursor_activate(CTX_wm_manager(C), sculpt_brush_stroke_poll, draw_paint_cursor);
}
return OPERATOR_FINISHED;

View File

@@ -127,8 +127,6 @@ void VIEW3D_OT_wpaint(struct wmOperatorType *ot);
void VIEW3D_OT_smoothview(struct wmOperatorType *ot);
void VIEW3D_OT_setcameratoview(struct wmOperatorType *ot);
void view3d_operator_needs_opengl(const struct bContext *C);
int boundbox_clip(View3D *v3d, float obmat[][4], struct BoundBox *bb);
void view3d_project_short_clip(struct ARegion *ar, View3D *v3d, float *vec, short *adr, float projmat[4][4], float wmat[4][4]);

View File

@@ -509,6 +509,12 @@ float read_cached_depth(ViewContext *vc, int x, int y)
return 1;
}
void request_depth_update(ViewContext *vc)
{
if(vc->v3d->depths)
vc->v3d->depths->damaged= 1;
}
void view3d_get_object_project_mat(View3D *v3d, Object *ob, float pmat[4][4], float vmat[4][4])
{
Mat4MulMat4(vmat, ob->obmat, v3d->viewmat);