Beispiel #1
0
void Tab::init()
{
    addMouseListener(this);
    setFocusable(false);
    setFrameSize(0);
    mFlash = 0;

    addWidgetListener(this);

    if (mInstances == 0)
    {
        // Load the skin
        Theme *const theme = Theme::instance();
        if (theme)
        {
            for (int mode = 0; mode < TAB_COUNT; mode ++)
                tabImg[mode] = theme->load(data[mode], "tab.xml");
        }
        updateAlpha();
    }
    mInstances++;

    add(mLabel);

    const Skin *const skin = tabImg[TAB_STANDARD];
    if (!skin)
        return;
    const int padding = skin->getPadding();

    mLabel->setPosition(padding, padding);
}
ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity):
    mInventory(inventory),
    mGridColumns(1),
    mGridRows(1),
    mSelectedIndex(-1),
    mHighlightedIndex(-1),
    mLastUsedSlot(-1),
    mSelectionStatus(SEL_NONE),
    mForceQuantity(forceQuantity),
    mSwapItems(false),
    mDescItems(false)
{
    mItemPopup = new ItemPopup;
    setFocusable(true);

    ResourceManager *resman = ResourceManager::getInstance();

    mSelImg = resman->getImage("graphics/gui/selection.png");
    if (!mSelImg)
        logger->error("Unable to load selection.png");

    addKeyListener(this);
    addMouseListener(this);
    addWidgetListener(this);
}
Beispiel #3
0
ShortcutContainer::ShortcutContainer(Widget2 *const widget) :
    Widget(widget),
    WidgetListener(),
    MouseListener(),
    mBackgroundImg(nullptr),
    mMaxItems(0),
    mBoxWidth(1),
    mBoxHeight(1),
    mGridWidth(1),
    mGridHeight(1),
    mVertexes(new ImageCollection)
{
    mAllowLogic = false;

    addMouseListener(this);
    addWidgetListener(this);

    mForegroundColor = getThemeColor(ThemeColorId::TEXT);
    mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE);

    mBackgroundImg = Theme::getImageFromThemeXml(
        "item_shortcut_background.xml", "background.xml");

    if (mBackgroundImg)
    {
        mBackgroundImg->setAlpha(settings.guiAlpha);
        mBoxHeight = mBackgroundImg->getHeight();
        mBoxWidth = mBackgroundImg->getWidth();
    }
    else
    {
        mBoxHeight = 1;
        mBoxWidth = 1;
    }
}
Beispiel #4
0
ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity):
    mInventory(inventory),
    mGridColumns(1),
    mGridRows(1),
    mSelectedIndex(-1),
    mHighlightedIndex(-1),
    mLastUsedSlot(-1),
    mSelectionStatus(SEL_NONE),
    mForceQuantity(forceQuantity),
    mSwapItems(false),
    mDescItems(false),
    mTag(0),
    mSortType(0),
    mItemPopup(new ItemPopup),
    mShowMatrix(nullptr),
    mClicks(1),
    mEquipedColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED)),
    mUnEquipedColor(Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED))
{
    setFocusable(true);

    mSelImg = Theme::getImageFromTheme("selection.png");
    if (!mSelImg)
        logger->log1("Error: Unable to load selection.png");

    addKeyListener(this);
    addMouseListener(this);
    addWidgetListener(this);
}
Desktop::Desktop(const Widget2 *const widget) :
    Container(widget),
    gcn::WidgetListener(),
    mWallpaper(nullptr),
    mVersionLabel(nullptr),
    mBackgroundColor(getThemeColor(Theme::BACKGROUND, 128)),
    mBackgroundGrayColor(getThemeColor(Theme::BACKGROUND_GRAY))
{
    addWidgetListener(this);

    Wallpaper::loadWallpapers();

    const std::string appName = branding.getValue("appName", std::string());
    if (appName.empty())
    {
        mVersionLabel = new Label(this, FULL_VERSION);
    }
    else
    {
        mVersionLabel = new Label(this, strprintf("%s (%s)", FULL_VERSION,
            appName.c_str()));
    }

    mVersionLabel->setBackgroundColor(getThemeColor(Theme::BACKGROUND, 128));
}
Beispiel #6
0
WidgetGroup::WidgetGroup(std::string group, int height, int spacing) :
    mSpacing(spacing),
    mCount(0),
    mGroup(group),
    mLastX(spacing)
{
    setHeight(height);
    addWidgetListener(this);
}
SetupTab::SetupTab(const Widget2 *const widget) :
    Container(widget),
    gcn::ActionListener(),
    gcn::WidgetListener(),
    mName()
{
    setOpaque(false);
    addWidgetListener(this);
}
ProgressBar::ProgressBar(const Widget2 *const widget,
                         float progress,
                         const int width,
                         const int height,
                         const ProgressColorIdT backColor,
                         const std::string &skin,
                         const std::string &skinFill) :
    Widget(widget),
    WidgetListener(),
    mFillRect(),
    mTextChunk(),
    mSkin(nullptr),
    mProgress(progress),
    mProgressToGo(progress),
    mBackgroundColorToGo(),
    mText(),
    mVertexes(new ImageCollection),
    mProgressPalette(backColor),
    mPadding(2),
    mFillPadding(3),
    mFillImage(false),
    mSmoothProgress(true),
    mSmoothColorChange(true),
    mTextChanged(true)
{
    mBackgroundColor = Theme::getProgressColor(
        backColor >= ProgressColorId::PROG_HP
        ? backColor : ProgressColorId::PROG_HP,
        mProgress);
    mBackgroundColorToGo = mBackgroundColor;
    mForegroundColor2 = getThemeColor(ThemeColorId::PROGRESS_BAR_OUTLINE);

    // The progress value is directly set at load time:
    if (mProgress > 1.0F || mProgress < 0.0F)
        mProgress = 1.0F;

    mForegroundColor = getThemeColor(ThemeColorId::PROGRESS_BAR);
    addWidgetListener(this);
    setSize(width, height);

    if (theme)
    {
        mSkin = theme->load(skin, "progressbar.xml");
        if (mSkin)
        {
            setPadding(mSkin->getPadding());
            mFillPadding = mSkin->getOption("fillPadding");
            mFillImage = mSkin->getOption("fillImage") != 0;
            if (mFillImage)
                theme->loadRect(mFillRect, skinFill, "progressbar_fill.xml");
        }
        setHeight(2 * mPadding + getFont()->getHeight() + 2);
    }

    mInstances++;
}
Beispiel #9
0
ProgressBar::ProgressBar(float progress,
                         int width, int height,
                         int color):
    gcn::Widget(),
    mSmoothProgress(true),
    mProgressPalette(color),
    mSmoothColorChange(true),
    mVertexes(new GraphicsVertexes()),
    mRedraw(true)
{
    // The progress value is directly set at load time:
    if (progress > 1.0f || progress < 0.0f)
        progress = 1.0f;

    mProgress = progress;
    mProgressToGo = progress;

    mColor = Theme::getProgressColor(color >= 0 ? color : 0, mProgress);
    mColorToGo = mColor;

    addWidgetListener(this);

    setSize(width, height);

    if (mInstances == 0)
    {
        Image *dBorders = Theme::getImageFromTheme("progress.png");
        if (!dBorders)
            dBorders = Theme::getImageFromTheme("vscroll_grey.png");
        if (dBorders)
        {
            mBorder.grid[0] = dBorders->getSubImage(0, 0, 4, 4);
            mBorder.grid[1] = dBorders->getSubImage(4, 0, 3, 4);
            mBorder.grid[2] = dBorders->getSubImage(7, 0, 4, 4);
            mBorder.grid[3] = dBorders->getSubImage(0, 4, 4, 10);
            mBorder.grid[4] = dBorders->getSubImage(4, 4, 3, 10);
            mBorder.grid[5] = dBorders->getSubImage(7, 4, 4, 10);
            mBorder.grid[6] = dBorders->getSubImage(0, 15, 4, 4);
            mBorder.grid[7] = dBorders->getSubImage(4, 15, 3, 4);
            mBorder.grid[8] = dBorders->getSubImage(7, 15, 4, 4);

            for (int i = 0; i < 9; i++)
                mBorder.grid[i]->setAlpha(mAlpha);

            dBorders->decRef();
        }
        else
        {
            for (int f = 0; f < 9; f ++)
                mBorder.grid[f] = nullptr;
        }

    }

    mInstances++;
}
Beispiel #10
0
SetupTab::SetupTab(const Widget2 *const widget) :
    Container(widget),
    ActionListener(),
    WidgetListener(),
    mName()
{
    setOpaque(Opaque_false);
    addWidgetListener(this);
    setSelectable(false);
}
Beispiel #11
0
ScrollArea::ScrollArea():
    gcn::ScrollArea(),
    mX(0),
    mY(0),
    mHasMouse(false),
    mOpaque(true)
{
    addWidgetListener(this);
    init();
}
Beispiel #12
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);
}
HorizontContainer::HorizontContainer(const Widget2 *const widget,
                                     const int height,
                                     const int spacing) :
    Container(widget),
    WidgetListener(),
    mSpacing(spacing),
    mCount(0),
    mLastX(spacing)
{
    setHeight(height);
    addWidgetListener(this);
}
Beispiel #14
0
Window::Window(const std::string& caption, bool modal, Window *parent,
               const std::string& skin, bool visible):
    gcn::Window(caption),
    mOldVisibility(false),
    mGrip(NULL),
    mClose(NULL),
    mParent(parent),
    mLayout(NULL),
    mWindowName("window"),
    mDefaultSkinPath(skin),
    mShowTitle(true),
    mModal(modal),
    mDefaultVisible(visible),
    mSaveVisibility(true),
    mHasMaxDimensions(false),
    mMinWinWidth(100),
    mMinWinHeight(40),
    mMaxWinWidth(graphics->getWidth()),
    mMaxWinHeight(graphics->getHeight())
{
    logger->log("Window::Window(\"%s\")", caption.c_str());

    if (!windowContainer)
        throw GCN_EXCEPTION("Window::Window(): no windowContainer set");

    if (!skinLoader)
        skinLoader = new SkinLoader();

    instances++;

    setFrameSize(0);
    setPadding(3);
    setTitleBarHeight(20);

    // Loads the skin
    mSkin = skinLoader->load(skin, mDefaultSkinPath);

    // Add this window to the window container
    windowContainer->add(this);

    if (mModal)
    {
        gui->setCursorType(Gui::CURSOR_POINTER);
        requestModalFocus();
    }

    // Windows are invisible by default
    setVisible(false);

    addWidgetListener(this);
}
Beispiel #15
0
WidgetGroup::WidgetGroup(const Widget2 *const widget,
                         const std::string &group, const int height,
                         const int spacing) :
    Container(widget),
    gcn::WidgetListener(),
    gcn::ActionListener(),
    mSpacing(spacing),
    mCount(0),
    mGroup(group),
    mLastX(spacing)
{
    setHeight(height);
    addWidgetListener(this);
}
Beispiel #16
0
	TwoButton::TwoButton(Image *up_file , Image *down_file, Image *hover_file, const std::string& caption):
		Button(),
		m_upImage(up_file),
		m_downImage(down_file),
		m_hoverImage(hover_file),
		x_downoffset(0),
		y_downoffset(0) {
		addWidgetListener(this);

		m_hoverImage = hover_file;
		setFrameSize(0);
		adjustSize();
		mCaption = caption;
	}
