コード例 #1
0
ファイル: input.cpp プロジェクト: nyorain/ny
void WinapiMouseContext::over(WinapiWindowContext* wc)
{
	if(wc == over_) return;

	onFocus(*this, over_, wc);
	over_ = wc;
}
コード例 #2
0
ファイル: field.cpp プロジェクト: Ircher/CBoE
bool cTextField::triggerFocusHandler(cDialog& me, std::string id, bool losingFocus){
	if(losingFocus && field_type != FLD_TEXT) {
		try {
			std::string contents = getText();
			switch(field_type) {
				case FLD_TEXT: break;
				case FLD_INT:
					boost::lexical_cast<long long>(contents);
					break;
				case FLD_UINT:
					boost::lexical_cast<unsigned long long>(contents);
					break;
				case FLD_REAL:
					boost::lexical_cast<long double>(contents);
					break;
			}
		} catch(boost::bad_lexical_cast) {
			static const std::map<const eFldType, const std::string> typeNames = {
				{FLD_INT, "an integer"},
				{FLD_UINT, "a positive integer"},
				{FLD_REAL, "a number"},
			};
			giveError("You need to enter " + typeNames.at(field_type) + "!","",parent);
			return false;
		}
	}
	bool passed = true;
	if(onFocus != NULL) passed = onFocus(me,id,losingFocus);
	if(passed) haveFocus = !losingFocus;
	if(haveFocus && insertionPoint < 0)
		insertionPoint = getText().length();
	return passed;
}
コード例 #3
0
ファイル: Button.cpp プロジェクト: eggtart93/LuckyDraw
    void Button::update(const sf::RenderWindow& window)
    {
        if (!isFocusable())
        {
            onLock();
            updateAppearance();
            return;
        }

        sf::Vector2i mousePos = sf::Mouse::getPosition(window);
        bool isMouseOn = mousePos.x >= (getGlobalPosition().x - getWidth() * .5f)
                        && mousePos.x <= (getGlobalPosition().x + getWidth() * .5f)
                        && mousePos.y >= (getGlobalPosition().y - getHeight() * .5f)
                        && mousePos.y <= (getGlobalPosition().y + getHeight() * .5f);
        if (isMouseOn)
        {
            if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
            {
                onPress();
            }
            else
            {
                if(mState == Button::OnPressed) { onClick(); }
                onFocus();
            }
        }
        else
        {
            lostFocus();
        }
        updateAppearance();
    }
コード例 #4
0
/**
 * IComponent version handles MSG_FOCUS, MSG_UNFOCUS and MSG_KILL.
 * Any other message is passed to onHandleMessage.
 */
