示例#1
0
    //==============================================================================
    void handleEvent (ComponentPeer* const newPeer, Point<int> positionWithinPeer, Time time, const ModifierKeys newMods)
    {
        jassert (newPeer != nullptr);
        lastTime = time;
        ++mouseEventCounter;
        const Point<int> screenPos (newPeer->localToGlobal (positionWithinPeer));

        if (isDragging() && newMods.isAnyMouseButtonDown())
        {
            setScreenPos (screenPos, time, false);
        }
        else
        {
            setPeer (newPeer, screenPos, time);

            if (ComponentPeer* peer = getPeer())
            {
                if (setButtons (screenPos, time, newMods))
                    return; // some modal events have been dispatched, so the current event is now out-of-date

                peer = getPeer();
                if (peer != nullptr)
                    setScreenPos (screenPos, time, false);
            }
        }
    }
示例#2
0
    //==============================================================================
    void handleEvent (ComponentPeer& newPeer, Point<float> positionWithinPeer, Time time,
                      const ModifierKeys newMods, float newPressure)
    {
        lastTime = time;
        const bool pressureChanged = (pressure != newPressure);
        pressure = newPressure;
        ++mouseEventCounter;
        const Point<float> screenPos (newPeer.localToGlobal (positionWithinPeer));

        if (isDragging() && newMods.isAnyMouseButtonDown())
        {
            setScreenPos (screenPos, time, pressureChanged);
        }
        else
        {
            setPeer (newPeer, screenPos, time);

            if (ComponentPeer* peer = getPeer())
            {
                if (setButtons (screenPos, time, newMods))
                    return; // some modal events have been dispatched, so the current event is now out-of-date

                peer = getPeer();

                if (peer != nullptr)
                    setScreenPos (screenPos, time, pressureChanged);
            }
        }
    }
示例#3
0
void Player::animationDidFinish(Animation *sender)
{
    setScreenPos(tilePos.x*TILESIZE, tilePos.y*TILESIZE);
    locked = false;
    textStep = 0;
    setTexture();
}
示例#4
0
    Component* getTargetForGesture (ComponentPeer& peer, Point<float> positionWithinPeer,
                                    Time time, Point<float>& screenPos)
    {
        lastTime = time;
        ++mouseEventCounter;

        screenPos = peer.localToGlobal (positionWithinPeer);
        setPeer (peer, screenPos, time);
        setScreenPos (screenPos, time, false);
        triggerFakeMove();

        return isDragging() ? nullptr : getComponentUnderMouse();
    }
示例#5
0
    Component* getTargetForGesture (ComponentPeer* const peer, const Point<int>& positionWithinPeer,
                                    const Time& time, Point<int>& screenPos)
    {
        jassert (peer != nullptr);
        lastTime = time;
        ++mouseEventCounter;

        screenPos = peer->localToGlobal (positionWithinPeer);
        setPeer (peer, screenPos, time);
        setScreenPos (screenPos, time, false);
        triggerFakeMove();

        return isDragging() ? nullptr : getComponentUnderMouse();
    }
示例#6
0
    //==============================================================================
    // (returns true if the button change caused a modal event loop)
    bool setButtons (const Point<int>& screenPos, const Time& time, const ModifierKeys& newButtonState)
    {
        if (buttonState == newButtonState)
            return false;

        // (avoid sending a spurious mouse-drag when we receive a mouse-up)
        if (! (isDragging() && ! newButtonState.isAnyMouseButtonDown()))
            setScreenPos (screenPos, time, false);

        // (ignore secondary clicks when there's already a button down)
        if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
        {
            buttonState = newButtonState;
            return false;
        }

        const int lastCounter = mouseEventCounter;

        if (buttonState.isAnyMouseButtonDown())
        {
            Component* const current = getComponentUnderMouse();

            if (current != nullptr)
            {
                const ModifierKeys oldMods (getCurrentModifiers());
                buttonState = newButtonState; // must change this before calling sendMouseUp, in case it runs a modal loop

                sendMouseUp (current, screenPos + unboundedMouseOffset, time, oldMods);
            }

            enableUnboundedMouseMovement (false, false);
        }

        buttonState = newButtonState;

        if (buttonState.isAnyMouseButtonDown())
        {
            Desktop::getInstance().incrementMouseClickCounter();

            Component* const current = getComponentUnderMouse();

            if (current != nullptr)
            {
                registerMouseDown (screenPos, time, current, buttonState);
                sendMouseDown (current, screenPos, time);
            }
        }

        return lastCounter != mouseEventCounter;
    }
    void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const Time& time, float x, float y)
    {
        jassert (peer != nullptr);
        lastTime = time;
        ++mouseEventCounter;
        const Point<int> screenPos (peer->localToGlobal (positionWithinPeer));

        setPeer (peer, screenPos, time);
        setScreenPos (screenPos, time, false);
        triggerFakeMove();

        if (! isDragging())
        {
            Component* current = getComponentUnderMouse();
            if (current != nullptr)
                sendMouseWheel (current, screenPos, time, x, y);
        }
    }
