Exemple #1
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);
}
//--------------------------------------------------------------
// constructor
mgUglyButton::mgUglyButton(
  mgControl* parent,
  const char* cntlName)
: mgButtonControl(parent, cntlName)
{
  m_mode = MG_BUTTON_UP;

  mgStyle* style = getStyle();

  // assume style has set all our format elements
  style->getFontAttr(MG_STYLE_BUTTON, m_cntlName, "font", m_font);

  style->getFrameAttr(MG_STYLE_BUTTON, m_cntlName, "upFrame", m_upFrame);
  style->getFrameAttr(MG_STYLE_BUTTON, m_cntlName, "hoverFrame", m_hoverFrame);
  style->getFrameAttr(MG_STYLE_BUTTON, m_cntlName, "downFrame", m_downFrame);
  style->getFrameAttr(MG_STYLE_BUTTON, m_cntlName, "disFrame", m_disFrame);

  style->getColorAttr(MG_STYLE_BUTTON, m_cntlName, "upColor", m_upColor);
  style->getColorAttr(MG_STYLE_BUTTON, m_cntlName, "hoverColor", m_hoverColor);
  style->getColorAttr(MG_STYLE_BUTTON, m_cntlName, "downColor", m_downColor);
  style->getColorAttr(MG_STYLE_BUTTON, m_cntlName, "disColor", m_disColor);

  m_actionListeners = NULL;
  addMouseListener((mgMouseListener*) this);
  addFocusListener((mgFocusListener*) this);
}
Exemple #3
0
TabbedArea::TabbedArea(bool hide) :
    Container(),
    mHideWhenOneTab(hide),
    mSelectedTab(NULL)
{
    setFocusable(false);
    addKeyListener(this);
    addMouseListener(this);

    mTabContainer = new Container();
    mTabContainer->setOpaque(false);
    mWidgetContainer = new Container();
    mWidgetContainer->setOpaque(false);

    add(mTabContainer);
    add(mWidgetContainer);

    mProtFocusListener = new ProtectedFocusListener();

    addFocusListener(mProtFocusListener);

    mProtFocusListener->blockKey(SDLK_LEFT);
    mProtFocusListener->blockKey(SDLK_RIGHT);
    mProtFocusListener->blockKey(SDLK_UP);
    mProtFocusListener->blockKey(SDLK_DOWN);
}
//--------------------------------------------------------------
// constructor
mgSimpleField::mgSimpleField(
  mgControl* parent,
  const char* cntlName)
: mgFieldControl(parent, cntlName)
{
  m_displayCount = 20;  // default
  m_cursorPosn = 0;
  m_scrollPosn = 0;
  m_insertMode = true;
  m_changed = false;
  m_history = NULL;  // not enabled

  mgStyle* style = getStyle();

  // assume style has set all our format elements
  style->getFontAttr(MG_STYLE_FIELD, getName(), "font", m_font);

  style->getFrameAttr(MG_STYLE_FIELD, getName(), "upFrame", m_upFrame);
  style->getFrameAttr(MG_STYLE_FIELD, getName(), "hoverFrame", m_hoverFrame);
  style->getFrameAttr(MG_STYLE_FIELD, getName(), "downFrame", m_downFrame);
  style->getFrameAttr(MG_STYLE_FIELD, getName(), "disFrame", m_disFrame);

  style->getColorAttr(MG_STYLE_FIELD, getName(), "upColor", m_upColor);
  style->getColorAttr(MG_STYLE_FIELD, getName(), "hoverColor", m_hoverColor);
  style->getColorAttr(MG_STYLE_FIELD, getName(), "downColor", m_downColor);
  style->getColorAttr(MG_STYLE_FIELD, getName(), "disColor", m_disColor);

  m_hasMouse = false;

  m_changeListeners = NULL;
  addMouseListener((mgMouseListener*) this);
  addKeyListener((mgKeyListener*) this);
  addFocusListener((mgFocusListener*) this);
}
Exemple #5
0
//--------------------------------------------------------------
// constructor
mgUglyList::mgUglyList(
  mgControl* parent,
  const char* cntlName)