void IComponent::handleMessage(int msg)
{
	switch (msg)
	{
	case MSG_FOCUS:
		awake = true;
		visible = true;
		onFocus();
		break;
	case MSG_UNFOCUS:
		awake = false;
		visible = false;
		break;
	case MSG_KILL:
		kill();
		break;
	default:
		bool handled = onHandleMessage(msg);
		if (!handled)
		{
			pushMsg(msg); // let parent handle it.
		}
		break;
	}

}
コード例 #5
0
CommandDlg::CommandDlg(dwt::Widget* parent, int type_, int ctx_, const tstring& name_, const tstring& command_, const tstring& hub_) :
	WidgetFactory<dwt::ModalDialog>(parent),
	separator(0),
	raw(0),
	chat(0),
	PM(0),
	hubMenu(0),
	userMenu(0),
	searchMenu(0),
	fileListMenu(0),
	nameBox(0),
	commandBox(0),
	hubBox(0),
	nick(0),
	once(0),
	result(0),
	openHelp(0),
	type(type_),
	ctx(ctx_),
	name(name_),
	command(command_),
	hub(hub_)
{
	onInitDialog(std::tr1::bind(&CommandDlg::handleInitDialog, this));
	onFocus(std::tr1::bind(&CommandDlg::handleFocus, this));
	onHelp(std::tr1::bind(&WinUtil::help, _1, _2));
}
コード例 #6
0
ファイル: input.cpp プロジェクト: nyorain/ny
void WinapiKeyboardContext::focus(WinapiWindowContext* wc)
{
	if(wc == focus_) return;

	onFocus(*this, focus_, wc);
	focus_ = wc;
}
コード例 #7
0
void ofxDatGuiComponent::setFocused(bool focused)
{
    if (focused){
        onFocus();
    }   else{
        onFocusLost();
    }
}
コード例 #8
0
ファイル: x11.c プロジェクト: destenson/keybase--client
void
processEvents() {
	while (XPending(x_dpy)) {
		XEvent ev;
		XNextEvent(x_dpy, &ev);
		switch (ev.type) {
		case KeyPress:
		case KeyRelease:
			onKey(ev.xkey.window, ev.xkey.state, ev.xkey.keycode, ev.type == KeyPress ? 1 : 2);
			break;
		case ButtonPress:
		case ButtonRelease:
			onMouse(ev.xbutton.window, ev.xbutton.x, ev.xbutton.y, ev.xbutton.state, ev.xbutton.button,
				ev.type == ButtonPress ? 1 : 2);
			break;
		case MotionNotify:
			onMouse(ev.xmotion.window, ev.xmotion.x, ev.xmotion.y, ev.xmotion.state, 0, 0);
			break;
		case FocusIn:
		case FocusOut:
			onFocus(ev.xmotion.window, ev.type == FocusIn);
			break;
		case Expose:
			// A non-zero Count means that there are more expose events coming. For
			// example, a non-rectangular exposure (e.g. from a partially overlapped
			// window) will result in multiple expose events whose dirty rectangles
			// combine to define the dirty region. Go's paint events do not provide
			// dirty regions, so we only pass on the final X11 expose event.
			if (ev.xexpose.count == 0) {
				onExpose(ev.xexpose.window);
			}
			break;
		case ConfigureNotify:
			onConfigure(ev.xconfigure.window, ev.xconfigure.x, ev.xconfigure.y,
				ev.xconfigure.width, ev.xconfigure.height,
				DisplayWidth(x_dpy, DefaultScreen(x_dpy)),
				DisplayWidthMM(x_dpy, DefaultScreen(x_dpy)));
			break;
		case ClientMessage:
			if ((ev.xclient.message_type != wm_protocols) || (ev.xclient.format != 32)) {
				break;
			}
			Atom a = ev.xclient.data.l[0];
			if (a == wm_delete_window) {
				onDeleteWindow(ev.xclient.window);
			} else if (a == wm_take_focus) {
				XSetInputFocus(x_dpy, ev.xclient.window, RevertToParent, ev.xclient.data.l[1]);
			}
			break;
		}
	}
}
コード例 #9
0
void ofxDatGuiComponent::update(bool acceptEvents)
{
// if window does not have focus x & y will both be zero //
    if (acceptEvents && mEnabled && mVisible){
        bool mp = ofGetMousePressed();
        ofPoint mouse = ofPoint(ofGetMouseX() - mParentPosition.x, ofGetMouseY() - mParentPosition.y);
        if (hitTest(mouse)){
            if (!mMouseOver){
                onMouseEnter(mouse);
            }
            if (!mMouseDown && mp){
                onMousePress(mouse);
                if (!mFocused) onFocus();
            }
        }   else{
    // the mouse is not over the component //
            if (mMouseOver){
                onMouseLeave(mouse);
            }
            if (!mMouseDown && mp && mFocused){
                onFocusLost();
            }
        }
        if (mMouseDown) {
            if (mp){
                onMouseDrag(mouse);
            }   else{
                onMouseRelease(mouse);
            }
        }
    }
// don't update children unless they're visible //
    if (this->getIsExpanded()) {
        for(int i=0; i<children.size(); i++) {
            children[i]->update(acceptEvents);
            if (children[i]->getFocused()){
                if (acceptEvents == false ) children[i]->setFocused(false);
                acceptEvents = false;
            }
        }
    }
}
コード例 #10
0
void
SoXipMenuItemBase::fieldChanged( SoField* whichField )
{
    if( whichField == &focused )
    {
		onFocus();       
    }
    else if( whichField == &enabled )
    {
		onEnable();
    }
	else if( whichField == &caption )
    {
		updateCaption();
    }
	else if( whichField == &icon )
    {
		updateIcon();
    }
}
コード例 #11
0
ファイル: SDL2Window.cpp プロジェクト: striezel/ArxLibertatis
void SDL2Window::tick() {

    SDL_Event event;
    while(SDL_PollEvent(&event)) {

        switch(event.type) {

        case SDL_WINDOWEVENT: {
            switch(event.window.event) {

            case SDL_WINDOWEVENT_SHOWN:
                onShow(true);
                break;
            case SDL_WINDOWEVENT_HIDDEN:
                onShow(false);
                break;
            case SDL_WINDOWEVENT_EXPOSED:
                onPaint();
                break;
            case SDL_WINDOWEVENT_MINIMIZED:
                onMinimize();
                break;
            case SDL_WINDOWEVENT_MAXIMIZED:
                onMaximize();
                break;
            case SDL_WINDOWEVENT_RESTORED:
                onRestore();
                break;
            case SDL_WINDOWEVENT_FOCUS_GAINED:
                onFocus(true);
                break;
            case SDL_WINDOWEVENT_FOCUS_LOST:
                onFocus(false);
                break;

            case SDL_WINDOWEVENT_MOVED: {
                onMove(event.window.data1, event.window.data2);
                break;
            }

            case SDL_WINDOWEVENT_SIZE_CHANGED: {
                Vec2i newSize(event.window.data1, event.window.data2);
                if(newSize != m_size && !m_fullscreen) {
                    m_renderer->beforeResize(false);
                    updateSize();
                } else {
                    // SDL regrettably sends resize events when a fullscreen window
                    // is minimized - we'll have none of that!
                }
                break;
            }

            case SDL_WINDOWEVENT_CLOSE: {
                // The user has requested to close a single window
                // TODO we only support one main window for now
                break;
            }

            }
            break;
        }

        case SDL_QUIT: {
            // The user has requested to close the whole program
            // TODO onDestroy() fits SDL_WINDOWEVENT_CLOSE better, but SDL captures Ctrl+C
            // evenst and *only* sends the SDL_QUIT event for them while normal close
            // generates *both* SDL_WINDOWEVENT_CLOSE and SDL_QUIT
            onDestroy();
            return; // abort event loop!
        }

        }

        if(m_input) {
            m_input->onEvent(event);
        }

    }

    if(!m_renderer->isInitialized()) {
        updateSize();
        m_renderer->afterResize();
        m_renderer->SetViewport(Rect(m_size.x, m_size.y));
    }
}
コード例 #12
0
ファイル: SDL2Window.cpp プロジェクト: striezel/ArxLibertatis
bool SDL2Window::initialize() {

    arx_assert(!m_displayModes.empty());

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

#if ARX_PLATFORM == ARX_PLATFORM_WIN32
    // Used on Windows to prevent software opengl fallback.
    // The linux situation:
    // Causes SDL to require visuals without caveats.
    // On linux some drivers only supply multisample capable GLX Visuals
    // with a GLX_NON_CONFORMANT_VISUAL_EXT caveat.
    // see: https://www.opengl.org/registry/specs/EXT/visual_rating.txt
    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
#endif

    // TODO EGL and core profile are not supported yet
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);

    if(gldebug::isEnabled()) {
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
    }


    int x = SDL_WINDOWPOS_UNDEFINED, y = SDL_WINDOWPOS_UNDEFINED;
    Uint32 windowFlags = getSDLFlagsForMode(m_size, m_fullscreen);
    windowFlags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;

    for(int msaa = m_maxMSAALevel; msaa > 0; msaa--) {
        bool lastTry = (msaa == 1);

        // Cleanup context and window from previous tries
        if(m_glcontext) {
            SDL_GL_DeleteContext(m_glcontext);
            m_glcontext = NULL;
        }
        if(m_window) {
            SDL_DestroyWindow(m_window);
            m_window = NULL;
        }

        SDL_ClearError();

        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, msaa > 1 ? 1 : 0);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa > 1 ? msaa : 0);

        m_window = SDL_CreateWindow(m_title.c_str(), x, y, m_size.x, m_size.y, windowFlags);
        if(!m_window) {
            if(lastTry) {
                LogError << "Could not create window: " << SDL_GetError();
                return false;
            }
            continue;
        }

        m_glcontext = SDL_GL_CreateContext(m_window);
        if(!m_glcontext) {
            if(lastTry) {
                LogError << "Could not create GL context: " << SDL_GetError();
                return false;
            }
            continue;
        }

        // Verify that the MSAA setting matches what was requested
        int msaaEnabled, msaaValue;
        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &msaaEnabled);
        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msaaValue);
        if(!lastTry) {
            if(!msaaEnabled || msaaValue < msaa) {
                continue;
            }
        }
        if(msaaEnabled) {
            m_MSAALevel = msaaValue;
        } else {
            m_MSAALevel = 0;
        }

        // Verify that we actually got an accelerated context
        (void)glGetError(); // clear error flags
        GLint texunits = 0;
        glGetIntegerv(GL_MAX_TEXTURE_UNITS, &texunits);
        if(glGetError() != GL_NO_ERROR || texunits < GLint(m_minTextureUnits)) {
            if(lastTry) {
                LogError << "Not enough GL texture units available: have " << texunits
                         << ", need at least " << m_minTextureUnits;
                return false;
            }
            continue;
        }

        // All good
        const char * system = "(unknown)";
        {
            ARX_SDL_SysWMinfo info;
            info.version.major = 2;
            info.version.minor = 0;
            info.version.patch = 4;
            if(SDL_GetWindowWMInfo(m_window, reinterpret_cast<SDL_SysWMinfo *>(&info))) {
                switch(info.subsystem) {
                case ARX_SDL_SYSWM_UNKNOWN:
                    break;
                case ARX_SDL_SYSWM_WINDOWS:
                    system = "Windows";
                    break;
                case ARX_SDL_SYSWM_X11:
                    system = "X11";
                    break;
#if SDL_VERSION_ATLEAST(2, 0, 3)
                case ARX_SDL_SYSWM_WINRT:
                    system = "WinRT";
                    break;
#endif
                case ARX_SDL_SYSWM_DIRECTFB:
                    system = "DirectFB";
                    break;
                case ARX_SDL_SYSWM_COCOA:
                    system = "Cocoa";
                    break;
                case ARX_SDL_SYSWM_UIKIT:
                    system = "UIKit";
                    break;
#if SDL_VERSION_ATLEAST(2, 0, 2)
                case ARX_SDL_SYSWM_WAYLAND:
                    system = "Wayland";
                    break;
                case ARX_SDL_SYSWM_MIR:
                    system = "Mir";
                    break;
#endif
#if SDL_VERSION_ATLEAST(2, 0, 4)
                case ARX_SDL_SYSWM_ANDROID:
                    system = "Android";
                    break;
#endif
                }
            }
        }

        int red = 0, green = 0, blue = 0, alpha = 0, depth = 0, doublebuffer = 0;
        SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &red);
        SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &green);
        SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &blue);
        SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &alpha);
        SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depth);
        SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer);
        LogInfo << "Window: " << system << " r:" << red << " g:" << green << " b:" << blue
                << " a:" << alpha << " depth:" << depth << " aa:" << msaa << "x"
                << " doublebuffer:" << doublebuffer;
        break;
    }

    // Use the executable icon for the window