示例#8
0
    void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer,
                      const Time& time, const MouseWheelDetails& wheel)
    {
        jassert (peer != nullptr);
        lastTime = time;
        ++mouseEventCounter;
        Desktop::getInstance().incrementMouseWheelCounter();

        const Point<int> screenPos (peer->localToGlobal (positionWithinPeer));
        setPeer (peer, screenPos, time);
        setScreenPos (screenPos, time, false);
        triggerFakeMove();

        if (! isDragging())
        {
            Component* current = getComponentUnderMouse();
            if (current != nullptr)
                sendMouseWheel (current, screenPos, time, wheel);
        }
    }
示例#9
0
 void handleAsyncUpdate() override
 {
     setScreenPos (lastScreenPos, jmax (lastTime, Time::getCurrentTime()), true);
 }
示例#10
0
subway_panel::subway_panel(int len, int hei, subway_panel::position_T pos, QString name): QFrame()
{
    desktop = QApplication::desktop();
    this->setWindowFlags(Qt::FramelessWindowHint|Qt::Window|Qt::WindowStaysOnTopHint);
    position = pos;
    switch(pos)
    {
	case top:
	case bottom:
	if(len == 0)
	{
	    length = desktop->width();
	}
	else length = len;
	this->setMinimumWidth(length);
	this->setMaximumWidth(length);
	weight = hei;
	this->setMaximumHeight(weight);
	this->setMinimumHeight(weight);
	layout = new QBoxLayout(QBoxLayout::LeftToRight,this);
	((QBoxLayout*)layout)->setAlignment(Qt::AlignLeft);
	((QBoxLayout*)layout)->setSpacing(0);
	((QBoxLayout*)layout)->setMargin(0);
	((QBoxLayout*)layout)->setContentsMargins(0,0,0,0);
	break;
    }
    switch(pos)
    {
	case top:
	  setScreenPos(QPoint(0,0));
	  break;
	case bottom:
	  setScreenPos(QPoint(0,desktop->height()-weight));
	  break;
	case left:
	case right:
	  break;
    }
    settings = new QSettings("Subway","Panel-" + name + "-Applets");
    if(settings->value("initialized","").toString() == "")
    {
	//Initialize new panel
	settings->setValue("initialized","y");
	settings->setValue("appletnum",1);
	settings->setValue("applet1","window-list");
	settings->setValue("applet1-height",32);
	settings->setValue("applet1-width",32);
	//settings->setValue("applet1-align","left");
    }
    this->setLayout(layout);
    for(int i = 1;i<=settings->value("appletnum").toInt();i++)
    {
	QString applet_setting_name = QString("applet")+QVariant(i).toString();
	QString name = settings->value(applet_setting_name).toString();
	QWidget *applet;
	if(name == "window-list")
	{
	    applet = new window_list(this);
	}
	else
	{
	    applet = new QWidget(this);
	}
	int tmp;
	if((tmp = settings->value(applet_setting_name+"-height").toInt()) != 0)
	{
	    applet->setMinimumHeight(tmp);
	    applet->setMaximumHeight(tmp);
	}
	else
	{
	    QSizePolicy sp = applet->sizePolicy();
	    sp.setVerticalPolicy(QSizePolicy::Expanding);
	    applet->setSizePolicy(sp);
	}
	if((tmp = settings->value(applet_setting_name+"-width").toInt()) != 0)
	{
	    applet->setMaximumWidth(tmp);
	    applet->setMinimumWidth(tmp);
	}
	else
	{
	    QSizePolicy sp = applet->sizePolicy();
	    sp.setHorizontalPolicy(QSizePolicy::Expanding);
	    applet->setSizePolicy(sp);
	}
	//layout->addWidget(applet);
	layout->insertWidget(layout->count(),applet);
    }
    this->setAttribute(Qt::WA_X11NetWmWindowTypeDock);
    display = this->x11Info().display();
    XfitMan fitman = xfitMan();
    switch(pos)
    {
      case bottom:
	fitman.setStrut(winId(),  0, 0, 0, weight,
               /* Left   */   0, 0,
               /* Right  */   0, 0,
               /* Top    */   0, 0,
               /* Bottom */   0, desktop->width()
                         );
	break;
      case top:
	fitman.setStrut(winId(),  0, 0, weight, 0,
               /* Left   */   0, 0,
               /* Right  */   0, 0,
               /* Top    */   0, desktop->width(),
               /* Bottom */   0, 0
                         );
    }
}
void ClientEntity::render (IFrontend *frontend, Layer layer, int scale, float zoom, int offsetX, int offsetY) const
{
	if (!_currSprite)
		return;

	const ClientEntityPtr ropeEntity = _ropeEntity;
	const int basePosX = _pos.x * scale * zoom;
	const int basePosY = _pos.y * scale * zoom;
	int posX = basePosX;
	int posY = basePosY;

	switch (_align) {
	case ENTITY_ALIGN_UPPER_LEFT:
		break;
	case ENTITY_ALIGN_LOWER_LEFT:
		posX -= _currSprite->getWidth(layer) * zoom / 2.0f;
		posY += _size.y * scale * zoom / 2.0f;
		posY -= _currSprite->getHeight(layer) * zoom;
		break;
	case ENTITY_ALIGN_MIDDLE_CENTER: {
		posX -= _currSprite->getWidth(layer) * zoom / 2.0f;
		posY -= _currSprite->getHeight(layer) * zoom / 2.0f;
		break;
	}
	}

	setScreenPos(offsetX + posX, offsetY + posY);

	const int ropeX1 = basePosX;
	const int ropeY1 = (basePosY - _size.y * scale * zoom / 2.0f);
	int ropeX2 = 0;
	int ropeY2 = 0;
	if (ropeEntity && layer == LAYER_MIDDLE) {
		const vec2& pos = ropeEntity->getPos();
		const vec2& size = ropeEntity->getSize();
		ropeX2 = pos.x * scale * zoom;
		ropeY2 = pos.y * scale * zoom + size.y * scale * zoom / 2.0f;
		static const Color color = { 0.5f, 0.3f, 0.3f, 1.0f };
		frontend->renderLine(offsetX + ropeX1, offsetY + ropeY1, offsetX + ropeX2, offsetY + ropeY2, color);
	}

	const bool visible = _currSprite->render(frontend, layer, _screenPosX, _screenPosY, zoom, _angle, _alpha);
	_visChanged = visible != _visible;

	renderOverlays(frontend, layer, scale, zoom, offsetX, offsetY, posX, posY);

	if (layer != LAYER_FRONT)
		return;

	if (Config.isDebug())
		frontend->renderFilledRect(_screenPosX, _screenPosY, 4, 4, colorRed);

	const bool debug = Config.getConfigVar("debugentity")->getBoolValue();
	if (debug) {
		const BitmapFontPtr& font = UI::get().getFont();

		renderDot(frontend, offsetX + basePosX, offsetY + basePosY, colorGreen);
		renderDot(frontend, offsetX + posX, offsetY + posY, colorWhite);
		if (ropeEntity && layer == LAYER_MIDDLE) {
			renderDot(frontend, offsetX + ropeX1, offsetY + ropeY1, colorBlue);
			renderDot(frontend, offsetX + ropeX2, offsetY + ropeY2, colorBrightBlue);
		}
		int offsetPosX, offsetPosY;
		calcOffset(scale, zoom, posX, posY, offsetPosX, offsetPosY);
		renderDot(frontend, offsetX + offsetPosX, offsetY + offsetPosY, colorGray);

		int fontY = _screenPosY;
		if (!_animation->isNone()) {
			font->print(_animation->name, colorWhite, _screenPosX, fontY);
			fontY += font->getTextHeight(_animation->name);
		}
		font->print(string::toString(_angle), colorWhite, _screenPosX, fontY);
	}
}
示例#12
0
void Player::keyPressed(sf::Keyboard::Key key)
{
    if (locked)
    {
        return;
    }

    switch (key)
    {
        case sf::Keyboard::Left:

            if (dir == kLeft && tilePos.x == 0)
            {
                worldPos.x--;
                tilePos.x = REGIONSIZE-1;
                setScreenPos(tilePos.x*TILESIZE, tilePos.y*TILESIZE);
                break;
            }

            if (dir == kLeft && !checkCollision(worldPos.x, worldPos.y, tileLeft().x, tileLeft().y))
            {
                tilePos = tileLeft();
                AnimMoveX(&sprite, -TILESIZE, speed, animator, this, "moveLeft");
                locked = true;
            }

            if (tileAt(worldPos.x, worldPos.y, tileLeft().x, tileLeft().y) != nullptr && tileAt(worldPos.x, worldPos.y, tileLeft().x, tileLeft().y)->canUse())
            {
                useIcon = true;
            }
            else
            {
                useIcon = false;
            }

            dir = kLeft;
            dir_char = "_l_";
            setTexture();

            break;
        case sf::Keyboard::Right:

            if (dir == kRight && tilePos.x == REGIONSIZE-1)
            {
                worldPos.x++;
                tilePos.x = 0;
                setScreenPos(tilePos.x*TILESIZE, tilePos.y*TILESIZE);
                break;
            }

            if (dir == kRight && !checkCollision(worldPos.x, worldPos.y, tileRight().x, tileRight().y))
            {
                tilePos = tileRight();
                AnimMoveX(&sprite, TILESIZE, speed, animator, this, "moveRight");
                locked = true;
            }

            if (tileAt(worldPos.x, worldPos.y, tileRight().x, tileRight().y) != nullptr && tileAt(worldPos.x, worldPos.y, tileRight().x, tileRight().y)->canUse())
            {
                useIcon = true;
            }
            else
            {
                useIcon = false;
            }

            dir = kRight;
            dir_char = "_r_";
            setTexture();

            break;
        case sf::Keyboard::Up:

            if (dir == kUp && tilePos.y == 0)
            {
                worldPos.y--;
                tilePos.y = REGIONSIZE-1;
                setScreenPos(tilePos.x*TILESIZE, tilePos.y*TILESIZE);
                break;
            }

            if (dir == kUp && !checkCollision(worldPos.x, worldPos.y, tileUp().x, tileUp().y))
            {
                tilePos = tileUp();
                AnimMoveY(&sprite, -TILESIZE, speed, animator, this, "moveUp");
                locked = true;
            }

            if (tileAt(worldPos.x, worldPos.y, tileUp().x, tileUp().y) != nullptr && tileAt(worldPos.x, worldPos.y, tileUp().x, tileUp().y)->canUse())
            {
                useIcon = true;
            }
            else
            {
                useIcon = false;
            }

            dir = kUp;
            dir_char = "_u_";
            setTexture();

            break;
        case sf::Keyboard::Down:

            if (dir == kDown && tilePos.y == REGIONSIZE-1)
            {
                worldPos.y++;
                tilePos.y = 0;
                setScreenPos(tilePos.x*TILESIZE, tilePos.y*TILESIZE);
                break;
            }

            if (dir == kDown && !checkCollision(worldPos.x, worldPos.y, tileDown().x, tileDown().y))
            {
                tilePos = tileDown();
                AnimMoveY(&sprite, TILESIZE, speed, animator, this, "moveDown");
                locked = true;
            }

            if (tileAt(worldPos.x, worldPos.y, tileDown().x, tileDown().y) != nullptr && tileAt(worldPos.x, worldPos.y, tileDown().x, tileDown().y)->canUse())
            {
                useIcon = true;
            }
            else
            {
                useIcon = false;
            }

            dir = kDown;
            dir_char = "_d_";
            setTexture();

            break;
        case sf::Keyboard::E:
            use();
            break;
        default:
            break;
    }
}
示例#13
0
void Player::snap()
{
    int sx = (int)screenPos.x & 0xFFF0 << 1;
    int sy = (int)screenPos.y & 0xFFF0 << 1;
    setScreenPos(sx, sy);
}
示例#14
0
Player::Player(sf::Vector2i pos) : worldPos(0,0), locked(false), dir(kLeft), speed(PLAYERSPEED), textStep(0)
{
    sprite = sf::Sprite(*Manager::texture().getTexture("player"));
    setTilePos(pos);
    setScreenPos(pos.x*TILESIZE, pos.y*TILESIZE);
}
示例#15
0
Player::Player(int x, int y) : worldPos(0,0), locked(false), dir(kLeft), speed(PLAYERSPEED), textStep(0)
{
    sprite = sf::Sprite(*Manager::texture().getTexture("player_l_0"));
    setTilePos(x, y);
    setScreenPos(x*TILESIZE, y*TILESIZE);
}