: mgListControl(parent, cntlName)
{
  m_selected = -1;
  m_displayLines = 5;
  m_multiSelect = false;
  m_hasIcons = false;
  m_scrollPosn = 0;
  m_hover = -1;
  
  mgStyle* style = getStyle();
  style->getFontAttr(MG_STYLE_LIST, m_cntlName, "font", m_font);
  
  style->getFrameAttr(MG_STYLE_LIST, m_cntlName, "upFrame", m_upFrame);
  style->getFrameAttr(MG_STYLE_LIST, m_cntlName, "disFrame", m_disFrame);

  style->getFrameAttr(MG_STYLE_LIST, m_cntlName, "itemUpFrame", m_itemUpFrame);
  style->getFrameAttr(MG_STYLE_LIST, m_cntlName, "itemHoverFrame", m_itemHoverFrame);
  style->getFrameAttr(MG_STYLE_LIST, m_cntlName, "itemDownFrame", m_itemDownFrame);
  style->getFrameAttr(MG_STYLE_LIST, m_cntlName, "itemDisFrame", m_itemDisFrame);

  style->getColorAttr(MG_STYLE_LIST, m_cntlName, "itemUpColor", m_itemUpColor);
  style->getColorAttr(MG_STYLE_LIST, m_cntlName, "itemHoverColor", m_itemHoverColor);
  style->getColorAttr(MG_STYLE_LIST, m_cntlName, "itemDownColor", m_itemDownColor);
  style->getColorAttr(MG_STYLE_LIST, m_cntlName, "itemDisColor", m_itemDisColor);

  // set icon height to 80% line height
  m_iconHeight = (m_font->getHeight()*8)/10;
  m_lineHeight = max(m_iconHeight, m_font->getHeight());

  // add any item framing -- all frames should be same size as itemUpFrame
  if (m_itemUpFrame != NULL)
  {
    mgDimension size;
    m_itemUpFrame->getOutsideSize(mgDimension(0, m_lineHeight), size);
    m_lineHeight = size.m_height;
  }
      
  // create the scrollbars, so we can get preferred size correct
  m_vertScroller = new mgUglyScrollbar(this);
  m_vertScroller->setHorizontal(false);
  m_vertScroller->setVisible(false);
  m_vertScroller->addScrollListener(this);

  m_horzScroller = NULL;
/* =-= not used or laid out correctly
  m_horzScroller = new mgUglyScrollbar(this);
  m_horzScroller->setHorizontal(true);
  m_horzScroller->setVisible(false);
  m_horzScroller->addScrollListener(this);
*/

  m_selectListeners = NULL;

  addMouseListener(this);
  addFocusListener(this);
}
Exemple #6
0
ChatInput::ChatInput() :
    TextField(),
    mProxy(NULL)
{
    setVisible(false);
    addFocusListener(this);
    mCurHist = mHistory.end();
}
Exemple #7
0
	void Button::init(Icon *icon,const std::string &label)
	{
		setThemeName("Button");
		setDefaultIcon(icon);
		addMouseListener(this);
		addFocusListener(this);
		setText(label);
	}
GlassCanvas::GlassCanvas() : GlassContainer(), GlassWidget(this) {
	setOpaque(false);
	
	//for GlassWidget
	addActionListener(this);
	addMouseListener(this);
	addFocusListener(this);
	addKeyListener(this);
}
Exemple #9
0
 ChatInput(ChatWindow *const window, TabbedArea *const tabs):
     TextField(window, "", false),
     mWindow(window),
     mChatTabs(tabs),
     mFocusGaining(false)
 {
     setVisible(false);
     addFocusListener(this);
 }
Exemple #10
0
	ClickLabel::ClickLabel()  {
		mGuiFont = static_cast<FIFE::GuiFont*> (getFont());
// 		setAlignment(Graphics::LEFT);
		setTextWrapping(false);
		setFrameSize(0);
		addMouseListener(this);
		addKeyListener(this);
		addFocusListener(this);

	}
Exemple #11
0
	ClickLabel::ClickLabel(const std::string& caption) {
		mGuiFont = static_cast<FIFE::GuiFont*> (getFont());
// 		setAlignment(Graphics::LEFT);
		setTextWrapping(false);
		setCaption(caption);
		setFrameSize(0);
		addMouseListener(this);
		addKeyListener(this);
		addFocusListener(this);

		wrapText();
	}
