Пример #1
0
ci::vec2 Event::getLocalPos()
{
    NodeRef source = getSource();
    if (source) {
        return source->windowToLocal(getWindowPos());
    }

    return getWindowPos();
}
Пример #2
0
ci::vec2 Event::getScenePos()
{
    NodeRef source = getSource();
    if (source) {
        return source->windowToScene(getWindowPos());
    }

    return getWindowPos();
}
Пример #3
0
	void ComboBox::showPopup() {
		setPressed(true);
		if(_win)
			removeWindow();
		else {
			gsize_t pad = Application::getInstance()->getDefaultTheme()->getTextPadding();
			gsize_t height = _items.size() * (getGraphics()->getFont().getSize().height + pad * 2);
			const Window *w = getWindow();
			Pos pos(w->getPos().x + getWindowPos().x,
			        w->getPos().y + getWindowPos().y + getSize().height);
			_win = make_control<ItemWindow>(this,pos,Size(getSize().width,height));
			_win->show();
			Application::getInstance()->addWindow(_win);
		}
	}
Пример #4
0
void LinuxEnvironment::setWindowResizableInt(bool resizable, Vector2 windowSize)
{
	m_bResizable = resizable;

	const Vector2 windowPos = getWindowPos();

	// window managers may ignore this completely, there is no way to force it
	XSizeHints wmsize;
	memset(&wmsize, 0, sizeof(XSizeHints));

	wmsize.flags = PMinSize | PMaxSize;
	wmsize.min_width = m_bResizable ? 100 : (int)windowSize.x;
	wmsize.min_height = m_bResizable ? 100 : (int)windowSize.y;
	wmsize.max_width = m_bResizable ? (std::numeric_limits<int>::max() - 1) : (int)windowSize.x;
	wmsize.max_height = m_bResizable ? (std::numeric_limits<int>::max() - 1) : (int)windowSize.y;

	XSetWMNormalHints(m_display, m_window, &wmsize);

	// hack to force update the XSizeHints state
	XResizeWindow(m_display, m_window, (unsigned int)windowSize.x, (unsigned int)windowSize.y);
	XMoveWindow(m_display, m_window, (int)windowPos.x, (int)windowPos.y);
	XRaiseWindow(m_display, m_window);

	XFlush(m_display);
}
Пример #5
0
void LinuxEnvironment::setWindowSize(int width, int height)
{
	// due to the way resizability works, we have to temporarily disable it to be able to resize the window (because min/max is fixed)
	const Vector2 windowPos = getWindowPos();
	const bool wasWindowResizable = m_bResizable;
	if (!wasWindowResizable)
		setWindowResizableInt(true, Vector2(width, height));

	m_vResizeHackSize = Vector2(width, height);
	m_bResizeDelayHack = true;

	// hack to force update the XSizeHints state
	XResizeWindow(m_display, m_window, (unsigned int)width, (unsigned int)height);
	XMoveWindow(m_display, m_window, (int)windowPos.x, (int)windowPos.y);
	XRaiseWindow(m_display, m_window);

	if (!wasWindowResizable)
		setWindowResizableInt(false, Vector2(width, height));

	XFlush(m_display);
}
Пример #6
0
bool
Hud::MouseClick(int x, int y)
{
    for (std::vector<RadioButton>::iterator it = _radioButtons.begin();
            it != _radioButtons.end(); ++it) {
        if (hitTest(*it, x, y)) {
            for (std::vector<RadioButton>::iterator it2 = _radioButtons.begin();
                    it2 != _radioButtons.end(); ++it2) {

                if (it2->group == it->group && it != it2) it2->checked = false;
            }
            it->checked = true;
            it->callback(it->callbackData);
            _requiresRebuildStatic = true;
            return true;
        }
    }
    for (std::vector<CheckBox>::iterator it = _checkBoxes.begin();
            it != _checkBoxes.end(); ++it) {
        if (hitTest(*it, x, y)) {
            it->checked = !it->checked;
            it->callback(it->checked, it->callbackData);
            _requiresRebuildStatic = true;
            return true;
        }
    }
    for (std::vector<Slider>::iterator it = _sliders.begin();
            it != _sliders.end(); ++it) {
        if (hitTest(*it, x, y)) {
            int bx = 0, by = 0;
            getWindowPos(*it, &bx, &by);
            it->SetValue(((x-bx-FONT_CHAR_WIDTH/2)/float(it->w))*(it->max - it->min) + it->min);
            it->callback(it->value, it->callbackData);
            _capturedSlider = (int)(it - _sliders.begin());
            _requiresRebuildStatic = true;
            return true;
        }
    }
    return false;
}
Пример #7
0
void
Hud::Rebuild(int width, int height)
{
    _requiresRebuildStatic = false;
    _windowWidth = width;
    _windowHeight = height;

    _staticVboSource.clear();

    int x, y;
    // add UI elements
    for (std::vector<Item>::const_iterator it = _labels.begin();
            it != _labels.end(); ++it) {
        getWindowPos(*it, &x, &y);
        drawString(_staticVboSource, x, y, 1, 1, 1, it->label.c_str());
    }

    for (std::vector<RadioButton>::const_iterator it = _radioButtons.begin();
            it != _radioButtons.end(); ++it) {
        getWindowPos(*it, &x, &y);
        if (it->checked) {
            x = drawChar(_staticVboSource, x, y, 1, 1, 1, FONT_RADIO_BUTTON_ON);
            drawString(_staticVboSource, x, y, 1, 1, 0, it->label.c_str());
        } else {
            x = drawChar(_staticVboSource, x, y, 1, 1, 1, ' ');
            drawString(_staticVboSource, x, y, .5f, .5f, .5f, it->label.c_str());
        }
    }
    for (std::vector<CheckBox>::const_iterator it = _checkBoxes.begin();
            it != _checkBoxes.end(); ++it) {
        getWindowPos(*it, &x, &y);
        if (it->checked) {
            x = drawChar(_staticVboSource, x, y, 1, 1, 1, FONT_CHECK_BOX_ON);
            drawString(_staticVboSource, x, y, 1, 1, 0, it->label.c_str());
        } else {
            x = drawChar(_staticVboSource, x, y, 1, 1, 1, FONT_CHECK_BOX_OFF);
            drawString(_staticVboSource, x, y, .5f, .5f, .5f, it->label.c_str());
        }
    }
    for (std::vector<Slider>::const_iterator it = _sliders.begin();
            it != _sliders.end(); ++it) {
        getWindowPos(*it, &x, &y);
        int sx = x;
        x = drawString(_staticVboSource, x, y, 1, 1, 1, it->label.c_str());
        char value[16];
        snprintf(value, 16, " : %.2f", it->value);
        drawString(_staticVboSource, x, y, 1, 1, 1, value);

        // new line
        y += FONT_CHAR_HEIGHT;
        x = sx;

        x = drawChar(_staticVboSource, x, y, 1, 1, 1, FONT_SLIDER_LEFT);
        int nw = it->w / FONT_CHAR_WIDTH;
        for (int i = 1; i < nw; ++i) {
            x = drawChar(_staticVboSource, x, y, 1, 1, 1, FONT_SLIDER_MIDDLE);
        }
        drawChar(_staticVboSource, x, y, 1, 1, 1, FONT_SLIDER_RIGHT);
        int pos = (int)((it->value/float(it->max-it->min))*it->w);
        drawChar(_staticVboSource, sx+pos, y, 1, 1, 0, FONT_SLIDER_CURSOR);
    }

    drawString(_staticVboSource, _windowWidth-80, _windowHeight-48, .5, .5, .5,
               "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f");
    drawString(_staticVboSource, _windowWidth-80, _windowHeight-32, .5, .5, .5,
               "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f");
}
bool MyDirectDrawSw::presentInternal(int xdest,
                                     int ydest,
                                     int width,
                                     int height,
                                     int xsrc,
                                     int ysrc,
                                     const MyDirectDrawSurfaceSw* surf)
{
    LOG_FUNCTION();
    ++mFramesCount;
    const auto newTime = clock::now();
    if(std::chrono::duration_cast<seconds>(newTime - mPrevFrameTime).count() >= 1)
    {
        const auto dur = std::chrono::duration_cast<microseconds>(newTime - mPrevFrameTime);
        mFrameTime = (decltype(mFrameTime))dur.count() /
                (decltype(mFrameTime))mFramesCount / 1000000.0f;
        mFramesCount = 0;
        mPrevFrameTime = newTime;
    }

    int xoff = 0;
    int yoff = 0;
    if(mSettings->drawOnScreen())
    {
        const auto off = getWindowPos(true);
        xoff = off.first;
        yoff = off.second;
    }
    xdest += xoff;
    ydest += yoff;
    const auto bpp = surf->bpp();
    const void* data = surf->GetBufferPtr();

    struct
    {
        BITMAPINFO bmi;
        RGBQUAD data[255];
    } s;
    s.bmi.bmiHeader.biSize = sizeof(s.bmi.bmiHeader);
    s.bmi.bmiHeader.biWidth = width;
    s.bmi.bmiHeader.biHeight = -height;
    s.bmi.bmiHeader.biPlanes = 1;
    s.bmi.bmiHeader.biBitCount = bpp;
    s.bmi.bmiHeader.biCompression = BI_RGB;
    s.bmi.bmiHeader.biSizeImage = 0;
    s.bmi.bmiHeader.biXPelsPerMeter = 0;
    s.bmi.bmiHeader.biYPelsPerMeter = 0;
    s.bmi.bmiHeader.biClrUsed = 0;
    s.bmi.bmiHeader.biClrImportant = 0;
    if(bpp <= 8)
    {
        const auto palette = surf->getPaletteInternal();
        if(nullptr != palette)
        {
            int i = 0;
            std::generate_n(s.bmi.bmiColors, palette->count(),[&]()
            {
                const auto& e = palette->entry(i++);
                RGBQUAD ret;
                ret.rgbBlue  = e.peBlue;
                ret.rgbGreen = e.peGreen,
                ret.rgbRed   = e.peRed;
                return ret;
            });
        }
        else
        {
            memset(&s.bmi.bmiColors, 0, sizeof(RGBQUAD) * 256);
        }
    }
    else if(bpp < 32)
    {
        s.bmi.bmiHeader.biCompression = BI_BITFIELDS;
        auto masks = reinterpret_cast<DWORD*>(s.bmi.bmiColors);
        surf->getColorMask(masks[0], masks[1], masks[2]);
    }

    const bool result = (0 != ::SetDIBitsToDevice(mHDC,
                                                  xdest,
                                                  ydest,
                                                  width,
                                                  height,
                                                  xsrc,
                                                  ysrc,
                                                  0,
                                                  height,
                                                  data,
                                                  &s.bmi,
                                                  DIB_RGB_COLORS));
    if(!result)
    {
        LOG_ERROR() << "SetDIBitsToDevice failed: " << getWinError();
    }

    if(mSettings->showDebugInfo())
    {
        RECT textRc = {xoff,yoff,mDispMode.width + xoff,mDispMode.height + yoff};
        ::DrawText(mHDC, getDebugInfo().c_str(), -1, &textRc, DT_LEFT | DT_TOP);
    }

    return result;
}
Пример #9
0
void LinuxEnvironment::enableFullscreen()
{
	if (m_bFullScreen) return;

	// backup
	if (m_vPrevDisableFullscreenWindowSize != getWindowSize())
	{
		m_vLastWindowPos = getWindowPos();
		m_vLastWindowSize = getWindowSize();
	}

	// handle resizability (force enable while fullscreen)
	m_bFullscreenWasResizable = m_bResizable;
	setWindowResizable(true);

	// disable window decorations
    Hints hints;
    Atom property;
    hints.flags = 2; // specify that we're changing the window decorations
    hints.decorations = 0; // 0 (false) = disable decorations
    property = XInternAtom(m_display, "_MOTIF_WM_HINTS", True);
    XChangeProperty(m_display, m_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);

	// set size to fill entire screen (also fill borders)
	// the "x" and "y" members of "attributes" are the window's coordinates relative to its parent, i.e. to the decoration window
	XWindowAttributes attributes;
	XGetWindowAttributes(m_display, m_window, &attributes);
	XMoveResizeWindow(m_display,
			m_window,
			-attributes.x,
			-attributes.y,
			(unsigned int)getNativeScreenSize().x,
			(unsigned int)getNativeScreenSize().y);

    // suggest fullscreen mode
	Atom atom = XInternAtom(m_display, "_NET_WM_STATE_FULLSCREEN", True);
	XChangeProperty(
		m_display, m_window,
		XInternAtom(m_display, "_NET_WM_STATE", True),
		XA_ATOM, 32, PropModeReplace,
		(unsigned char*)&atom, 1);

	// get identifiers for the provided atom name strings
	Atom wm_state = XInternAtom(m_display, "_NET_WM_STATE", False);
	Atom fullscreen = XInternAtom(m_display, "_NET_WM_STATE_FULLSCREEN", False);

	XEvent xev;
	memset(&xev, 0, sizeof(xev));

	xev.type                 = ClientMessage;
	xev.xclient.window       = m_window;
	xev.xclient.message_type = wm_state;
	xev.xclient.format       = 32;
	xev.xclient.data.l[0]    = 1; // enable fullscreen (1 == true)
	xev.xclient.data.l[1]    = fullscreen;

	// send an event mask to the X-server
	XSendEvent(
		m_display,
		DefaultRootWindow(m_display),
		False,
		SubstructureNotifyMask,
		&xev);

	// force top window
	focus();

	m_bFullScreen = true;
}