style cleanup: wm, mosyly adding space around ops

This commit is contained in:
2012-03-27 01:24:16 +00:00
parent 126c9d4caa
commit ae654301b0
14 changed files with 2587 additions and 2588 deletions

View File

@@ -63,7 +63,7 @@
/* ****************************************************** */
static ListBase dropboxes= {NULL, NULL};
static ListBase dropboxes = {NULL, NULL};
/* drop box maps are stored global for now */
/* these are part of blender's UI/space specs, and not like keymaps */
@@ -83,15 +83,15 @@ ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
{
wmDropBoxMap *dm;
for (dm= dropboxes.first; dm; dm= dm->next)
if (dm->spaceid==spaceid && dm->regionid==regionid)
if (0==strncmp(idname, dm->idname, KMAP_MAX_NAME))
for (dm = dropboxes.first; dm; dm = dm->next)
if (dm->spaceid == spaceid && dm->regionid == regionid)
if (0 == strncmp(idname, dm->idname, KMAP_MAX_NAME))
return &dm->dropboxes;
dm= MEM_callocN(sizeof(struct wmDropBoxMap), "dropmap list");
dm = MEM_callocN(sizeof(struct wmDropBoxMap), "dropmap list");
BLI_strncpy(dm->idname, idname, KMAP_MAX_NAME);
dm->spaceid= spaceid;
dm->regionid= regionid;
dm->spaceid = spaceid;
dm->regionid = regionid;
BLI_addtail(&dropboxes, dm);
return &dm->dropboxes;
@@ -100,16 +100,16 @@ ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
wmDropBox *WM_dropbox_add(ListBase *lb, const char *idname, int (*poll)(bContext *, wmDrag *, wmEvent *),
void (*copy)(wmDrag *, wmDropBox *))
void (*copy)(wmDrag *, wmDropBox *))
{
wmDropBox *drop= MEM_callocN(sizeof(wmDropBox), "wmDropBox");
wmDropBox *drop = MEM_callocN(sizeof(wmDropBox), "wmDropBox");
drop->poll= poll;
drop->copy= copy;
drop->ot= WM_operatortype_find(idname, 0);
drop->opcontext= WM_OP_INVOKE_DEFAULT;
drop->poll = poll;
drop->copy = copy;
drop->ot = WM_operatortype_find(idname, 0);
drop->opcontext = WM_OP_INVOKE_DEFAULT;
if (drop->ot==NULL) {
if (drop->ot == NULL) {
MEM_freeN(drop);
printf("Error: dropbox with unknown operator: %s\n", idname);
return NULL;
@@ -125,10 +125,10 @@ void wm_dropbox_free(void)
{
wmDropBoxMap *dm;
for (dm= dropboxes.first; dm; dm= dm->next) {
for (dm = dropboxes.first; dm; dm = dm->next) {
wmDropBox *drop;
for (drop= dm->dropboxes.first; drop; drop= drop->next) {
for (drop = dm->dropboxes.first; drop; drop = drop->next) {
if (drop->ptr) {
WM_operator_properties_free(drop->ptr);
MEM_freeN(drop->ptr);
@@ -145,40 +145,40 @@ void wm_dropbox_free(void)
/* note that the pointer should be valid allocated and not on stack */
wmDrag *WM_event_start_drag(struct bContext *C, int icon, int type, void *poin, double value)
{
wmWindowManager *wm= CTX_wm_manager(C);
wmDrag *drag= MEM_callocN(sizeof(struct wmDrag), "new drag");
wmWindowManager *wm = CTX_wm_manager(C);
wmDrag *drag = MEM_callocN(sizeof(struct wmDrag), "new drag");
/* keep track of future multitouch drag too, add a mousepointer id or so */
/* if multiple drags are added, they're drawn as list */
BLI_addtail(&wm->drags, drag);
drag->icon= icon;
drag->type= type;
if (type==WM_DRAG_PATH)
drag->icon = icon;
drag->type = type;
if (type == WM_DRAG_PATH)
BLI_strncpy(drag->path, poin, FILE_MAX);
else
drag->poin= poin;
drag->value= value;
drag->poin = poin;
drag->value = value;
return drag;
}
void WM_event_drag_image(wmDrag *drag, ImBuf *imb, float scale, int sx, int sy)
{
drag->imb= imb;
drag->scale= scale;
drag->sx= sx;
drag->sy= sy;
drag->imb = imb;
drag->scale = scale;
drag->sx = sx;
drag->sy = sy;
}
static const char *dropbox_active(bContext *C, ListBase *handlers, wmDrag *drag, wmEvent *event)
{
wmEventHandler *handler= handlers->first;
for (; handler; handler= handler->next) {
wmEventHandler *handler = handlers->first;
for (; handler; handler = handler->next) {
if (handler->dropboxes) {
wmDropBox *drop= handler->dropboxes->first;
for (; drop; drop= drop->next) {
wmDropBox *drop = handler->dropboxes->first;
for (; drop; drop = drop->next) {
if (drop->poll(C, drag, event))
return drop->ot->name;
}
@@ -190,18 +190,18 @@ static const char *dropbox_active(bContext *C, ListBase *handlers, wmDrag *drag,
/* return active operator name when mouse is in box */
static const char *wm_dropbox_active(bContext *C, wmDrag *drag, wmEvent *event)
{
wmWindow *win= CTX_wm_window(C);
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= CTX_wm_region(C);
wmWindow *win = CTX_wm_window(C);
ScrArea *sa = CTX_wm_area(C);
ARegion *ar = CTX_wm_region(C);
const char *name;
name= dropbox_active(C, &win->handlers, drag, event);
name = dropbox_active(C, &win->handlers, drag, event);
if (name) return name;
name= dropbox_active(C, &sa->handlers, drag, event);
name = dropbox_active(C, &sa->handlers, drag, event);
if (name) return name;
name= dropbox_active(C, &ar->handlers, drag, event);
name = dropbox_active(C, &ar->handlers, drag, event);
if (name) return name;
return NULL;
@@ -210,20 +210,20 @@ static const char *wm_dropbox_active(bContext *C, wmDrag *drag, wmEvent *event)
static void wm_drop_operator_options(bContext *C, wmDrag *drag, wmEvent *event)
{
wmWindow *win= CTX_wm_window(C);
wmWindow *win = CTX_wm_window(C);
/* for multiwin drags, we only do this if mouse inside */
if (event->x<0 || event->y<0 || event->x>win->sizex || event->y>win->sizey)
if (event->x < 0 || event->y < 0 || event->x > win->sizex || event->y > win->sizey)
return;
drag->opname[0]= 0;
drag->opname[0] = 0;
/* check buttons (XXX todo rna and value) */
if ( UI_but_active_drop_name(C) ) {
if (UI_but_active_drop_name(C) ) {
strcpy(drag->opname, "Paste name");
}
else {
const char *opname= wm_dropbox_active(C, drag, event);
const char *opname = wm_dropbox_active(C, drag, event);
if (opname) {
BLI_strncpy(drag->opname, opname, FILE_MAX);
@@ -238,10 +238,10 @@ static void wm_drop_operator_options(bContext *C, wmDrag *drag, wmEvent *event)
/* called in inner handler loop, region context */
void wm_drags_check_ops(bContext *C, wmEvent *event)
{
wmWindowManager *wm= CTX_wm_manager(C);
wmWindowManager *wm = CTX_wm_manager(C);
wmDrag *drag;
for (drag= wm->drags.first; drag; drag= drag->next) {
for (drag = wm->drags.first; drag; drag = drag->next) {
wm_drop_operator_options(C, drag, event);
}
}
@@ -250,7 +250,7 @@ void wm_drags_check_ops(bContext *C, wmEvent *event)
static void wm_drop_operator_draw(const char *name, int x, int y)
{
int width= UI_GetStringWidth(name);
int width = UI_GetStringWidth(name);
glColor4ub(0, 0, 0, 50);
@@ -258,16 +258,16 @@ static void wm_drop_operator_draw(const char *name, int x, int y)
uiRoundBox(x, y, x + width + 8, y + 15, 4);
glColor4ub(255, 255, 255, 255);
UI_DrawString(x+4, y+4, name);
UI_DrawString(x + 4, y + 4, name);
}
static const char *wm_drag_name(wmDrag *drag)
{
switch(drag->type) {
switch (drag->type) {
case WM_DRAG_ID:
{
ID *id= (ID *)drag->poin;
return id->name+2;
ID *id = (ID *)drag->poin;
return id->name + 2;
}
case WM_DRAG_PATH:
return drag->path;
@@ -293,12 +293,12 @@ static void drag_rect_minmax(rcti *rect, int x1, int y1, int x2, int y2)
/* if rect set, do not draw */
void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
{
wmWindowManager *wm= CTX_wm_manager(C);
wmWindowManager *wm = CTX_wm_manager(C);
wmDrag *drag;
int cursorx, cursory, x, y;
cursorx= win->eventstate->x;
cursory= win->eventstate->y;
cursorx = win->eventstate->x;
cursory = win->eventstate->y;
if (rect) {
rect->xmin = rect->xmax = cursorx;
rect->ymin = rect->ymax = cursory;
@@ -306,44 +306,44 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
/* XXX todo, multiline drag draws... but maybe not, more types mixed wont work well */
glEnable(GL_BLEND);
for (drag= wm->drags.first; drag; drag= drag->next) {
for (drag = wm->drags.first; drag; drag = drag->next) {
/* image or icon */
if (drag->imb) {
x= cursorx - drag->sx/2;
y= cursory - drag->sy/2;
x = cursorx - drag->sx / 2;
y = cursory - drag->sy / 2;
if (rect)
drag_rect_minmax(rect, x, y, x+drag->sx, y+drag->sy);
drag_rect_minmax(rect, x, y, x + drag->sx, y + drag->sy);
else {
glColor4f(1.0, 1.0, 1.0, 0.65); /* this blends texture */
glColor4f(1.0, 1.0, 1.0, 0.65); /* this blends texture */
glaDrawPixelsTexScaled(x, y, drag->imb->x, drag->imb->y, GL_UNSIGNED_BYTE, drag->imb->rect, drag->scale, drag->scale);
}
}
else {
x= cursorx - 8;
y= cursory - 2;
x = cursorx - 8;
y = cursory - 2;
/* icons assumed to be 16 pixels */
if (rect)
drag_rect_minmax(rect, x, y, x+16, y+16);
drag_rect_minmax(rect, x, y, x + 16, y + 16);
else
UI_icon_draw_aspect(x, y, drag->icon, 1.0, 0.8);
}
/* item name */
if (drag->imb) {
x= cursorx - drag->sx/2;
y= cursory - drag->sy/2 - 16;
x = cursorx - drag->sx / 2;
y = cursory - drag->sy / 2 - 16;
}
else {
x= cursorx + 10;
y= cursory + 1;
x = cursorx + 10;
y = cursory + 1;
}
if (rect) {
int w= UI_GetStringWidth(wm_drag_name(drag));
drag_rect_minmax(rect, x, y, x+w, y+16);
int w = UI_GetStringWidth(wm_drag_name(drag));
drag_rect_minmax(rect, x, y, x + w, y + 16);
}
else {
glColor4ub(255, 255, 255, 255);
@@ -353,17 +353,17 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
/* operator name with roundbox */
if (drag->opname[0]) {
if (drag->imb) {
x= cursorx - drag->sx/2;
y= cursory + drag->sy/2 + 4;
x = cursorx - drag->sx / 2;
y = cursory + drag->sy / 2 + 4;
}
else {
x= cursorx - 8;
y= cursory + 16;
x = cursorx - 8;
y = cursory + 16;
}
if (rect) {
int w= UI_GetStringWidth(wm_drag_name(drag));
drag_rect_minmax(rect, x, y, x+w, y+16);
int w = UI_GetStringWidth(wm_drag_name(drag));
drag_rect_minmax(rect, x, y, x + w, y + 16);
}
else
wm_drop_operator_draw(drag->opname, x, y);