Exemple #12
0
    DropDown::DropDown(ListModel *listModel,
                       ScrollArea *scrollArea,
                       ListBox *listBox)
    {
        setWidth(100);
        setFocusable(true);
        mDroppedDown = false;
        mPushed = false;
        mIsDragged = false;

        setInternalFocusHandler(&mInternalFocusHandler);

        mInternalScrollArea = (scrollArea == NULL);
        mInternalListBox = (listBox == NULL);

        if (mInternalScrollArea)
        {
            mScrollArea = new ScrollArea();
        }
        else
        {
            mScrollArea = scrollArea;
        }

        if (mInternalListBox)
        {
            mListBox = new ListBox();
        }
        else
        {
            mListBox = listBox;
        }

        mScrollArea->setContent(mListBox);
        add(mScrollArea);

        mListBox->addActionListener(this);
        mListBox->addSelectionListener(this);

        setListModel(listModel);

        if (mListBox->getSelected() < 0)
        {
            mListBox->setSelected(0);
        }

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

        adjustHeight();
        setBorderSize(1);
    }
Exemple #13
0
TabbedArea::TabbedArea() :
    gcn::TabbedArea()
{
    mWidgetContainer->setOpaque(false);

    mProtFocusListener = new ProtectedFocusListener();

    addFocusListener(mProtFocusListener);

    mProtFocusListener->blockKey(SDLK_LEFT);
    mProtFocusListener->blockKey(SDLK_RIGHT);
    mProtFocusListener->blockKey(SDLK_UP);
    mProtFocusListener->blockKey(SDLK_DOWN);
}
Exemple #14
0
    Button::Button()
        : mHasMouse(false),
          mKeyPressed(false),
          mMousePressed(false),
          mAlignment(Graphics::CENTER),
          mSpacing(4)
    {
        setFocusable(true);
        adjustSize();
        setBorderSize(1);

        addMouseListener(this);
        addKeyListener(this);
        addFocusListener(this);
    }
Exemple #15
0
    Button::Button(const std::string& caption)
            : mCaption(caption),
              mHasMouse(false),
              mKeyPressed(false),
              mMousePressed(false),
              mAlignment(Graphics::CENTER),
              mSpacing(4)
    {
        SetFocusable(true);
        AdjustSize();
        SetFrameSize(1);

        addMouseListener(this);
        addKeyListener(this);
        addFocusListener(this);
    }
Exemple #16
0
InventoryDialog::InventoryDialog(Inventory* inventory)
{
	mInventory = inventory;

	setSize(260, 180);
	setOpaque(false);
	setFocusable(true);
	addFocusListener(this);
	setEnabled(true);

	mLabelContainer = new DbContainer();
	mLabelContainer->setSize(260, 20);
	add(mLabelContainer);
	mLabel = new gcn::Label("ITEMS");
	mLabel->adjustSize();
	mLabelContainer->add(mLabel, 
						 mLabelContainer->getWidth() / 2 - mLabel->getWidth() / 2,
						 mLabelContainer->getHeight() / 2 - mLabel->getHeight() / 2);

	
	mListContainer = new DbContainer();
	mListContainer->setSize(260, 110);
	mListContainer->setVisible(true);
	add(mListContainer, 0, 22);
	mList = new DBListBox();
	mList->addActionListener(this);
	mList->addSelectionListener(this);
	mListModel = new InventoryListModel(mInventory);
	mList->setListModel(mListModel);
	mList->setWidth(250);
	mScrollArea = new DbScrollArea();
	mScrollArea->setSize(250, 99);
	mScrollArea->setContent(mList);
	mListContainer->add(mScrollArea, 5, 5);

	mInfoContainer = new DbContainer();
	mInfoContainer->setSize(260, 30);
	mInfoContainer->setVisible(true);
	add(mInfoContainer, 0, 135);
	mInfo = new gcn::TextBox();
	mInfo->setOpaque(false);
	mInfo->setText("");
	mInfo->setEditable(false);
	mInfoContainer->add(mInfo, 5, 5);
}
Exemple #17
0
    Button::Button() :
        gcn::Widget(),
        gcn::MouseListener(),
        gcn::KeyListener(),
        gcn::FocusListener(),
        mCaption(),
        mHasMouse(false),
        mKeyPressed(false),
        mMousePressed(false),
        mAlignment(Graphics::CENTER),
        mSpacing(4)
    {
        setFocusable(true);
        adjustSize();
        setFrameSize(1);

        addMouseListener(this);
        addKeyListener(this);
        addFocusListener(this);
    }
