Esempio n. 1
0
void Window::_processEvent(const SDL_WindowEvent& event) {
	log().debug("Window event: ", _sdlWindowEventName(event.event));

	switch(event.event) {
	case SDL_WINDOWEVENT_SHOWN:
	case SDL_WINDOWEVENT_HIDDEN:
	case SDL_WINDOWEVENT_EXPOSED:
	case SDL_WINDOWEVENT_MOVED:
	case SDL_WINDOWEVENT_SIZE_CHANGED:
	case SDL_WINDOWEVENT_MINIMIZED:
	case SDL_WINDOWEVENT_MAXIMIZED:
	case SDL_WINDOWEVENT_RESTORED:
	case SDL_WINDOWEVENT_ENTER:
	case SDL_WINDOWEVENT_LEAVE:
	case SDL_WINDOWEVENT_FOCUS_GAINED:
	case SDL_WINDOWEVENT_RESIZED:
		onResize();
		break;
	case SDL_WINDOWEVENT_FOCUS_LOST:
		break;
	case SDL_WINDOWEVENT_CLOSE:
		break;

	default:
		log().warning("Unknown SDL window event: ", event.type);
		break;
	}
}
Esempio n. 2
0
void display() {
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    /*
     * See drawing.c for the definition of these routines.
     *
     * Note: Only one should be called at a time (based on the
     * display mode).
     */
    
    if (drawing3D()) {
        lightSource(true);
        draw3DModel();
    } // if
    
    else {
        lightSource(false);
        drawSurface();
    } // else

    glFlush();  /* Flush all executed OpenGL ops finish */

    onResize();

    /*
     * Since we are using double buffers, we need to call the swap
     * function every time we are done drawing.
     */
    glutSwapBuffers();
}
Esempio n. 3
0
LRESULT App::onMessage( UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message )
	{
	case WM_SIZE:
		{
			onResize( LOWORD( lParam ), HIWORD( lParam ) );
			return 0;
		}
		break;

	case WM_COMMAND:
		{
			WORD menu_id = LOWORD( wParam );
			onMenuCommand( menu_id );
		}
		break;

	case WM_CLOSE:
		{
			/// first release the App, it will destroy everything except the Window.
			/// when the Game thread exit, it will post a WM_DESTROY message to exit the program safely.
			release();
			return 0;
		}
	case WM_DESTROY:
		{
			::PostQuitMessage( 0 );
			return 0;
		}
	}

	return klwin::Window::handleDefaultMessage( message, wParam, lParam );
}
Esempio n. 4
0
void SDLWindow::updateSize(bool reinit) {
	
	const SDL_VideoInfo * vid = SDL_GetVideoInfo();
	
	DisplayMode oldMode(size_, depth_);
	
	size_ = Vec2i(vid->current_w, vid->current_h);
	depth_ = vid->vfmt->BitsPerPixel;
	
	// Finally, set the viewport for the newly created device
	arx_assert(renderer != NULL);
	
#if ARX_PLATFORM == ARX_PLATFORM_WIN32
	// use reinit as-is
#elif ARX_PLATFORM == ARX_PLATFORM_LINUX || ARX_PLATFORM == ARX_PLATFORM_BSD
	reinit = false; // Never needed under linux & bsd
#else
	reinit = true; // By default, always reinit to avoid issues on untested platforms
#endif
	
	if(reinit && !reinterpret_cast<OpenGLRenderer *>(renderer)->isInitialized()) {
		reinterpret_cast<OpenGLRenderer *>(renderer)->reinit();
		renderer->SetViewport(Rect(size_.x, size_.y));
		onRendererInit();
	} else {
		renderer->SetViewport(Rect(size_.x, size_.y));
	}
	
	if(size_ != oldMode.resolution) {
		onResize(size_.x, size_.y);
	}
}
Esempio n. 5
0
	LRESULT Win32Window::wndProc(UINT msg, WPARAM wParam, LPARAM lParam) {
		if(msg == WM_CLOSE) {
			PostQuitMessage(0);
		}

		switch(msg) {
		case WM_SIZE:
			onResize(ResizeEvent(LOWORD(lParam), HIWORD(lParam)));
			break;

		case WM_KEYDOWN:
			onKeyDown(KeyEvent(wParam));
			break;

		case WM_KEYUP:
			onKeyUp(KeyEvent(wParam));
			break;

		case WM_MOUSEMOVE:
			POINTS pt = MAKEPOINTS(lParam);
			break;
		}

		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
Esempio n. 6
0
void Window::initDirect3D()
{
	//Create swap chain.
	DXGI_SWAP_CHAIN_DESC sd;
	sd.BufferDesc.Width  = windowWidth;
	sd.BufferDesc.Height = windowHeight;
	sd.BufferDesc.RefreshRate.Numerator = 60;
	sd.BufferDesc.RefreshRate.Denominator = 1;
	sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
	sd.SampleDesc.Count   = 1;
	sd.SampleDesc.Quality = 0;
	sd.BufferUsage  = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	sd.BufferCount  = 1;
	sd.OutputWindow = hMainWnd;
	sd.Windowed     = true;
	sd.SwapEffect   = DXGI_SWAP_EFFECT_DISCARD;
	sd.Flags        = 0;


	//Create DirectX device.
	UINT createDeviceFlags = 0;
#if defined(DEBUG) || defined(_DEBUG)  
    createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
#endif
	HR(D3D10CreateDeviceAndSwapChain(0, d3dDriverType, 0, createDeviceFlags, D3D10_SDK_VERSION, &sd, &swapChain, &d3dDevice));


	//Create backbuffer etc, used here to prevents duplication of code
	onResize();
}
Esempio n. 7
0
void
processEvents(void) {
	while (XPending(x_dpy)) {
		XEvent ev;
		XNextEvent(x_dpy, &ev);
		switch (ev.type) {
		case ButtonPress:
			onTouchBegin((float)ev.xbutton.x, (float)ev.xbutton.y);
			break;
		case ButtonRelease:
			onTouchEnd((float)ev.xbutton.x, (float)ev.xbutton.y);
			break;
		case MotionNotify:
			onTouchMove((float)ev.xmotion.x, (float)ev.xmotion.y);
			break;
		case ConfigureNotify:
			onResize(ev.xconfigure.width, ev.xconfigure.height);
			break;
		case ClientMessage:
			if (wm_delete_window != None && (Atom)ev.xclient.data.l[0] == wm_delete_window) {
				onStop();
				return;
			}
			break;
		}
	}
}
Esempio n. 8
0
void Win32Window::setWindowSize(Vec2i size) {
	
	SetWindowLong(m_hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);
	
	depth_ = 0;
	
	DWORD windowStyle = WS_OVERLAPPEDWINDOW;
	DWORD windowExtendedStyle = WS_EX_APPWINDOW;
	
	RECT rcWnd;
	
	SetRect(&rcWnd, 0, 0, size.x, size.y);
	AdjustWindowRectEx(&rcWnd, windowStyle, GetMenu(m_hWnd) != NULL, windowExtendedStyle);
	
	int dx = rcWnd.right - rcWnd.left - size.x;
	int dy = rcWnd.bottom - rcWnd.top - size.y;
	
	SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, size.x + dx, size.y + dy, SWP_SHOWWINDOW);
	
	if(isFullscreen_) {
		isFullscreen_ = false;
		onToggleFullscreen();
	}
	
	onResize(size.x, size.y);
}
Esempio n. 9
0
void ControlResizer::onResize() const
{
	GetClientRect(window->hWnd, &window->newRect);
	onResize(window);
	window->oldRect = window->newRect;
	RedrawWindow(window->hWnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW);
}
Esempio n. 10
0
void v_window::_updateOSWindow() {
    xcb_generic_event_t* event = xcb_poll_for_event(_xcb_connection);   //非阻塞的方式接收事件 xcb_wait_for_event为阻塞式
    if(!event){
        return;
    }
    switch(event->response_type & ~0x80){
        case XCB_CLIENT_MESSAGE:
            if( ( (xcb_client_message_event_t*)event )->data.data32[ 0 ] == _xcb_atom_window_reply->atom ) {
                close();
            }
            break;
        case XCB_CONFIGURE_NOTIFY:
            if(xcb_configure_notify_event_t* cfg = (xcb_configure_notify_event_t*)event){
                if(_width != cfg->width || _height != cfg->height) {
                    _width = cfg->width;
                    _height = cfg->height;
                    vkDeviceWaitIdle(_renderer->getDevice());
                    _initSwapchain();
                    _initSwapchainImageViews();
                    if (onResize != nullptr) {
                        onResize(_width, _height);
                    }
                }
            }
            break;
        default:
            break;
    }

    free(event);
}
Esempio n. 11
0
void UIView::setSize(float width, float height)
{
	// -- This control is about to be resized, might need to do some automatic operations on children
	processSizeChange(mRect.width, mRect.height, width, height);

	float pX = mRect.width;
	float pY = mRect.height;

	mRect.width = width;
	mRect.height = height;
	
	onResize();

	onSizeChanged();

	updateLayout();

	// Let components know a resize was made
	for(std::size_t i = 0; i < components.size(); ++i)
	{
		components[i]->onResize(this);
	}

	size.x = width;
	size.y = height;

	// lets try to notify the parent layouters 
	if (getParent() && getParent()->getLayout())
	{
		//getParent()->getLayout()->doLayout(getParent());
	}
};
Esempio n. 12
0
void SDLWindow::handleWindowEvent() {
    switch (m_sdlEvent.window.event) {
        case SDL_WINDOWEVENT_MOVED:
            onMove(m_sdlEvent.window.data1, m_sdlEvent.window.data2);
            break;
        case SDL_WINDOWEVENT_RESIZED:
        case SDL_WINDOWEVENT_SIZE_CHANGED:
            onResize(m_sdlEvent.window.data1, m_sdlEvent.window.data2);
            break;
        case SDL_WINDOWEVENT_MINIMIZED:
            onMinimize();
            break;
        case SDL_WINDOWEVENT_MAXIMIZED:
            onMaximize();
            break;
        case SDL_WINDOWEVENT_RESTORED:
            onRestore();
            break;
		case SDL_WINDOWEVENT_SHOWN:
			onDisplay();
			break;
        default:
            break;
    }
}
Esempio n. 13
0
//------------------------------------------------------------------------------
// SDL event handeling by type, asynchronously called to handle events
//------------------------------------------------------------------------------
void Client::onEvent(SDL_Event* event) {
	switch (event->type) {
		case SDL_QUIT:
			running = false;
			break;
		case SDL_VIDEORESIZE:
			onResize(event->resize.w, event->resize.h);
			break;
		case SDL_KEYDOWN:
			keys[event->key.keysym.sym] = true;
			break;
		case SDL_KEYUP:
			keys[event->key.keysym.sym] = false;

			// toggle follow mode
			if (event->key.keysym.sym == SDLK_f) {
				follow = !follow;
			}
			break;
		case SDL_MOUSEMOTION:
			xMouse = event->motion.x;
			yMouse = event->motion.y;
			break;
        case SDL_MOUSEBUTTONDOWN:
            mbts[event->button.button] = true;
            break;
        case SDL_MOUSEBUTTONUP:
            mbts[event->button.button] = false;
            break;
		default:
			break;
	}
}
Esempio n. 14
0
void SdlApp::handleInput()
{
	SDL_Event sdlEvent;

	while (SDL_PollEvent(&sdlEvent) != 0)
	{
		if (sdlEvent.type == SDL_QUIT)
			setExitFlag();
		else if (sdlEvent.type == SDL_KEYDOWN)
			onKeyDown(sdlEvent.key.keysym.sym);
		else if (sdlEvent.type == SDL_WINDOWEVENT)
		{
			switch (sdlEvent.window.event)
			{
			case SDL_WINDOWEVENT_RESIZED:
				// Handle resize
				mWindowWidth = sdlEvent.window.data1;
				mWindowHeight = sdlEvent.window.data2;
				onResize(mWindowWidth, mWindowHeight);
				break;
			case SDL_WINDOWEVENT_EXPOSED:
				draw();
			}

		}
	}
}
Esempio n. 15
0
bool windowOGL::initOGL()
{
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glEnable(GL_DEPTH_TEST);
	glClearStencil(0);                          // clear stencil buffer
	glClearDepth(1.0f);                         // 0 is near, 1 is far
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_TEXTURE_2D); //enable 2D texturing
	glEnable(GL_LIGHTING);
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_LIGHT0);
	glEnable(GL_AMBIENT);
	glColor3f(1,1,1);
	GLfloat lightpos[] = {currentX,0,-100};
	glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
	
	
	onResize(1024, 768);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45, 1, 1, 1000);

    //Return success
    return true;
}
Esempio n. 16
0
void AbstractWindow::resize( ui32 x, ui32 y, ui32 w, ui32 h ) {
    if ( !m_isCreated ) {
        osre_warn( Tag, "Surface not valid, cannot be resized." );
        return;
    }

    onResize( x, y, w, h );
}
Esempio n. 17
0
void Window::
fakeResizeCallback()
{
    int width, height;
    Window* window = main_window_.get();
    glfwGetWindowSize(window->glfw_handle_, &width, &height);
    onResize(window->glfw_handle_, width, height);
}
void GUIController::setFullscreen(bool full, bool adjustOverlay)
{
    m_isFullscreen = full;
    SDL_SetWindowFullscreen(m_window, full ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
    int w, h;
    SDL_GetWindowSize(m_window, &w, &h);
    onResize((size_t)w, (size_t)h, adjustOverlay);
}
Esempio n. 19
0
bool Window::filterEvent(const Event& event)
{
    // Notify resize events to the derived class
    if (event.type == Event::Resized)
        onResize();

    return true;
}
Esempio n. 20
0
HRESULT DXRender::resetDevice()
{
	HRESULT hr = S_OK;

	if (isDeviceReady())
		return D3D_OK;
	
	if (!shouldResetDevice())
		return D3DERR_DEVICELOST;
	
	texMgr->onPowerSuspend();
	menuManager->onRelease();
	scnManager->onRelease();
	hr = releaseResources();
	if (FAILED(hr))
	{
		LOG(QString_NT("Could not release resources after device was lost: hr = %1").arg(hr));
		return hr;
	}
	
	LOG(QString_NT("Started resetting the device"));
	hr = device->Reset(&_dummyDevicePresentationParameters);
	if (FAILED(hr))
	{
		LOG(QString_NT("Could not reset the device: hr = %1").arg(hr));
		if (hr == D3DERR_INVALIDCALL)
		{
			device->AddRef();
			ULONG ref = device->Release();
			LOG(QString_NT("Ref Count: %1").arg(ref));
		}
		return hr;
	}
	LOG(QString_NT("Finished resetting the device"));
	
	LOG(QString_NT("Start recreating resources"));
	hr = recreateResources();
	if (FAILED(hr))
	{
		LOG(QString_NT("Could not recreate resources after device was lost: hr = %1").arg(hr));
		return hr;
	}
	LOG(QString_NT("Finish recreating resources"));

	texMgr->onPowerResume();
	
	ResizeWallsToWorkArea(winOS->GetWindowWidth(), winOS->GetWindowHeight());

	// Recreate the swap chain
	hr = onResize(winOS->GetWindowWidth(), winOS->GetWindowHeight());

	if (SUCCEEDED(hr))
	{
		LOG(QString_NT("%1: Device reset successfully").arg(timeGetTime()));
		_deviceLost = false;
	}
	return hr;
}
Esempio n. 21
0
void GUIObject::setSize(const GSize& size)
{
    if (size != m_size)
    {
        GSize szOld = m_size;
        m_size = size;
        onResize(szOld, size);
    }
}
Esempio n. 22
0
void Window::setSize(const Vector2u &size) {
    if (mBase) {
        mBase->setSize(size);

        mSize.x = size.x;
        mSize.y = size.y;

        onResize();
    }
}
Esempio n. 23
0
void Widget::setSize(sf::Vector2f size)
{
	if (mySize != size)
	{
		mySize = size;

		onResize();
		notify(NotifyResized);
	}
}
void Application::onWindowSize(int width, int height) {
    if (context->getScreenWidth() != width || context->getScreenHeight() != height) {
        context->screenSize = int2(width, height);
        context->dirtyUI = true;
        context->requestPack();
        if (onResize) {
            onResize(context->viewSize);
        }
    }
}
    void BasicRenderer::handleInput()
    {
	    if(m_width != m_viewportWidth || m_height != m_viewportHeight)
	    {
		    m_width = m_viewportWidth;
		    m_height = m_viewportHeight;

		    onResize();
	    }
    }
Esempio n. 26
0
bool Window::filterEvent(const WindowEvent &event) {
    if (event.type == WindowEvent::Resized) {
        mSize.x = event.size.width;
        mSize.y = event.size.height;

        onResize();
    }

    return true;
}
Esempio n. 27
0
void Widget::setSize(float width, float height)
{
	if (mySize.x != width || mySize.y != height)
	{
		mySize.x = width;
		mySize.y = height;

		onResize();
		notify(NotifyResized);
	}
}
Esempio n. 28
0
	LRESULT onMessage(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
	{
		switch (msg)
		{
			case WM_CLOSE: PostQuitMessage(0); break;
			case WM_MOVE:
			case WM_SIZE: onResize(); break;
			case WM_QUIT: m_finished = true; break;
			case WM_INPUT: handleRawInput(lparam); break;
		}
		return DefWindowProc(hwnd, msg, wparam, lparam);
	}
Esempio n. 29
0
	bool CSLevel::OnUserEvent(const SEvent& e)
	{
		switch (e.UserEvent.UserData1)
		{
			// window resize event
			case CS_SCREENWASRESIZED: 
			{
				onResize();
				return true;
			}
		}
		return CSEventHandler::OnUserEvent(e);
	}
Esempio n. 30
0
/**
* @param width - устанавливаемая ширина.
* @param height - устанавливаемая высота.
*/
void CalendarItem::setSize(qreal width, qreal height)
{
    if(width != myBoundingRect.width() || height != myBoundingRect.height())
    {
        prepareGeometryChange(); //Подготавливаем элемент для смены геометрии.
        QSizeF old = myBoundingRect.size();//Запоминаем старый размер
        QSizeF size(width, height); //Новый размер
        myBoundingRect.setWidth(width); //устанавливаем новую ширину
        myBoundingRect.setHeight(height); //и высоту
        onResize(size, old); //Взываем обработчик перерисовки
        update(); //перерисовка области элемента
    }
}