Beispiel #17
0
void TabbedArea::postInit()
{
    mTabContainer->setOpaque(Opaque_false);

    add(mTabContainer);
    add(mWidgetContainer);

    mWidgetContainer->setOpaque(Opaque_false);
    addWidgetListener(this);

    mArrowButton[0] = new Button(this, "<", "shift_left", this);
    mArrowButton[1] = new Button(this, ">", "shift_right", this);

    widgetResized(Event(nullptr));
}
Beispiel #18
0
RichTextBox::RichTextBox(unsigned int mode, bool opaque):
    gcn::Widget(),
    mLaidOutTextValid(false),
    mLinkHandler(NULL),
    mMode(mode),
    mHighMode(UNDERLINE | BACKGROUND),
    mOpaque(opaque),
    mUseLinksAndUserColors(true),
    mSelectedLink(-1),
    mMaxRows(0)
{
    setFocusable(false);
    addMouseListener(this);
    addWidgetListener(this);
}
FlowContainer::FlowContainer(const Widget2 *const widget,
                             const int boxWidth,
                             const int boxHeight) :
    Container(widget),
    WidgetListener(),
    mBoxWidth(boxWidth),
    mBoxHeight(boxHeight),
    mGridWidth(1),
    mGridHeight(1)
{
    addWidgetListener(this);
    if (!mBoxWidth)
        mBoxWidth = 1;
    if (!mBoxHeight)
        mBoxHeight = 1;
}
Beispiel #20
0
VertContainer::VertContainer(const Widget2 *const widget,
                             const int verticalItemSize,
                             const bool resizable,
                             const int leftSpacing) :
    Container(widget),
    WidgetListener(),
    mResizableWidgets(),
    mVerticalItemSize(verticalItemSize),
    mCount(0),
    mNextY(0),
    mLeftSpacing(leftSpacing),
    mVerticalSpacing(0),
    mResizable(resizable)
{
    addWidgetListener(this);
}
Beispiel #21
0
TabbedArea::TabbedArea() : gcn::TabbedArea(),
                           mTabsWidth(0),
                           mVisibleTabsWidth(0),
                           mTabScrollIndex(0)
{
    mWidgetContainer->setOpaque(false);
    addWidgetListener(this);

    mArrowButton[0] = new Button(std::string(), "shift_left", this);
    mArrowButton[1] = new Button(std::string(), "shift_right", this);
    mArrowButton[0]->setButtonIcon("tab_arrows_left.png");
    mArrowButton[1]->setButtonIcon("tab_arrows_right.png");

    add(mArrowButton[0]);
    add(mArrowButton[1]);

    widgetResized(NULL);
}
ItemShortcutContainer::ItemShortcutContainer():
    ShortcutContainer(),
    mItemClicked(false),
    mItemMoved(NULL)
{
    addMouseListener(this);
    addWidgetListener(this);

    mItemPopup = new ItemPopup;

    ResourceManager *resman = ResourceManager::getInstance();

    mBackgroundImg = resman->getImage("graphics/gui/item_shortcut_bgr.png");
    mMaxItems = itemShortcut->getItemCount();

    mBackgroundImg->setAlpha(config.getValue("guialpha", 0.8));

    mBoxHeight = mBackgroundImg->getHeight();
    mBoxWidth = mBackgroundImg->getWidth();
}
Beispiel #23
0
Popup::Popup(const std::string &name, std::string skin):
    mPopupName(name),
    mMinWidth(100),
    mMinHeight(40),
    mMaxWidth(mainGraphics->mWidth),
    mMaxHeight(mainGraphics->mHeight),
    mVertexes(new GraphicsVertexes()),
    mRedraw(true)
{
    logger->log("Popup::Popup(\"%s\")", name.c_str());

    if (!windowContainer)
        throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set");

    addWidgetListener(this);

    setPadding(3);

    if (skin == "")
        skin = "popup.xml";

    // Loads the skin
    if (Theme::instance())
    {
        mSkin = Theme::instance()->load(skin);
        if (mSkin)
            setPadding(mSkin->getPadding());
    }
    else
    {
        mSkin = nullptr;
    }

    // Add this window to the window container
    windowContainer->add(this);

    // Popups are invisible by default
    setVisible(false);
}
Beispiel #24
0
ProgressBar::ProgressBar(const Widget2 *const widget, float progress,
                         const int width, const int height,
                         const int color):
    gcn::Widget(),
    Widget2(widget),
    gcn::WidgetListener(),
    mSkin(nullptr),
    mProgress(progress),
    mProgressToGo(progress),
    mSmoothProgress(true),
    mProgressPalette(color),
    mColor(Theme::getProgressColor(color >= 0 ? color : 0, mProgress)),
    mColorToGo(mColor),
    mSmoothColorChange(true),
    mText(),
    mVertexes(new ImageCollection),
    mRedraw(true),
    mPadding(2),
    mFillPadding(3),
    mOutlineColor(getThemeColor(Theme::OUTLINE))
{
    // The progress value is directly set at load time:
    if (mProgress > 1.0f || mProgress < 0.0f)
        mProgress = 1.0f;

    mForegroundColor = getThemeColor(Theme::PROGRESS_BAR);
    addWidgetListener(this);
    setSize(width, height);

    if (Theme::instance())
    {
        mSkin = Theme::instance()->load("progressbar.xml", "");
        setPadding(mSkin->getPadding());
        mFillPadding = mSkin->getOption("fillPadding");
        setHeight(2 * mPadding + getFont()->getHeight() + 2);
    }

    mInstances++;
}
EmoteShortcutContainer::EmoteShortcutContainer():
    ShortcutContainer(),
    mEmoteImg(),
    mEmotePopup(new TextPopup),
    mForegroundColor2(getThemeColor(Theme::TEXT_OUTLINE)),
    mEmoteClicked(false),
    mEmoteMoved(0)
{
    addMouseListener(this);
    addWidgetListener(this);

    mBackgroundImg = Theme::getImageFromThemeXml(
        "item_shortcut_background.xml", "background.xml");

    if (mBackgroundImg)
        mBackgroundImg->setAlpha(Client::getGuiAlpha());

    // Setup emote sprites
    for (int i = 0; i <= EmoteDB::getLast(); i++)
    {
        const EmoteSprite *const sprite = EmoteDB::getSprite(i, true);
        if (sprite && sprite->sprite)
            mEmoteImg.push_back(sprite);
    }

    mMaxItems = MAX_ITEMS;

    if (mBackgroundImg)
    {
        mBoxHeight = mBackgroundImg->getHeight();
        mBoxWidth = mBackgroundImg->getWidth();
    }
    else
    {
        mBoxHeight = 1;
        mBoxWidth = 1;
    }
    mForegroundColor = getThemeColor(Theme::TEXT);
}
EmoteShortcutContainer::EmoteShortcutContainer():
    ShortcutContainer(),
    mEmoteClicked(false),
    mEmoteMoved(0)
{
    addMouseListener(this);
    addWidgetListener(this);

    mBackgroundImg = Theme::getImageFromTheme("item_shortcut_bgr.png");

    mBackgroundImg->setAlpha(config.getFloatValue("guialpha"));

    // Setup emote sprites
    for (int i = 0; i <= EmoteDB::getLast(); i++)
    {
        mEmoteImg.push_back(EmoteDB::get(i)->sprite);
    }

    mMaxItems = EmoteDB::getLast() < MAX_ITEMS ? EmoteDB::getLast() : MAX_ITEMS;

    mBoxHeight = mBackgroundImg->getHeight();
    mBoxWidth = mBackgroundImg->getWidth();
}
Beispiel #27
0
TabbedArea::TabbedArea(const Widget2 *const widget) :
    Widget2(widget),
    gcn::ActionListener(),
    gcn::BasicContainer(),
    gcn::KeyListener(),
    gcn::MouseListener(),
    gcn::WidgetListener(),
    mSelectedTab(nullptr),
    mTabContainer(new gcn::Container()),
    mWidgetContainer(new gcn::Container()),
    mTabsToDelete(),
    mTabs(),
    mOpaque(false),
    mTabsWidth(0),
    mVisibleTabsWidth(0),
    mTabScrollIndex(0),
    mEnableScrollButtons(false),
    mRightMargin(0),
    mFollowDownScroll(false),
    mBlockSwitching(true)
{
    setFocusable(true);
    addKeyListener(this);
    addMouseListener(this);
    mTabContainer->setOpaque(false);

    add(mTabContainer);
    add(mWidgetContainer);

    mWidgetContainer->setOpaque(false);
    addWidgetListener(this);

    mArrowButton[0] = new Button(this, "<", "shift_left", this);
    mArrowButton[1] = new Button(this, ">", "shift_right", this);

    widgetResized(gcn::Event(nullptr));
}
Beispiel #28
0
Desktop::Desktop(const Widget2 *const widget) :
    Container(widget),
    LinkHandler(),
    WidgetListener(),
    mWallpaper(nullptr),
    mVersionLabel(new BrowserBox(this, BrowserBox::AUTO_WRAP, false,
        "browserbox.xml")),
    mSkin(nullptr),
    mBackgroundColor(getThemeColor(ThemeColorId::BACKGROUND, 128)),
    mBackgroundGrayColor(getThemeColor(ThemeColorId::BACKGROUND_GRAY)),
    mShowBackground(true)
{
    addWidgetListener(this);

    Wallpaper::loadWallpapers();

    if (theme)
        mSkin = theme->load("desktop.xml", "");

    if (mSkin)
        mShowBackground = mSkin->getOption("showBackground");

    const std::string appName = branding.getValue("appName", std::string());
    if (appName.empty())
    {
        mVersionLabel->addRow(FULL_VERSION);
    }
    else
    {
        mVersionLabel->addRow(strprintf("%s (%s)", FULL_VERSION,
            appName.c_str()));
    }
    mVersionLabel->addRow("copyright",
        "(C) ManaPlus developers, http://manaplus.org");
    mVersionLabel->setLinkHandler(this);
}
VertContainer::VertContainer(int spacing):
        mSpacing(spacing),
        mCount(0)
{
    addWidgetListener(this);
}
FlowContainer::FlowContainer(int boxWidth, int boxHeight):
    mBoxWidth(boxWidth), mBoxHeight(boxHeight),
    mGridWidth(1), mGridHeight(1)
{
    addWidgetListener(this);
}