Beispiel #1
0
// -- KeyListener notifications
void ListBox::keyPressed(gcn::KeyEvent& keyEvent)
{
    gcn::Key key = keyEvent.getKey();

    if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
    {
        if (keyEvent.isShiftPressed())
        {
            const std::string actionEventId = getActionEventId();
            setActionEventId("default");
            distributeActionEvent();
            setActionEventId(actionEventId);
        }
        else
            distributeActionEvent();
    }
    else if (key.getValue() == Key::UP)
        decrementSelected();
    else if (key.getValue() == Key::DOWN)
        incrementSelected();
    else if (key.getValue() == Key::HOME)
        setSelected(0);
    else if (key.getValue() == Key::END)
        setSelected(getListModel()->getNumberOfElements() - 1);
    else
        return;

    keyEvent.consume();
}
Beispiel #2
0
void
Wellcome::mousePressed(gcn::MouseEvent &event)
{
    gcn::Rectangle d1, d2, d3, d4;
    d1.setAll(mNext->getDimension().x,
              mNext->getDimension().y + getTitleBarHeight(),
              mNext->getDimension().x + mNext->getDimension().width,
              mNext->getDimension().y + mNext->getDimension().height + getTitleBarHeight());
    d2.setAll(mPrev->getDimension().x,
              mPrev->getDimension().y + getTitleBarHeight(),
              mPrev->getDimension().x + mPrev->getDimension().width,
              mPrev->getDimension().y + mPrev->getDimension().height + getTitleBarHeight());
    d3.setAll(mFinish->getDimension().x,
              mFinish->getDimension().y + getTitleBarHeight(),
              mFinish->getDimension().x + mFinish->getDimension().width,
              mFinish->getDimension().y + mFinish->getDimension().height + getTitleBarHeight());
    d4.setAll(mAgain->getDimension().x,
              mAgain->getDimension().y + getTitleBarHeight(),
              mAgain->getDimension().x + mAgain->getDimension().width,
              mAgain->getDimension().y + mAgain->getDimension().height + getTitleBarHeight());

    if(d1.isPointInRect(event.getX(), event.getY()) ||
       d2.isPointInRect(event.getX(), event.getY()) ||
       d3.isPointInRect(event.getX(), event.getY()) ||
       d4.isPointInRect(event.getX(), event.getY()) ||
       event.getY()<getTitleBarHeight())
    {
        Window::mousePressed(event);
        return;
    }
    setActionEventId("next");
    distributeActionEvent();

}
Beispiel #3
0
Button::Button(const std::string &caption, const std::string &actionEventId,
    gcn::ActionListener *listener):
    gcn::Button(caption)
{
    init();
    setActionEventId(actionEventId);

    if (listener)
        addActionListener(listener);
}
Beispiel #4
0
ItemContainer::ItemContainer(Inventory *inventory,
                             const std::string &actionEventId,
                             gcn::ActionListener *listener):
    mInventory(inventory),
    mSelectedItemIndex(NO_ITEM),
    mLastSelectedItemId(NO_ITEM),
    mEquipSlotsFilter(NO_ITEM)
{
    if (!actionEventId.empty())
        setActionEventId(actionEventId);

    if (listener && !actionEventId.empty())
        addActionListener(listener);

    if (mInstances == 0)
    {
        mItemPopup = new ItemPopup();
        mItemPopup->setOpaque(false);

        mShowItemInfo = config.getValue("showItemPopups", true);
        mConfigListener = new ItemContainerConfigListener(this);
        config.addListener("showItemPopups", mConfigListener);

        mPopupMenu = new PopupMenu(TRADE);

        ResourceManager *resman = ResourceManager::getInstance();

        mSelImg = resman->getImage("graphics/gui/selection.png");

        if (!mSelImg)
            logger->error("Unable to load selection.png");
    }

    mProtFocusListener = new ProtectedFocusListener();

    mProtFocusListener->blockKey(SDLK_LEFT);
    mProtFocusListener->blockKey(SDLK_RIGHT);
    mProtFocusListener->blockKey(SDLK_UP);
    mProtFocusListener->blockKey(SDLK_DOWN);
    mProtFocusListener->blockKey(SDLK_SPACE);
    mProtFocusListener->blockKey(SDLK_RETURN);

    mInstances++;

    mMaxItems = mInventory->getLastUsedSlot(); // Count from 0, usage from 2

    addFocusListener(mProtFocusListener);
    addFocusListener(this);
    addKeyListener(this);
    addMouseListener(this);
    addWidgetListener(this);

    setFocusable(true);
}
ImageButton::ImageButton(const std::string &caption) : gcn::Button (caption), GlassWidget(this) {
	idleState = state = GB_IDLE;
	icon = NULL;
	setFrameSize(0);
	setActionEventId(caption);
	setForegroundColor(gcn::Color(255,255,255));
		
	//for GlassWidget
	addActionListener(this);
	//addMouseListener((GlassWidget*)this);
}
ImageButton::ImageButton(const std::string &caption, const std::string &icf) : gcn::Button (caption), GlassWidget(this) {
	idleState = state = GB_IDLE;
	icon = gcn::Image::load(icf.c_str());
	if(icon)
		setSize(icon->getWidth(),icon->getHeight());
	setFrameSize(0);
	setActionEventId(caption);
	setForegroundColor(gcn::Color(255,255,255));
		
	//for GlassWidget
	addActionListener(this);
	//addMouseListener((GlassWidget*)this);
}
Beispiel #7
0
void SliderList::postInit(ActionListener *const listener,
                          const std::string &eventId)
{
    mPrevEventId = eventId + "_prev";
    mNextEventId = eventId + "_next";

    mButtons[0] = new Button(this, "<", mPrevEventId, this);
    mButtons[1] = new Button(this, ">", mNextEventId, this);

    add(mButtons[0]);
    add(mLabel);
    add(mButtons[1]);

    if (!eventId.empty())
        setActionEventId(eventId);

    if (listener)
        addActionListener(listener);

    updateLabel();
    addMouseListener(this);
}
Beispiel #8
0
ListBox::ListBox(gcn::ListModel *listModel, const std::string &actionEventId,
                 gcn::ActionListener *listener):
    gcn::ListBox(listModel)
{
    if (!actionEventId.empty())
        setActionEventId(actionEventId);

    if (listener && !actionEventId.empty())
        addActionListener(listener);

    mProtFocusListener = new ProtectedFocusListener();

    addFocusListener(mProtFocusListener);

    mProtFocusListener->blockKey(SDLK_LEFT);
    mProtFocusListener->blockKey(SDLK_RIGHT);
    mProtFocusListener->blockKey(SDLK_UP);
    mProtFocusListener->blockKey(SDLK_DOWN);
    mProtFocusListener->blockKey(SDLK_SPACE);
    mProtFocusListener->blockKey(SDLK_RETURN);
    mProtFocusListener->blockKey(SDLK_HOME);
    mProtFocusListener->blockKey(SDLK_END);
}
Beispiel #9
0
DropDown::DropDown(const Widget2 *const widget,
                   ListModel *const listModel,
                   const bool extended,
                   const Modal modal,
                   ActionListener *const listener,
                   const std::string &eventId) :
    ActionListener(),
    BasicContainer(widget),
    KeyListener(),
    MouseListener(),
    FocusListener(),
    SelectionListener(),
    mPopup(CREATEWIDGETR(PopupList, this, listModel, extended, modal)),
    mShadowColor(getThemeColor(ThemeColorId::DROPDOWN_SHADOW)),
    mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
    mPadding(1),
    mImagePadding(2),
    mSpacing(0),
    mFoldedUpHeight(0),
    mSelectionListeners(),
    mExtended(extended),
    mDroppedDown(false),
    mPushed(false),
    mIsDragged(false)
{
    mAllowLogic = false;
    mFrameSize = 2;
    mForegroundColor2 = getThemeColor(ThemeColorId::DROPDOWN_OUTLINE);

    mPopup->setHeight(100);

    // Initialize graphics
    if (instances == 0 && theme)
    {
        // Load the background skin
        for (int i = 0; i < 2; i ++)
        {
            Skin *const skin = theme->load(dropdownFiles[i], "dropdown.xml");
            if (skin)
            {
                if (!i)
                    mSkin = skin;
                const ImageRect &rect = skin->getBorder();
                for (int f = 0; f < 2; f ++)
                {
                    if (rect.grid[f])
                    {
                        rect.grid[f]->incRef();
                        buttons[f][i] = rect.grid[f];
                        buttons[f][i]->setAlpha(mAlpha);
                    }
                    else
                    {
                        buttons[f][i] = nullptr;
                    }
                }
                if (i)
                    theme->unload(skin);
            }
            else
            {
                for (int f = 0; f < 2; f ++)
                    buttons[f][i] = nullptr;
            }
        }

        // get the border skin
        theme->loadRect(skinRect, "dropdown_background.xml", "");
    }

    instances++;

    setWidth(100);
    setFocusable(true);
    setListModel(listModel);

    if (mPopup->getSelected() < 0)
        mPopup->setSelected(0);

    addMouseListener(this);
    addKeyListener(this);
    addFocusListener(this);

    adjustHeight();
//    mPopup->setForegroundColorAll(getThemeColor(ThemeColorId::DROPDOWN),
//        getThemeColor(ThemeColorId::DROPDOWN_OUTLINE));
    mForegroundColor = getThemeColor(ThemeColorId::DROPDOWN);
    mForegroundColor2 = getThemeColor(ThemeColorId::DROPDOWN_OUTLINE);

    if (!eventId.empty())
        setActionEventId(eventId);

    if (listener)
        addActionListener(listener);

    mPopup->adjustSize();

    if (mSkin)
    {
        mSpacing = mSkin->getOption("spacing");
        mFrameSize = CAST_U32(mSkin->getOption("frameSize"));
        mPadding = mSkin->getPadding();
        mImagePadding = mSkin->getOption("imagePadding");
    }
    adjustHeight();
}
Beispiel #10
0
void TextSelectDialog::postInit()
{
    Window::postInit();
    setWindowName("TextSelectDialog");
    setResizable(true);
    setCloseButton(mAllowQuit == AllowQuit_true);
    setStickyButtonLock(true);
    setMinWidth(260);
    setMinHeight(220);
    setDefaultSize(260, 230, ImagePosition::CENTER, 0, 0);

    if (setupWindow != nullptr)
        setupWindow->registerWindowForReset(this);

    setActionEventId("OK");
    mModel = new NamesModel;
    mItemList = CREATEWIDGETR(ListBox,
        this,
        mModel,
        "listbox.xml");
    mScrollArea = new ScrollArea(this, mItemList,
        fromBool(getOptionBool("showbackground", false), Opaque),
        "sell_background.xml");
    mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);

    mSelectButton = new Button(this,
        mSelectButtonName,
        "select",
        BUTTON_SKIN,
        this);
    if (mAllowQuit == AllowQuit_true)
    {
        mQuitButton = new Button(this,
            // TRANSLATORS: sell dialog button
            _("Quit"),
            "quit",
            BUTTON_SKIN,
            this);
    }

    mSelectButton->setEnabled(false);

    mItemList->setDistributeMousePressed(false);
    mItemList->addSelectionListener(this);
    mItemList->setActionEventId("item");
    mItemList->addActionListener(this);

    ContainerPlacer placer(nullptr, nullptr);
    placer = getPlacer(0, 0);

    placer(0, 0, mScrollArea, 8, 5).setPadding(3);
    if (mQuitButton != nullptr)
    {
        placer(6, 5, mSelectButton, 1, 1);
        placer(7, 5, mQuitButton, 1, 1);
    }
    else
    {
        placer(7, 5, mSelectButton, 1, 1);
    }

    Layout &layout = getLayout();
    layout.setRowHeight(0, LayoutType::SET);

    center();
    loadWindowState();

    setVisible(Visible_true);
    enableVisibleSound(true);
}
Beispiel #11
0
void ItemContainer::keyPressed(gcn::KeyEvent &event)
{
    const int columns = std::max(1, getWidth() / gridWidth);
    const int gridSlot = getVisibleSlot(getSelectedItem());
    int itemX = gridSlot % columns;
    int itemY = gridSlot / columns;

    // Handling direction keys: all of these set selectNewItem, and change
    // itemX or itemY checking only that the selection doesn't go off the top,
    // left or right of the grid.  The block below the switch statement then
    // checks that there's an item in that slot (implictly bounds-checking that
    // the selection didn't go off the bottom of the grid).
    bool selectNewItem = false;
    switch (event.getKey().getValue())
    {
        case Key::LEFT:
            if (itemX != 0)
                itemX--;

            selectNewItem = true;
            event.consume();
            break;
        case Key::RIGHT:
            if (itemX < (columns - 1))
                itemX++;

            selectNewItem = true;
            event.consume();
            break;
        case Key::UP:
            if (itemY != 0)
                itemY--;

            selectNewItem = true;
            event.consume();
            break;
        case Key::DOWN:
            itemY++;
            selectNewItem = true;
            event.consume();
            break;
        case Key::ENTER:
        case Key::SPACE:
            if (event.isShiftPressed())
            {
                const std::string actionEventId = getActionEventId();
                setActionEventId("default");
                distributeActionEvent();
                setActionEventId(actionEventId);
            }
            else
                distributeActionEvent();

            event.consume();
            break;
    }

    if (selectNewItem)
    {
        Item* selection = getItemInVisibleSlot(itemX + columns * itemY);

        if (selection)
            setSelectedItemIndex(selection->getInvIndex());
    }
}
void OkDialog::action(const gcn::ActionEvent &event)
{
    setActionEventId(event.getId());
    distributeActionEvent();
    scheduleDelete();
}
Beispiel #13
0
DropDown::DropDown(gcn::ListModel *listModel, gcn::ActionListener* listener,
                   std::string eventId):
    gcn::DropDown::DropDown(listModel,
                            new ScrollArea,
                            new ListBox(listModel))
{
    setFrameSize(2);

    // Initialize graphics
    if (instances == 0)
    {
        // Load the background skin

        // Get the button skin
        buttons[1][0] = Theme::getImageFromTheme("vscroll_up_default.png");
        buttons[0][0] = Theme::getImageFromTheme("vscroll_down_default.png");
        buttons[1][1] = Theme::getImageFromTheme("vscroll_up_pressed.png");
        buttons[0][1] = Theme::getImageFromTheme("vscroll_down_pressed.png");

        if (buttons[0][0])
            buttons[0][0]->setAlpha(mAlpha);
        if (buttons[0][1])
            buttons[0][1]->setAlpha(mAlpha);
        if (buttons[1][0])
            buttons[1][0]->setAlpha(mAlpha);
        if (buttons[1][1])
            buttons[1][1]->setAlpha(mAlpha);

        // get the border skin
        Image *boxBorder = Theme::getImageFromTheme("deepbox.png");
        if (boxBorder)
        {
            int gridx[4] = {0, 3, 28, 31};
            int gridy[4] = {0, 3, 28, 31};
            int a = 0, x, y;

            for (y = 0; y < 3; y++)
            {
                for (x = 0; x < 3; x++)
                {
                    skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y],
                                                          gridx[x + 1] -
                                                          gridx[x] + 1,
                                                          gridy[y + 1] -
                                                          gridy[y] + 1);
                    if (skin.grid[a])
                        skin.grid[a]->setAlpha(mAlpha);
                    a++;
                }
            }

            boxBorder->decRef();
        }
    }

    instances++;

    mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT);
    mShadowColor = Theme::getThemeColor(Theme::DROPDOWN_SHADOW);
    setForegroundColor(Theme::getThemeColor(Theme::TEXT));

    if (!eventId.empty())
        setActionEventId(eventId);

    if (listener)
        addActionListener(listener);
}