Ejemplo n.º 1
0
static void playanim_window_get_size(int *width_r, int *height_r)
{
	GHOST_RectangleHandle bounds = GHOST_GetClientBounds(g_WS.ghost_window);
	*width_r = GHOST_GetWidthRectangle(bounds);
	*height_r = GHOST_GetHeightRectangle(bounds);
	GHOST_DisposeRectangle(bounds);
}
Ejemplo n.º 2
0
static void setViewPortGL(GHOST_WindowHandle hWindow)
{
	GHOST_RectangleHandle hRect = NULL;
	GLfloat w, h;
	
	GHOST_ActivateWindowDrawingContext(hWindow);
	hRect = GHOST_GetClientBounds(hWindow);
	
	w = (float)GHOST_GetWidthRectangle(hRect) / (float)GHOST_GetHeightRectangle(hRect);
	h = 1.0;
	
	glViewport(0, 0, GHOST_GetWidthRectangle(hRect), GHOST_GetHeightRectangle(hRect));

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(-w, w, -h, h, 5.0, 60.0);
	/* glOrtho(0, bnds.getWidth(), 0, bnds.getHeight(), -10, 10); */
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0.0, 0.0, -40.0);
	
	glClearColor(.2f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	GHOST_DisposeRectangle(hRect);
}
Ejemplo n.º 3
0
/* exceptional case: - splash is called before events are processed
 * this means we don't actually know the window size so get this from GHOST */
