/** * $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * The Original Code is Copyright (C) 2008 Blender Foundation. * All rights reserved. * * * Contributor(s): Blender Foundation * * ***** END GPL LICENSE BLOCK ***** */ #include "DNA_screen_types.h" #include "DNA_vec_types.h" #include "DNA_windowmanager_types.h" #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" #include "BKE_global.h" #include "BKE_utildefines.h" #include "WM_api.h" #include "WM_types.h" #include "wm_event_system.h" #include "wm_subwindow.h" #include "BIF_gl.h" #include "BIF_glutil.h" /* context checked on having screen, window and area */ wmGesture *WM_gesture_new(bContext *C, wmEvent *event, int type) { wmGesture *gesture= MEM_callocN(sizeof(wmGesture), "new gesture"); int sx, sy; BLI_addtail(&C->window->gesture, gesture); gesture->type= type; gesture->eventtype= event->type; gesture->swinid= C->screen->subwinactive; /* means only in area-region context! */ wm_subwindow_getorigin(C->window, gesture->swinid, &sx, &sy); if( ELEM(type, WM_GESTURE_RECT, WM_GESTURE_CROSS_RECT)) { rcti *rect= MEM_callocN(sizeof(rcti), "gesture rect new"); gesture->customdata= rect; rect->xmin= event->x - sx; rect->ymin= event->y - sy; rect->xmax= event->x - sx; rect->ymax= event->y - sy; } return gesture; } void WM_gesture_end(bContext *C, wmGesture *gesture) { BLI_remlink(&C->window->gesture, gesture); MEM_freeN(gesture->customdata); MEM_freeN(gesture); } /* ******************* gesture draw ******************* */ static void wm_gesture_draw_rect(wmWindow *win, wmGesture *gt) { rcti *rect= (rcti *)gt->customdata; glEnable(GL_LINE_STIPPLE); glColor3ub(0, 0, 0); glLineStipple(1, 0xAAAA); sdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax); glColor3ub(255, 255, 255); glLineStipple(1, 0x3333); sdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax); glDisable(GL_LINE_STIPPLE); } static void wm_gesture_draw_cross(wmWindow *win, wmGesture *gt) { rcti *rect= (rcti *)gt->customdata; glEnable(GL_LINE_STIPPLE); glColor3ub(0, 0, 0); glLineStipple(1, 0xAAAA); sdrawline(rect->xmin - win->sizex, rect->ymin, rect->xmin + win->sizex, rect->ymin); sdrawline(rect->xmin, rect->ymin - win->sizey, rect->xmin, rect->ymin + win->sizey); glColor3ub(255, 255, 255); glLineStipple(1, 0x3333); sdrawline(rect->xmin - win->sizex, rect->ymin, rect->xmin + win->sizex, rect->ymin); sdrawline(rect->xmin, rect->ymin - win->sizey, rect->xmin, rect->ymin + win->sizey); glDisable(GL_LINE_STIPPLE); } /* called in wm_event_system.c */ void wm_gesture_draw(wmWindow *win) { wmGesture *gt= (wmGesture *)win->gesture.first; for(; gt; gt= gt->next) { /* all in subwindow space */ wm_subwindow_set(win, gt->swinid); if(gt->type==WM_GESTURE_RECT) wm_gesture_draw_rect(win, gt); else if(gt->type==WM_GESTURE_CROSS_RECT) { if(gt->mode==1) wm_gesture_draw_rect(win, gt); else wm_gesture_draw_cross(win, gt); } } }