GlassWindow::GlassWindow() : gcn::Window(), GlassWidget(this), wmhandler() {
	titleBar = gcn::Image::load("/gui/standard/bar_gradient.png");
	mTitleBarHeight = titleBar->getHeight()+3;
	titleBarContainer._setParent(this);
	setAlignment(gcn::Graphics::LEFT);
	shadeState = SH_OPEN;
	titleVisible = true;
	mGradient = false;
	frame = NULL;
	mBorder = 0;
	
	setBackgroundColor(gcn::Color(213,213,213));
	
	wmhandler.setWindow(this);
	
	buildTitleBar(WT_ALL);
	
	//for GlassWidget
	addActionListener(this);
	addFocusListener(this);
	gui->addGlobalKeyListener(this);
}
Exemple #19
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);
}
Exemple #20
0
void Slider::init()
{
    int x, y, w, h,o1,o2;
    setFrameSize(0);

    // Load resources
    if (mInstances == 0)
    {
        mAlpha = config.getValue("guialpha", 0.8);

        ResourceManager *resman = ResourceManager::getInstance();
        Image *slider = resman->getImage("graphics/gui/slider.png");
        Image *highlight = resman->getImage("graphics/gui/sliderhi.png");

        x = 0; y = 0;
        w = 15; h = 6;
        o1 = 4; o2 = 11;
        hStart = slider->getSubImage(x, y, o1 - x, h);
        hStartHi = highlight->getSubImage(x, y, o1 - x, h);
        hMid = slider->getSubImage(o1, y, o2 - o1, h);
        hMidHi = highlight->getSubImage(o1, y, o2 - o1, h);
        hEnd = slider->getSubImage(o2, y, w - o2 + x, h);
        hEndHi = highlight->getSubImage(o2, y, w - o2 + x, h);

        x = 6; y = 8;
        w = 9; h = 10;
        hGrip = slider->getSubImage(x, y, w, h);
        hGripHi = highlight->getSubImage(x, y, w, h);

        x = 0; y = 6;
        w = 6; h = 21;
        o1 = 10; o2 = 18;
        vStart = slider->getSubImage(x, y, w, o1 - y);
        vStartHi = highlight->getSubImage(x, y, w, o1 - y);
        vMid = slider->getSubImage(x, o1, w, o2 - o1);
        vMidHi = highlight->getSubImage(x, o1, w, o2 - o1);
        vEnd = slider->getSubImage(x, o2, w, h - o2 + y);
        vEndHi = highlight->getSubImage(x, o2, w, h - o2 + y);

        x = 6; y = 8;
        w = 9; h = 10;
        vGrip = slider->getSubImage(x, y, w, h);
        vGripHi = highlight->getSubImage(x, y, w, h);

        slider->decRef();
        highlight->decRef();

        hStart->setAlpha(mAlpha);
        hStartHi->setAlpha(mAlpha);
        hMid->setAlpha(mAlpha);
        hMidHi->setAlpha(mAlpha);
        hEnd->setAlpha(mAlpha);
        hEndHi->setAlpha(mAlpha);
        hGrip->setAlpha(mAlpha);
        hGripHi->setAlpha(mAlpha);

        vStart->setAlpha(mAlpha);
        vStartHi->setAlpha(mAlpha);
        vMid->setAlpha(mAlpha);
        vMidHi->setAlpha(mAlpha);
        vEnd->setAlpha(mAlpha);
        vEndHi->setAlpha(mAlpha);
        vGrip->setAlpha(mAlpha);
        vGripHi->setAlpha(mAlpha);

        mConfigListener = new SliderConfigListener(this);
        config.addListener("guialpha", mConfigListener);
    }

    mProtFocusListener = new ProtectedFocusListener();

    addFocusListener(mProtFocusListener);

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

    mInstances++;

    setMarkerLength(hGrip->getWidth());
}
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();
}