void wm_window_get_size_ghost(wmWindow *win, int *width_r, int *height_r)
{
	GHOST_RectangleHandle bounds = GHOST_GetClientBounds(win->ghostwin);
	*width_r = GHOST_GetWidthRectangle(bounds);
	*height_r = GHOST_GetHeightRectangle(bounds);
	
	GHOST_DisposeRectangle(bounds);
}
Ejemplo n.º 4
0
bool WM_init_game(bContext *C)
{
	wmWindowManager *wm = CTX_wm_manager(C);
	wmWindow *win;

	ScrArea *sa;
	ARegion *ar = NULL;

	Scene *scene = CTX_data_scene(C);

	if (!scene) {
		/* XXX, this should not be needed. */
		Main *bmain = CTX_data_main(C);
		scene = bmain->scene.first;
	}

	win = wm->windows.first;

	/* first to get a valid window */
	if (win)
		CTX_wm_window_set(C, win);

	sa = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_VIEW3D, 0);
	ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);

	/* if we have a valid 3D view */
	if (sa && ar) {
		ARegion *arhide;

		CTX_wm_area_set(C, sa);
		CTX_wm_region_set(C, ar);

		/* disable quad view */
		if (ar->alignment == RGN_ALIGN_QSPLIT)
			WM_operator_name_call(C, "SCREEN_OT_region_quadview", WM_OP_EXEC_DEFAULT, NULL);

		/* toolbox, properties panel and header are hidden */
		for (arhide = sa->regionbase.first; arhide; arhide = arhide->next) {
			if (arhide->regiontype != RGN_TYPE_WINDOW) {
				if (!(arhide->flag & RGN_FLAG_HIDDEN)) {
					ED_region_toggle_hidden(C, arhide);
				}
			}
		}

		/* full screen the area */
		if (!sa->full) {
			ED_screen_state_toggle(C, win, sa, SCREENMAXIMIZED);
		}

		/* Fullscreen */
		if ((scene->gm.playerflag & GAME_PLAYER_FULLSCREEN)) {
			WM_operator_name_call(C, "WM_OT_window_fullscreen_toggle", WM_OP_EXEC_DEFAULT, NULL);
			wm_get_screensize(&ar->winrct.xmax, &ar->winrct.ymax);
			ar->winx = ar->winrct.xmax + 1;
			ar->winy = ar->winrct.ymax + 1;
		}
		else {
			GHOST_RectangleHandle rect = GHOST_GetClientBounds(win->ghostwin);
			ar->winrct.ymax = GHOST_GetHeightRectangle(rect);
			ar->winrct.xmax = GHOST_GetWidthRectangle(rect);
			ar->winx = ar->winrct.xmax + 1;
			ar->winy = ar->winrct.ymax + 1;
			GHOST_DisposeRectangle(rect);
		}

		WM_operator_name_call(C, "VIEW3D_OT_game_start", WM_OP_EXEC_DEFAULT, NULL);

		BKE_sound_exit();

		return true;
	}
	else {
		ReportTimerInfo *rti;

		BKE_report(&wm->reports, RPT_ERROR, "No valid 3D View found, game auto start is not possible");

		/* After adding the report to the global list, reset the report timer. */
		WM_event_remove_timer(wm, NULL, wm->reports.reporttimer);

		/* Records time since last report was added */
		wm->reports.reporttimer = WM_event_add_timer(wm, CTX_wm_window(C), TIMER, 0.02);

		rti = MEM_callocN(sizeof(ReportTimerInfo), "ReportTimerInfo");
		wm->reports.reporttimer->customdata = rti;

		return false;
	}
}
Ejemplo n.º 5
0
/* called by ghost, here we handle events for windows themselves or send to event system */
static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr)
{
	bContext *C = C_void_ptr;
	wmWindowManager *wm = CTX_wm_manager(C);
	GHOST_TEventType type = GHOST_GetEventType(evt);
	int time = GHOST_GetEventTime(evt);
	
	if (type == GHOST_kEventQuit) {
		WM_exit(C);
	}
	else {
		GHOST_WindowHandle ghostwin = GHOST_GetEventWindow(evt);
		GHOST_TEventDataPtr data = GHOST_GetEventData(evt);
		wmWindow *win;
		
		if (!ghostwin) {
			/* XXX - should be checked, why are we getting an event here, and */
			/* what is it? */
			puts("<!> event has no window");
			return 1;
		}
		else if (!GHOST_ValidWindow(g_system, ghostwin)) {
			/* XXX - should be checked, why are we getting an event here, and */
			/* what is it? */
			puts("<!> event has invalid window");			
			return 1;
		}
		else {
			win = GHOST_GetWindowUserData(ghostwin);
		}
		
		switch (type) {
			case GHOST_kEventWindowDeactivate:
				wm_event_add_ghostevent(wm, win, type, time, data);
				win->active = 0; /* XXX */
				break;
			case GHOST_kEventWindowActivate: 
			{
				GHOST_TEventKeyData kdata;
				wmEvent event;
				int cx, cy, wx, wy;
				
				wm->winactive = win; /* no context change! c->wm->windrawable is drawable, or for area queues */
				
				win->active = 1;
//				window_handle(win, INPUTCHANGE, win->active);
				
				/* bad ghost support for modifier keys... so on activate we set the modifiers again */
				kdata.ascii = '\0';
				kdata.utf8_buf[0] = '\0';
				if (win->eventstate->shift && !query_qual(SHIFT)) {
					kdata.key = GHOST_kKeyLeftShift;
					wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
				}
				if (win->eventstate->ctrl && !query_qual(CONTROL)) {
					kdata.key = GHOST_kKeyLeftControl;
					wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
				}
				if (win->eventstate->alt && !query_qual(ALT)) {
					kdata.key = GHOST_kKeyLeftAlt;
					wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
				}
				if (win->eventstate->oskey && !query_qual(OS)) {
					kdata.key = GHOST_kKeyOS;
					wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
				}
				/* keymodifier zero, it hangs on hotkeys that open windows otherwise */
				win->eventstate->keymodifier = 0;
				
				/* entering window, update mouse pos. but no event */
				GHOST_GetCursorPosition(g_system, &wx, &wy);
				
				GHOST_ScreenToClient(win->ghostwin, wx, wy, &cx, &cy);
				win->eventstate->x = cx;
				win->eventstate->y = (win->sizey - 1) - cy;
				
				win->addmousemove = 1;   /* enables highlighted buttons */
				
				wm_window_make_drawable(C, win);

				/* window might be focused by mouse click in configuration of window manager
				 * when focus is not following mouse
				 * click could have been done on a button and depending on window manager settings
				 * click would be passed to blender or not, but in any case button under cursor
				 * should be activated, so at max next click on button without moving mouse
				 * would trigger it's handle function
				 * currently it seems to be common practice to generate new event for, but probably
				 * we'll need utility function for this? (sergey)
				 */
				event = *(win->eventstate);
				event.type = MOUSEMOVE;
				event.prevx = event.x;
				event.prevy = event.y;

				wm_event_add(win, &event);

				break;
			}
			case GHOST_kEventWindowClose: {
				wm_window_close(C, wm, win);
				break;
			}
			case GHOST_kEventWindowUpdate: {
				if (G.debug & G_DEBUG_EVENTS) {
					printf("%s: ghost redraw %d\n", __func__, win->winid);
				}
				
				wm_window_make_drawable(C, win);
				WM_event_add_notifier(C, NC_WINDOW, NULL);

				break;
			}
			case GHOST_kEventWindowSize:
			case GHOST_kEventWindowMove: {
				GHOST_TWindowState state;
				state = GHOST_GetWindowState(win->ghostwin);
				win->windowstate = state;

				/* win32: gives undefined window size when minimized */
				if (state != GHOST_kWindowStateMinimized) {
					GHOST_RectangleHandle client_rect;
					int l, t, r, b, scr_w, scr_h;
					int sizex, sizey, posx, posy;
					
					client_rect = GHOST_GetClientBounds(win->ghostwin);
					GHOST_GetRectangle(client_rect, &l, &t, &r, &b);
					
					GHOST_DisposeRectangle(client_rect);
					
					wm_get_screensize(&scr_w, &scr_h);
					sizex = r - l;
					sizey = b - t;
					posx = l;
					posy = scr_h - t - win->sizey;

					/*
					 * Ghost sometimes send size or move events when the window hasn't changed.
					 * One case of this is using compiz on linux. To alleviate the problem
					 * we ignore all such event here.
					 * 
					 * It might be good to eventually do that at Ghost level, but that is for 
					 * another time.
					 */
					if (win->sizex != sizex ||
					    win->sizey != sizey ||
					    win->posx != posx ||
					    win->posy != posy)
					{
						win->sizex = sizex;
						win->sizey = sizey;
						win->posx = posx;
						win->posy = posy;

						/* debug prints */
						if (G.debug & G_DEBUG_EVENTS) {
							const char *state_str;
							state = GHOST_GetWindowState(win->ghostwin);

							if (state == GHOST_kWindowStateNormal) {
								state_str = "normal";
							}
							else if (state == GHOST_kWindowStateMinimized) {
								state_str = "minimized";
							}
							else if (state == GHOST_kWindowStateMaximized) {
								state_str = "maximized";
							}
							else if (state == GHOST_kWindowStateFullScreen) {
								state_str = "fullscreen";
							}
							else {
								state_str = "<unknown>";
							}

							printf("%s: window %d state = %s\n", __func__, win->winid, state_str);

							if (type != GHOST_kEventWindowSize) {
								printf("win move event pos %d %d size %d %d\n",
								       win->posx, win->posy, win->sizex, win->sizey);
							}
						}
					
						wm_window_make_drawable(C, win);
						wm_draw_window_clear(win);
						WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
						WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);
					}
				}
				break;
			}
				
			case GHOST_kEventOpenMainFile:
			{
				PointerRNA props_ptr;
				wmWindow *oldWindow;
				char *path = GHOST_GetEventData(evt);
				
				if (path) {
					/* operator needs a valid window in context, ensures
					 * it is correctly set */
					oldWindow = CTX_wm_window(C);
					CTX_wm_window_set(C, win);
					
					WM_operator_properties_create(&props_ptr, "WM_OT_open_mainfile");
					RNA_string_set(&props_ptr, "filepath", path);
					WM_operator_name_call(C, "WM_OT_open_mainfile", WM_OP_EXEC_DEFAULT, &props_ptr);
					WM_operator_properties_free(&props_ptr);
					
					CTX_wm_window_set(C, oldWindow);
				}
				break;
			}
			case GHOST_kEventDraggingDropDone:
			{
				wmEvent event;
				GHOST_TEventDragnDropData *ddd = GHOST_GetEventData(evt);
				int cx, cy, wx, wy;
				
				/* entering window, update mouse pos */
				GHOST_GetCursorPosition(g_system, &wx, &wy);
				
				GHOST_ScreenToClient(win->ghostwin, wx, wy, &cx, &cy);
				win->eventstate->x = cx;
				win->eventstate->y = (win->sizey - 1) - cy;
				
				event = *(win->eventstate);  /* copy last state, like mouse coords */
				
				/* activate region */
				event.type = MOUSEMOVE;
				event.prevx = event.x;
				event.prevy = event.y;
				
				wm->winactive = win; /* no context change! c->wm->windrawable is drawable, or for area queues */
				win->active = 1;
				
				wm_event_add(win, &event);
				
				
				/* make blender drop event with custom data pointing to wm drags */
				event.type = EVT_DROP;
				event.val = KM_RELEASE;
				event.custom = EVT_DATA_LISTBASE;
				event.customdata = &wm->drags;
				event.customdatafree = 1;
				
				wm_event_add(win, &event);
				
				/* printf("Drop detected\n"); */
				
				/* add drag data to wm for paths: */
				
				if (ddd->dataType == GHOST_kDragnDropTypeFilenames) {
					GHOST_TStringArray *stra = ddd->data;
					int a, icon;
					
					for (a = 0; a < stra->count; a++) {
						printf("drop file %s\n", stra->strings[a]);
						/* try to get icon type from extension */
						icon = ED_file_extension_icon((char *)stra->strings[a]);
						
						WM_event_start_drag(C, icon, WM_DRAG_PATH, stra->strings[a], 0.0);
						/* void poin should point to string, it makes a copy */
						break; /* only one drop element supported now */
					}
				}
				
				
				
				break;
			}
			
			default:
				wm_event_add_ghostevent(wm, win, type, time, data);
				break;
		}

	}
	return 1;
}
Ejemplo n.º 6
0
/* mouse coordinate converversion happens here */
static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr)
{
    bContext *C = C_void_ptr;
    wmWindowManager *wm = CTX_wm_manager(C);
    GHOST_TEventType type = GHOST_GetEventType(evt);
    int time = GHOST_GetEventTime(evt);

    if (type == GHOST_kEventQuit) {
        WM_exit(C);
    }
    else {
        GHOST_WindowHandle ghostwin = GHOST_GetEventWindow(evt);
        GHOST_TEventDataPtr data = GHOST_GetEventData(evt);
        wmWindow *win;

        /* Ghost now can call this function for life resizes, but it should return if WM didn't initialize yet.
         * Can happen on file read (especially full size window)  */
        if ((wm->initialized & WM_INIT_WINDOW) == 0) {
            return 1;
        }
        if (!ghostwin) {
            /* XXX - should be checked, why are we getting an event here, and */
            /* what is it? */
            puts("<!> event has no window");
            return 1;
        }
        else if (!GHOST_ValidWindow(g_system, ghostwin)) {
            /* XXX - should be checked, why are we getting an event here, and */
            /* what is it? */
            puts("<!> event has invalid window");
            return 1;
        }
        else {
            win = GHOST_GetWindowUserData(ghostwin);
        }

        switch (type) {
        case GHOST_kEventWindowDeactivate:
            wm_event_add_ghostevent(wm, win, type, time, data);
            win->active = 0; /* XXX */

            /* clear modifiers for inactive windows */
            win->eventstate->alt = 0;
            win->eventstate->ctrl = 0;
            win->eventstate->shift = 0;
            win->eventstate->oskey = 0;
            win->eventstate->keymodifier = 0;

            break;
        case GHOST_kEventWindowActivate:
        {
            GHOST_TEventKeyData kdata;
            wmEvent event;
            int wx, wy;
            const int keymodifier = ((query_qual(SHIFT)     ? KM_SHIFT : 0) |
                                     (query_qual(CONTROL)   ? KM_CTRL  : 0) |
                                     (query_qual(ALT)       ? KM_ALT   : 0) |
                                     (query_qual(OS)        ? KM_OSKEY : 0));

            /* Win23/GHOST modifier bug, see T40317 */
#ifndef WIN32
//#  define USE_WIN_ACTIVATE
#endif

            wm->winactive = win; /* no context change! c->wm->windrawable is drawable, or for area queues */

            win->active = 1;
//				window_handle(win, INPUTCHANGE, win->active);

            /* bad ghost support for modifier keys... so on activate we set the modifiers again */

            /* TODO: This is not correct since a modifier may be held when a window is activated...
             * better solve this at ghost level. attempted fix r54450 but it caused bug [#34255]
             *
             * For now don't send GHOST_kEventKeyDown events, just set the 'eventstate'.
             */
            kdata.ascii = '\0';
            kdata.utf8_buf[0] = '\0';

            if (win->eventstate->shift) {
                if ((keymodifier & KM_SHIFT) == 0) {
                    kdata.key = GHOST_kKeyLeftShift;
                    wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
                }
            }
#ifdef USE_WIN_ACTIVATE
            else {
                if (keymodifier & KM_SHIFT) {
                    win->eventstate->shift = KM_MOD_FIRST;
                }
            }
#endif
            if (win->eventstate->ctrl) {
                if ((keymodifier & KM_CTRL) == 0) {
                    kdata.key = GHOST_kKeyLeftControl;
                    wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
                }
            }
#ifdef USE_WIN_ACTIVATE
            else {
                if (keymodifier & KM_CTRL) {
                    win->eventstate->ctrl = KM_MOD_FIRST;
                }
            }
#endif
            if (win->eventstate->alt) {
                if ((keymodifier & KM_ALT) == 0) {
                    kdata.key = GHOST_kKeyLeftAlt;
                    wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
                }
            }
#ifdef USE_WIN_ACTIVATE
            else {
                if (keymodifier & KM_ALT) {
                    win->eventstate->alt = KM_MOD_FIRST;
                }
            }
#endif
            if (win->eventstate->oskey) {
                if ((keymodifier & KM_OSKEY) == 0) {
                    kdata.key = GHOST_kKeyOS;
                    wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
                }
            }
#ifdef USE_WIN_ACTIVATE
            else {
                if (keymodifier & KM_OSKEY) {
                    win->eventstate->oskey = KM_MOD_FIRST;
                }
            }
#endif

#undef USE_WIN_ACTIVATE


            /* keymodifier zero, it hangs on hotkeys that open windows otherwise */
            win->eventstate->keymodifier = 0;

            /* entering window, update mouse pos. but no event */
            wm_get_cursor_position(win,  &wx, &wy);

            win->eventstate->x = wx;
            win->eventstate->y = wy;

            win->addmousemove = 1;   /* enables highlighted buttons */

            wm_window_make_drawable(wm, win);

            /* window might be focused by mouse click in configuration of window manager
             * when focus is not following mouse
             * click could have been done on a button and depending on window manager settings
             * click would be passed to blender or not, but in any case button under cursor
             * should be activated, so at max next click on button without moving mouse
             * would trigger it's handle function
             * currently it seems to be common practice to generate new event for, but probably
             * we'll need utility function for this? (sergey)
             */
            wm_event_init_from_window(win, &event);
            event.type = MOUSEMOVE;
            event.prevx = event.x;
            event.prevy = event.y;

            wm_event_add(win, &event);

            break;
        }
        case GHOST_kEventWindowClose:
        {
            wm_window_close(C, wm, win);
            break;
        }
        case GHOST_kEventWindowUpdate:
        {
            if (G.debug & G_DEBUG_EVENTS) {
                printf("%s: ghost redraw %d\n", __func__, win->winid);
            }

            wm_window_make_drawable(wm, win);
            WM_event_add_notifier(C, NC_WINDOW, NULL);

            break;
        }
        case GHOST_kEventWindowSize:
        case GHOST_kEventWindowMove:
        {
            GHOST_TWindowState state;
            state = GHOST_GetWindowState(win->ghostwin);
            win->windowstate = state;

            /* stop screencast if resize */
            if (type == GHOST_kEventWindowSize) {
                WM_jobs_stop(wm, win->screen, NULL);
            }

            /* win32: gives undefined window size when minimized */
            if (state != GHOST_kWindowStateMinimized) {
                GHOST_RectangleHandle client_rect;
                int l, t, r, b, scr_w, scr_h;
                int sizex, sizey, posx, posy;

                client_rect = GHOST_GetClientBounds(win->ghostwin);
                GHOST_GetRectangle(client_rect, &l, &t, &r, &b);

                GHOST_DisposeRectangle(client_rect);

                wm_get_desktopsize(&scr_w, &scr_h);
                sizex = r - l;
                sizey = b - t;
                posx = l;
                posy = scr_h - t - win->sizey;

                /*
                 * Ghost sometimes send size or move events when the window hasn't changed.
                 * One case of this is using compiz on linux. To alleviate the problem
                 * we ignore all such event here.
                 *
                 * It might be good to eventually do that at Ghost level, but that is for
                 * another time.
                 */
                if (win->sizex != sizex ||
                        win->sizey != sizey ||
                        win->posx != posx ||
                        win->posy != posy)
                {
                    win->sizex = sizex;
                    win->sizey = sizey;
                    win->posx = posx;
                    win->posy = posy;

                    /* debug prints */
                    if (G.debug & G_DEBUG_EVENTS) {
                        const char *state_str;
                        state = GHOST_GetWindowState(win->ghostwin);

                        if (state == GHOST_kWindowStateNormal) {
                            state_str = "normal";
                        }
                        else if (state == GHOST_kWindowStateMinimized) {
                            state_str = "minimized";
                        }
                        else if (state == GHOST_kWindowStateMaximized) {
                            state_str = "maximized";
                        }
                        else if (state == GHOST_kWindowStateFullScreen) {
                            state_str = "fullscreen";
                        }
                        else {
                            state_str = "<unknown>";
                        }

                        printf("%s: window %d state = %s\n", __func__, win->winid, state_str);

                        if (type != GHOST_kEventWindowSize) {
                            printf("win move event pos %d %d size %d %d\n",
                                   win->posx, win->posy, win->sizex, win->sizey);
                        }
                    }

                    wm_window_make_drawable(wm, win);
                    wm_draw_window_clear(win);
                    WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
                    WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);

#if defined(__APPLE__) || defined(WIN32)
                    /* OSX and Win32 don't return to the mainloop while resize */
                    wm_event_do_handlers(C);
                    wm_event_do_notifiers(C);
                    wm_draw_update(C);
#endif
                }
            }
            break;
        }

        case GHOST_kEventOpenMainFile:
        {
            PointerRNA props_ptr;
            wmWindow *oldWindow;
            const char *path = GHOST_GetEventData(evt);

            if (path) {
                wmOperatorType *ot = WM_operatortype_find("WM_OT_open_mainfile", false);
                /* operator needs a valid window in context, ensures
                 * it is correctly set */
                oldWindow = CTX_wm_window(C);
                CTX_wm_window_set(C, win);

                WM_operator_properties_create_ptr(&props_ptr, ot);
                RNA_string_set(&props_ptr, "filepath", path);
                WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &props_ptr);
                WM_operator_properties_free(&props_ptr);

                CTX_wm_window_set(C, oldWindow);
            }
            break;
        }
        case GHOST_kEventDraggingDropDone:
        {
            wmEvent event;
            GHOST_TEventDragnDropData *ddd = GHOST_GetEventData(evt);
            int wx, wy;

            /* entering window, update mouse pos */
            wm_get_cursor_position(win, &wx, &wy);
            win->eventstate->x = wx;
            win->eventstate->y = wy;

            wm_event_init_from_window(win, &event);  /* copy last state, like mouse coords */

            /* activate region */
            event.type = MOUSEMOVE;
            event.prevx = event.x;
            event.prevy = event.y;

            wm->winactive = win; /* no context change! c->wm->windrawable is drawable, or for area queues */
            win->active = 1;

            wm_event_add(win, &event);


            /* make blender drop event with custom data pointing to wm drags */
            event.type = EVT_DROP;
            event.val = KM_RELEASE;
            event.custom = EVT_DATA_DRAGDROP;
            event.customdata = &wm->drags;
            event.customdatafree = 1;

            wm_event_add(win, &event);

            /* printf("Drop detected\n"); */

            /* add drag data to wm for paths: */

            if (ddd->dataType == GHOST_kDragnDropTypeFilenames) {
                GHOST_TStringArray *stra = ddd->data;
                int a, icon;

                for (a = 0; a < stra->count; a++) {
                    printf("drop file %s\n", stra->strings[a]);
                    /* try to get icon type from extension */
                    icon = ED_file_extension_icon((char *)stra->strings[a]);

                    WM_event_start_drag(C, icon, WM_DRAG_PATH, stra->strings[a], 0.0, WM_DRAG_NOP);
                    /* void poin should point to string, it makes a copy */
                    break; /* only one drop element supported now */
                }
            }

            break;
        }
        case GHOST_kEventNativeResolutionChange:
            // printf("change, pixel size %f\n", GHOST_GetNativePixelSize(win->ghostwin));

            U.pixelsize = wm_window_pixelsize(win);
            BKE_userdef_state();
            WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
            WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);

            break;
        case GHOST_kEventTrackpad:
        {
            GHOST_TEventTrackpadData *pd = data;

            wm_convert_cursor_position(win, &pd->x, &pd->y);
            wm_event_add_ghostevent(wm, win, type, time, data);
            break;
        }
        case GHOST_kEventCursorMove:
        {
            GHOST_TEventCursorData *cd = data;

            wm_convert_cursor_position(win, &cd->x, &cd->y);
            wm_event_add_ghostevent(wm, win, type, time, data);
            break;
        }
        default:
            wm_event_add_ghostevent(wm, win, type, time, data);
            break;
        }

    }
    return 1;
}
Ejemplo n.º 7
0
/* belongs to below */
static void wm_window_add_ghostwindow(wmWindowManager *wm, const char *title, wmWindow *win)
{
    GHOST_WindowHandle ghostwin;
    GHOST_GLSettings glSettings = {0};
    static int multisamples = -1;
    int scr_w, scr_h, posy;

    /* force setting multisamples only once, it requires restart - and you cannot
     * mix it, either all windows have it, or none (tested in OSX opengl) */
    if (multisamples == -1)
        multisamples = U.ogl_multisamples;

    glSettings.numOfAASamples = multisamples;

    /* a new window is created when pageflip mode is required for a window */
    if (win->stereo3d_format->display_mode == S3D_DISPLAY_PAGEFLIP)
        glSettings.flags |= GHOST_glStereoVisual;

    if (G.debug & G_DEBUG_GPU) {
        glSettings.flags |= GHOST_glDebugContext;
    }

    if (!(U.uiflag2 & USER_OPENGL_NO_WARN_SUPPORT))
        glSettings.flags |= GHOST_glWarnSupport;

    wm_get_screensize(&scr_w, &scr_h);
    posy = (scr_h - win->posy - win->sizey);

    ghostwin = GHOST_CreateWindow(g_system, title,
                                  win->posx, posy, win->sizex, win->sizey,
                                  (GHOST_TWindowState)win->windowstate,
                                  GHOST_kDrawingContextTypeOpenGL,
                                  glSettings);

    if (ghostwin) {
        GHOST_RectangleHandle bounds;

        /* the new window has already been made drawable upon creation */
        wm->windrawable = win;

        /* needed so we can detect the graphics card below */
        GPU_init();

        win->ghostwin = ghostwin;
        GHOST_SetWindowUserData(ghostwin, win); /* pointer back */

        if (win->eventstate == NULL)
            win->eventstate = MEM_callocN(sizeof(wmEvent), "window event state");

#ifdef __APPLE__
        /* set the state here, else OSX would not recognize changed screen resolution */
        /* we agreed to not set any fullscreen or iconized state on startup */
        GHOST_SetWindowState(ghostwin, GHOST_kWindowStateNormal);
#endif
        /* store actual window size in blender window */
        bounds = GHOST_GetClientBounds(win->ghostwin);
        win->sizex = GHOST_GetWidthRectangle(bounds);
        win->sizey = GHOST_GetHeightRectangle(bounds);
        GHOST_DisposeRectangle(bounds);

#ifndef __APPLE__
        /* set the state here, so minimized state comes up correct on windows */
        GHOST_SetWindowState(ghostwin, (GHOST_TWindowState)win->windowstate);
#endif
        /* until screens get drawn, make it nice gray */
        glClearColor(0.55, 0.55, 0.55, 0.0);
        /* Crash on OSS ATI: bugs.launchpad.net/ubuntu/+source/mesa/+bug/656100 */
        if (!GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_UNIX, GPU_DRIVER_OPENSOURCE)) {
            glClear(GL_COLOR_BUFFER_BIT);
        }

        /* displays with larger native pixels, like Macbook. Used to scale dpi with */
        /* needed here, because it's used before it reads userdef */
        U.pixelsize = wm_window_pixelsize(win);
        BKE_userdef_state();

        wm_window_swap_buffers(win);

        //GHOST_SetWindowState(ghostwin, GHOST_kWindowStateModified);

        /* standard state vars for window */
        glEnable(GL_SCISSOR_TEST);
        GPU_state_init();
    }
}
Ejemplo n.º 8
0
/* belongs to below */
static void wm_window_add_ghostwindow(const char *title, wmWindow *win)
{
	GHOST_WindowHandle ghostwin;
	static int multisamples = -1;
	int scr_w, scr_h, posy;
	
	/* force setting multisamples only once, it requires restart - and you cannot 
	 * mix it, either all windows have it, or none (tested in OSX opengl) */
	if (multisamples == -1)
		multisamples = U.ogl_multisamples;
	
	wm_get_screensize(&scr_w, &scr_h);
	posy = (scr_h - win->posy - win->sizey);
	
	ghostwin = GHOST_CreateWindow(g_system, title,
	                              win->posx, posy, win->sizex, win->sizey,
	                              (GHOST_TWindowState)win->windowstate,
	                              GHOST_kDrawingContextTypeOpenGL,
	                              0 /* no stereo */,
	                              multisamples /* AA */);
	
	if (ghostwin) {
		GHOST_RectangleHandle bounds;
		
		/* needed so we can detect the graphics card below */
		GPU_extensions_init();
		
		win->ghostwin = ghostwin;
		GHOST_SetWindowUserData(ghostwin, win); /* pointer back */
		
		if (win->eventstate == NULL)
			win->eventstate = MEM_callocN(sizeof(wmEvent), "window event state");
		
		/* set the state */
		GHOST_SetWindowState(ghostwin, (GHOST_TWindowState)win->windowstate);

		/* until screens get drawn, make it nice gray */
		glClearColor(0.55, 0.55, 0.55, 0.0);
		/* Crash on OSS ATI: bugs.launchpad.net/ubuntu/+source/mesa/+bug/656100 */
		if (!GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_UNIX, GPU_DRIVER_OPENSOURCE)) {
			glClear(GL_COLOR_BUFFER_BIT);
		}
		
		/* displays with larger native pixels, like Macbook. Used to scale dpi with */
		/* needed here, because it's used before it reads userdef */
		U.pixelsize = GHOST_GetNativePixelSize(win->ghostwin);
		BKE_userdef_state();
		
		/* store actual window size in blender window */
		bounds = GHOST_GetClientBounds(win->ghostwin);
		win->sizex = GHOST_GetWidthRectangle(bounds);
		win->sizey = GHOST_GetHeightRectangle(bounds);
		GHOST_DisposeRectangle(bounds);

		
		wm_window_swap_buffers(win);
		
		//GHOST_SetWindowState(ghostwin, GHOST_kWindowStateModified);
		
		/* standard state vars for window */
		glEnable(GL_SCISSOR_TEST);
		GPU_state_init();
	}
}