#if ARX_PLATFORM == ARX_PLATFORM_WIN32
    {
        SDL_SysWMinfo info;
        SDL_VERSION(&info.version);
        if(SDL_GetWindowWMInfo(m_window, &info) && info.subsystem == SDL_SYSWM_WINDOWS) {
            platform::WideString filename;
            filename.allocate(filename.capacity());
            while(true) {
                DWORD size = GetModuleFileNameW(NULL, filename.data(), filename.size());
                if(size < filename.size()) {
                    filename.resize(size);
                    break;
                }
                filename.allocate(filename.size() * 2);
            }
            HICON largeIcon = 0;
            HICON smallIcon = 0;
            ExtractIconExW(filename, 0, &largeIcon, &smallIcon, 1);
            if(smallIcon) {
                SendMessage(info.info.win.window, WM_SETICON, ICON_SMALL, LPARAM(smallIcon));
            }
            if(largeIcon) {
                SendMessage(info.info.win.window, WM_SETICON, ICON_BIG, LPARAM(largeIcon));
            }
        }
    }
#endif

    setVSync(m_vsync);

    SDL_ShowWindow(m_window);
    SDL_ShowCursor(SDL_DISABLE);

    m_renderer->initialize();

    onCreate();
    onToggleFullscreen(m_fullscreen);
    updateSize(true);

    onShow(true);
    onFocus(true);

    return true;
}
コード例 #13
0
ファイル: ViewerWindow.cpp プロジェクト: Aliceljm1/TightVNC-1
bool ViewerWindow::onMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
	case WM_SIZING:
		m_sizeIsChanged = true;
		return false;
	case WM_NCDESTROY:
		m_stopped = true;
		return true;
	case WM_USER_STOP:
		SendMessage(m_hWnd, WM_DESTROY, 0, 0);
		return true;
	case WM_USER_FS_WARNING:
		return onFsWarning();
	case WM_CLOSE:
		return onClose();
	case WM_DESTROY:
		return onDestroy();
	case WM_CREATE:
		return onCreate((LPCREATESTRUCT)lParam);
	case WM_SIZE:
		return onSize(wParam, lParam);
	case WM_USER_AUTH_ERROR:
		return onAuthError(wParam);
	case WM_USER_ERROR:
		return onError();
	case WM_USER_DISCONNECT:
		return onDisconnect();
	case WM_ACTIVATE:
		if ((LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE) && m_isFullScr) {
			try {
				// Registration of keyboard hook.
				m_winHooks.registerKeyboardHook(this);
				// Switching off ignoring win key.
				m_dsktWnd.setWinKeyIgnore(false);
			}
			catch (Exception &e) {
				m_logWriter.error(_T("%s"), e.getMessage());
			}
		}
		else if (LOWORD(wParam) == WA_INACTIVE && m_isFullScr) {
			// Unregistration of keyboard hook.
			m_winHooks.unregisterKeyboardHook(this);
			// Switching on ignoring win key.
			m_dsktWnd.setWinKeyIgnore(true);
		}
		return true;
	case WM_SETFOCUS:
		return onFocus(wParam);
	case WM_ERASEBKGND:
		return onEraseBackground((HDC)wParam);
	case WM_KILLFOCUS:
		return onKillFocus(wParam);
	case WM_TIMER:
		return onTimer(wParam);
	case WM_DISPLAYCHANGE:
		adjustWindowSize();

	}
	return false;
}
コード例 #14
0
bool SDLWindow::initialize(const std::string & title, Vec2i size, bool fullscreen,
                           unsigned depth) {
	
	arx_assert(!displayModes.empty());
	
	SDL_SetEventFilter(eventFilter);
	
	SDL_EventState(SDL_ACTIVEEVENT, SDL_ENABLE);
	SDL_EventState(SDL_QUIT, SDL_ENABLE);
	SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
	SDL_EventState(SDL_VIDEORESIZE, SDL_ENABLE);
	SDL_EventState(SDL_VIDEOEXPOSE, SDL_ENABLE);
	SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
	
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);

	SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, config.video.vsync ? 1 : 0);
	
	size_ = Vec2i_ZERO;
	depth_ = 0;
	
	for(int msaa = config.video.antialiasing ? 8 : 1; msaa >= 0; msaa--) {
		
		if(msaa > 1) {
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa);
		} else if(msaa > 0) {
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
		} else {
			LogError << "Failed to initialize SDL Window: " << SDL_GetError();
			return false;
		}
		
		if(setMode(DisplayMode(size, fullscreen ? depth : 0), fullscreen)) {
			break;
		}
	}
	
	isFullscreen_ = fullscreen;
	
	SDL_WM_SetCaption(title.c_str(), title.c_str());
	title_ = title;
	
	SDL_ShowCursor(SDL_DISABLE);
	
	onCreate();
	
	renderer = new OpenGLRenderer;
	renderer->Initialize();
	
	updateSize(false);
	
	onShow(true);
	onFocus(true);
	
	onRendererInit();
	
	return true;
}
コード例 #15
0
void 
SoXipMenuItem::onEnable()
{
	onFocus();
}
コード例 #16
0
void SDL2Window::tick() {
	
	SDL_Event event;
	while(SDL_PollEvent(&event)) {
		
		switch(event.type) {
			
			case SDL_WINDOWEVENT: {
				switch(event.window.event) {
					
					case SDL_WINDOWEVENT_SHOWN:        onShow(true);   break;
					case SDL_WINDOWEVENT_HIDDEN:       onShow(false);  break;
					case SDL_WINDOWEVENT_EXPOSED:      onPaint();      break;
					case SDL_WINDOWEVENT_MINIMIZED:    onMinimize();   break;
					case SDL_WINDOWEVENT_MAXIMIZED:    onMaximize();   break;
					case SDL_WINDOWEVENT_RESTORED:     onRestore();    break;
					case SDL_WINDOWEVENT_FOCUS_GAINED: onFocus(true);  break;
					case SDL_WINDOWEVENT_FOCUS_LOST:   onFocus(false); break;
					
					case SDL_WINDOWEVENT_MOVED: {
						onMove(event.window.data1, event.window.data2);
						break;
					}
					
					case SDL_WINDOWEVENT_SIZE_CHANGED: {
						Vec2i newSize(event.window.data1, event.window.data2);
						if(newSize != m_size && !m_fullscreen) {
							m_renderer->beforeResize(false);
							updateSize();
						} else {
							// SDL regrettably sends resize events when a fullscreen window
							// is minimized - we'll have none of that!
						}
						break;
					}
					
					case SDL_WINDOWEVENT_CLOSE: {
						// The user has requested to close a single window
						// TODO we only support one main window for now
						break;
					}
					
				}
				break;
			}
			
			#if ARX_PLATFORM == ARX_PLATFORM_WIN32
			case SDL_KEYDOWN: {
				// SDL2 is still eating our ALT+F4 under windows...
				// See bug report here: https://bugzilla.libsdl.org/show_bug.cgi?id=1555
				if(event.key.keysym.sym == SDLK_F4
				   && (event.key.keysym.mod & KMOD_ALT) != KMOD_NONE) {
					SDL_Event quitevent;
					quitevent.type = SDL_QUIT;
					SDL_PushEvent(&quitevent);
				}
				break;
			}
			#endif
			
			case SDL_QUIT: {
				// The user has requested to close the whole program
				// TODO onDestroy() fits SDL_WINDOWEVENT_CLOSE better, but SDL captures Ctrl+C
				// evenst and *only* sends the SDL_QUIT event for them while normal close
				// generates *both* SDL_WINDOWEVENT_CLOSE and SDL_QUIT
				onDestroy();
				return; // abort event loop!
			}
			
		}
		
		if(m_input) {
			m_input->onEvent(event);
		}
		
	}
	
	if(!m_renderer->isInitialized()) {
		updateSize();
		m_renderer->afterResize();
		m_renderer->SetViewport(Rect(m_size.x, m_size.y));
	}
}
コード例 #17
0
bool SDL2Window::initialize() {
	
	arx_assert(!m_displayModes.empty());
	
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	
	// We need an accelerated OpenGL context or we'll likely fail later
	SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
	// TODO EGL and core profile are not supported yet
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 0);
	
	if(gldebug::isEnabled()) {
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
	}
	
	
	int x = SDL_WINDOWPOS_UNDEFINED, y = SDL_WINDOWPOS_UNDEFINED;
	Uint32 windowFlags = getSDLFlagsForMode(m_size, m_fullscreen);
	windowFlags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
	
	for(int msaa = m_maxMSAALevel; msaa > 0; msaa--) {
		bool lastTry = (msaa == 1);
		
		// Cleanup context and window from previous tries
		if(m_glcontext) {
			SDL_GL_DeleteContext(m_glcontext);
			m_glcontext = NULL;
		}
		if(m_window) {
			SDL_DestroyWindow(m_window);
			m_window = NULL;
		}
		
		SDL_ClearError();
		
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, msaa > 1 ? 1 : 0);
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa > 1 ? msaa : 0);
		
		m_window = SDL_CreateWindow(m_title.c_str(), x, y, m_size.x, m_size.y, windowFlags);
		if(!m_window) {
			if(lastTry) {
				LogError << "Could not create window: " << SDL_GetError();
				return false;
			}
			continue;
		}
		
		m_glcontext = SDL_GL_CreateContext(m_window);
		if(!m_glcontext) {
			if(lastTry) {
				LogError << "Could not create GL context: " << SDL_GetError();
				return false;
			}
			continue;
		}
		
		// Verify that the MSAA setting matches what was requested
		int msaaEnabled, msaaValue;
		SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &msaaEnabled);
		SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msaaValue);
		if(!lastTry) {
			if(!msaaEnabled || msaaValue < msaa) {
				continue;
			}
		}
		if(msaaEnabled) {
			m_MSAALevel = msaaValue;
		} else {
			m_MSAALevel = 0;
		}
		
		// Verify that we actually got an accelerated context
		(void)glGetError(); // clear error flags
		GLint texunits = 0;
		glGetIntegerv(GL_MAX_TEXTURE_UNITS, &texunits);
		if(glGetError() != GL_NO_ERROR || texunits < GLint(m_minTextureUnits)) {
			if(lastTry) {
				LogError << "Not enough GL texture units available: have " << texunits
				         << ", need at least " << m_minTextureUnits;
				return false;
			}
			continue;
		}
		
		// All good
		int red = 0, green = 0, blue = 0, alpha = 0, depth = 0, doublebuffer = 0;
		SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &red);
		SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &green);
		SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &blue);
		SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &alpha);
		SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depth);
		SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer);
		LogInfo << "Window: r:" << red << " g:" << green << " b:" << blue << " a:" << alpha
		        << " depth:" << depth << " aa:" << msaa << "x doublebuffer:" << doublebuffer;
		break;
	}
	
	setVSync(m_vsync);
	
	SDL_ShowWindow(m_window);
	SDL_ShowCursor(SDL_DISABLE);
	
	m_renderer->initialize();
	
	onCreate();
	onToggleFullscreen(m_fullscreen);
	updateSize(true);
	
	onShow(true);
	onFocus(true);
	
	return true;
}
コード例 #18
0
ファイル: button.cpp プロジェクト: Ircher/CBoE
bool cLedGroup::triggerFocusHandler(cDialog& me, std::string id, bool losingFocus){
	if(onFocus != NULL) return onFocus(me,id,losingFocus);
	return true;
}