Beispiel #1
0
FB::variant hapticAPI::getPosition()
{
	if (initialized){
		hdPhantomGetPosition(deviceID, &position[0],&position[1],&position[2]);

		double buf[3];
		if (strcmp(context.c_str(),"2d")==0){
			buf[0] = position[1]+0.1+offsetX;
			buf[1] = -(position[2]-0.1)+offsetY;
			buf[2] = position[0];
			double x = (buf[0]/pixelWidth);
			double y = (buf[1]/pixelWidth);
			mouseRenderPosition(x,y);
			if (leftButton())
				mouseRenderLeftButton();
		}
		else{
			buf[0] = position[1];
			buf[1] = -position[2];
			buf[2] = -position[0];
		}

		std::string pos = arrayToString(buf);

		return pos;
	}

	return NotInitializedString;
}
Beispiel #2
0
PlayerPanel::PlayerPanel() : UI::Base()
{
    auto game = Game::getInstance();
    auto renderer = game->renderer();
    auto mouse = game->mouse();

    _background = std::make_shared<Image>("art/intrface/iface.frm");
    _ui.push_back(_background);

    setX((renderer->width() - 640) / 2);
    setY(renderer->height() - _background->height());

    _background->setPosition(this->position());

    mouseInHandler().add([this, mouse](Event::Event* event)
    {
        mouse->pushState(Input::Mouse::Cursor::BIG_ARROW);
    });

    mouseOutHandler().add([this, mouse](Event::Event* event)
    {
        if (mouse->scrollState())
        {
            // this trick is needed for correct cursor type returning on scrolling
            auto state = mouse->state();
            mouse->popState();
            mouse->popState();
            mouse->pushState(state);
        }
        else
        {
            mouse->popState();
        }
    });

    // Change hand button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::BIG_RED_CIRCLE, position() + Point(218, 5)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){ this->changeHand(); });

    // Inventory button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_INVENTORY, position() + Point(211, 40)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){ this->openInventory(); });

    // Options button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_OPTIONS, position() + Point(210, 61)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){ this->openGameMenu(); });

    // Attack button
    _isAttackBtnPressed = false;
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_ATTACK, position() + Point(267, 25)));

    _ui.back()->mouseDownHandler().add([this](Event::Event* event){
        if(auto mouse = dynamic_cast<Event::Mouse*>(event))
        {
            if(mouse->leftButton())
                _isAttackBtnPressed = true;
        }
    });

    _ui.back()->mouseUpHandler().add([this](Event::Event* event){
        _isAttackBtnPressed = false;
    });


    // Hit points
    _hitPoints = std::make_shared<SmallCounter>(position() + Point(473, 40));
    _hitPoints->setType(SmallCounter::Type::SIGNED);
    _hitPoints->setNumber(game->player()->hitPoints());
    _ui.push_back(_hitPoints);

    // Armor class
    _armorClass = std::make_shared<SmallCounter>(position() + Point(473, 76));
    _armorClass->setType(SmallCounter::Type::SIGNED);
    _armorClass->setNumber(game->player()->armorClass());
    _ui.push_back(_armorClass);

    // Skilldex button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::BIG_RED_CIRCLE, position() + Point(523, 5)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openSkilldex();
    });

    // MAP button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_MAP, position() + Point(526, 39)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openMap();
    });

    // CHA button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_CHA, position() + Point(526, 58)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openCharacterScreen();
    });

    // PIP button
    _ui.push_back(std::make_shared<ImageButton>(ImageButton::Type::PANEL_PIP, position() + Point(526, 77)));
    _ui.back()->mouseClickHandler().add([this](Event::Event* event){
        this->openPipBoy();
    });

    // Message log
    _messageLog = std::make_shared<UI::TextArea>(position() + Point(23, 24));
    _messageLog->setSize({165, 60});
    _messageLog->setWordWrap(true);
    _messageLog->setCustomLineShifts({0, 1, 2, 3, 4, 5});
    _ui.push_back(_messageLog);

    _messageLog->mouseDownHandler().add([this](Event::Mouse* event)
        {
            _scrollingLog = 0;
            Point relPos = event->position() - _messageLog->position();
            if (relPos.y() < (_messageLog->size().height() / 2))
            {
                if (_messageLog->lineOffset() > 0)
                {
                    _scrollingLog = -1;
                }
            }
            else if (_messageLog->lineOffset() < _messageLog->numLines() - 6)
            {
                _scrollingLog = 1;
            }
            if (_scrollingLog != 0)
            {
                _messageLog->setLineOffset(_messageLog->lineOffset() + _scrollingLog);
                _scrollingLogTimer = SDL_GetTicks();
            }
        });

    _messageLog->mouseUpHandler().add([this](Event::Mouse* event)
        {
            _scrollingLog = 0;
            _scrollingLogTimer = 0;
        });

    _messageLog->mouseMoveHandler().add([this](Event::Mouse* event)
        {
            auto mouse = Game::getInstance()->mouse();
            Point relPos = event->position() - _messageLog->position();

            auto state = relPos.y() < (_messageLog->size().height() / 2)
                ? Input::Mouse::Cursor::SMALL_UP_ARROW
                : Input::Mouse::Cursor::SMALL_DOWN_ARROW;

            if (mouse->state() != state)
            {
                mouse->setState(state);
            }
        });

     _messageLog->mouseOutHandler().add([this](Event::Mouse* event)
        {
            _scrollingLog = 0;
            _scrollingLogTimer = 0;
            Game::getInstance()->mouse()->setState(Input::Mouse::Cursor::BIG_ARROW);
        });

    keyDownHandler().add([this](Event::Event* event) {
        this->onKeyDown(dynamic_cast<Event::Keyboard*>(event));
    });
}