summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/avatarlistbox.cpp5
-rw-r--r--src/gui/widgets/browserbox.cpp19
-rw-r--r--src/gui/widgets/browserbox.h5
-rw-r--r--src/gui/widgets/chattab.cpp4
-rw-r--r--src/gui/widgets/dropdown.cpp9
-rw-r--r--src/gui/widgets/dropdown.h4
-rw-r--r--src/gui/widgets/flowcontainer.cpp2
-rw-r--r--src/gui/widgets/itemcontainer.cpp82
-rw-r--r--src/gui/widgets/itemcontainer.h4
-rw-r--r--src/gui/widgets/layout.cpp10
-rw-r--r--src/gui/widgets/mouseevent.h10
-rw-r--r--src/gui/widgets/popup.cpp32
-rw-r--r--src/gui/widgets/popup.h3
-rw-r--r--src/gui/widgets/progressbar.cpp4
-rw-r--r--src/gui/widgets/progressbar.h4
-rw-r--r--src/gui/widgets/radiobutton.cpp10
-rw-r--r--src/gui/widgets/setuptabscroll.cpp18
-rw-r--r--src/gui/widgets/tabbedarea.cpp13
-rw-r--r--src/gui/widgets/tabbedarea.h2
-rw-r--r--src/gui/widgets/textfield.cpp23
-rw-r--r--src/gui/widgets/textfield.h5
-rw-r--r--src/gui/widgets/vertcontainer.cpp5
-rw-r--r--src/gui/widgets/window.cpp116
-rw-r--r--src/gui/widgets/window.h2
24 files changed, 276 insertions, 115 deletions
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index d4764cba5..18dc48417 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -330,7 +330,7 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event)
Being* being = actorSpriteManager->findBeingByName(ava->getName(),
Being::PLAYER);
if (being)
- actorSpriteManager->heal(player_node, being);
+ actorSpriteManager->heal(being);
}
else
{
@@ -373,7 +373,7 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event)
default:
{
Map *map = viewport->getMap();
- Avatar *ava = model->getAvatarAt(selected);
+ ava = model->getAvatarAt(selected);
if (map && ava)
{
MapItem *mapItem = map->findPortalXY(
@@ -384,7 +384,6 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event)
}
}
}
-
else if (event.getButton() == gcn::MouseEvent::MIDDLE)
{
if (ava->getType() == AVATAR_PLAYER && chatWindow)
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index 65a25363d..1419e213c 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -210,23 +210,23 @@ void BrowserBox::addRow(const std::string &row, bool atTop)
for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); ++i)
{
- std::string row = *i;
- for (unsigned int j = 0; j < row.size(); j++)
+ std::string tempRow = *i;
+ for (unsigned int j = 0; j < tempRow.size(); j++)
{
- std::string character = row.substr(j, 1);
+ std::string character = tempRow.substr(j, 1);
x += font->getWidth(character);
nextChar = j + 1;
// Wraping between words (at blank spaces)
- if ((nextChar < row.size()) && (row.at(nextChar) == ' '))
+ if (nextChar < tempRow.size() && tempRow.at(nextChar) == ' ')
{
int nextSpacePos = static_cast<int>(
- row.find(" ", (nextChar + 1)));
+ tempRow.find(" ", (nextChar + 1)));
if (nextSpacePos <= 0)
- nextSpacePos = static_cast<int>(row.size()) - 1;
+ nextSpacePos = static_cast<int>(tempRow.size()) - 1;
unsigned nextWordWidth = font->getWidth(
- row.substr(nextChar,
+ tempRow.substr(nextChar,
(nextSpacePos - nextChar)));
if ((x + nextWordWidth + 10) > (unsigned)getWidth())
@@ -256,6 +256,11 @@ void BrowserBox::addRow(const std::string &row, bool atTop)
updateHeight();
}
+void BrowserBox::addRow(const std::string &cmd, char *text)
+{
+ addRow(strprintf("@@%s|%s@@", cmd.c_str(), text));
+}
+
void BrowserBox::addImage(const std::string &path)
{
if (!mEnableImages)
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
index cd69ce56f..e86f0288e 100644
--- a/src/gui/widgets/browserbox.h
+++ b/src/gui/widgets/browserbox.h
@@ -112,6 +112,11 @@ class BrowserBox : public gcn::Widget,
*/
void addRow(const std::string &row, bool atTop = false);
+ /**
+ * Adds a menu line to the browser.
+ */
+ void addRow(const std::string &cmd, char *text);
+
void addImage(const std::string &path);
/**
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index 81c0d277f..485e96e74 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -337,7 +337,7 @@ void ChatTab::chatInput(const std::string &message)
start = msg.find('[', start + 1);
}
- std::string temp = "";
+ std::string temp("");
if (start + 1 < msg.length() && end < msg.length()
&& end > start + 1)
{
@@ -439,7 +439,7 @@ void ChatTab::loadFromLogFile(std::string name)
{
std::list<std::string> list;
chatLogger->loadLast(name, list, 5);
- std::list<std::string>::iterator i = list.begin();
+ std::list<std::string>::const_iterator i = list.begin();
while (i != list.end())
{
std::string line = "##9" + *i;
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index f01d3fb55..687d7dc6d 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -46,7 +46,8 @@ Image *DropDown::buttons[2][2];
ImageRect DropDown::skin;
float DropDown::mAlpha = 1.0;
-DropDown::DropDown(gcn::ListModel *listModel):
+DropDown::DropDown(gcn::ListModel *listModel, gcn::ActionListener* listener,
+ std::string eventId):
gcn::DropDown::DropDown(listModel,
new ScrollArea,
new ListBox(listModel))
@@ -105,6 +106,12 @@ DropDown::DropDown(gcn::ListModel *listModel):
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);
}
DropDown::~DropDown()
diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h
index 6a22ba497..4cbd23314 100644
--- a/src/gui/widgets/dropdown.h
+++ b/src/gui/widgets/dropdown.h
@@ -46,7 +46,9 @@ class DropDown : public gcn::DropDown
* @param listBox the listBox to use.
* @see ListModel, ScrollArea, ListBox.
*/
- DropDown(gcn::ListModel *listModel = 0);
+ DropDown(gcn::ListModel *listModel = 0,
+ gcn::ActionListener* listener = NULL,
+ std::string eventId = "");
~DropDown();
diff --git a/src/gui/widgets/flowcontainer.cpp b/src/gui/widgets/flowcontainer.cpp
index 33e3790a0..0a64a7142 100644
--- a/src/gui/widgets/flowcontainer.cpp
+++ b/src/gui/widgets/flowcontainer.cpp
@@ -67,7 +67,7 @@ void FlowContainer::widgetResized(const gcn::Event &event A_UNUSED)
int i = 0;
height = 0;
- for (WidgetList::iterator it = mWidgets.begin();
+ for (WidgetList::const_iterator it = mWidgets.begin();
it != mWidgets.end(); ++it)
{
int x = i % mGridWidth * mBoxWidth;
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 91b674018..2cc80ee8b 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -96,6 +96,63 @@ class SortItemIdFunctor
}
} itemIdSorter;
+class SortItemWeightFunctor
+{
+ public:
+ bool operator() (ItemIdPair* pair1, ItemIdPair* pair2)
+ {
+ if (!pair1 || !pair2)
+ return false;
+
+ const int w1 = pair1->mItem->getInfo().getWeight();
+ const int w2 = pair2->mItem->getInfo().getWeight();
+ if (w1 == w2)
+ {
+ return (pair1->mItem->getInfo().getName()
+ < pair2->mItem->getInfo().getName());
+ }
+ return w1 < w2;
+ }
+} itemWeightSorter;
+
+class SortItemAmountFunctor
+{
+ public:
+ bool operator() (ItemIdPair* pair1, ItemIdPair* pair2)
+ {
+ if (!pair1 || !pair2)
+ return false;
+
+ const int c1 = pair1->mItem->getQuantity();
+ const int c2 = pair2->mItem->getQuantity();
+ if (c1 == c2)
+ {
+ return (pair1->mItem->getInfo().getName()
+ < pair2->mItem->getInfo().getName());
+ }
+ return c1 < c2;
+ }
+} itemAmountSorter;
+
+class SortItemTypeFunctor
+{
+ public:
+ bool operator() (ItemIdPair* pair1, ItemIdPair* pair2)
+ {
+ if (!pair1 || !pair2)
+ return false;
+
+ const int t1 = pair1->mItem->getInfo().getType();
+ const int t2 = pair2->mItem->getInfo().getType();
+ if (t1 == t2)
+ {
+ return (pair1->mItem->getInfo().getName()
+ < pair2->mItem->getInfo().getName());
+ }
+ return t1 < t2;
+ }
+} itemTypeSorter;
+
ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity):
mInventory(inventory),
mGridColumns(1),
@@ -456,6 +513,9 @@ void ItemContainer::updateMatrix()
int i = 0;
int j = 0;
+ std::string temp = mName;
+ toLower(temp);
+
for (unsigned idx = 0; idx < mInventory->getSize(); idx ++)
{
Item *item = mInventory->getItem(idx);
@@ -463,7 +523,15 @@ void ItemContainer::updateMatrix()
if (!item || item->getId() == 0 || !item->isHaveTag(mTag))
continue;
- sortedItems.push_back(new ItemIdPair(idx, item));
+ if (mName.empty())
+ {
+ sortedItems.push_back(new ItemIdPair(idx, item));
+ continue;
+ }
+ std::string name = item->getInfo().getName();
+ toLower(name);
+ if (name.find(temp) != std::string::npos)
+ sortedItems.push_back(new ItemIdPair(idx, item));
}
switch (mSortType)
@@ -477,9 +545,18 @@ void ItemContainer::updateMatrix()
case 2:
sort(sortedItems.begin(), sortedItems.end(), itemIdSorter);
break;
+ case 3:
+ sort(sortedItems.begin(), sortedItems.end(), itemWeightSorter);
+ break;
+ case 4:
+ sort(sortedItems.begin(), sortedItems.end(), itemAmountSorter);
+ break;
+ case 5:
+ sort(sortedItems.begin(), sortedItems.end(), itemTypeSorter);
+ break;
}
- std::vector<ItemIdPair*>::iterator iter;
+ std::vector<ItemIdPair*>::const_iterator iter;
for (iter = sortedItems.begin(); iter != sortedItems.end(); ++iter)
{
if (j >= mGridRows)
@@ -608,6 +685,5 @@ void ItemContainer::setFilter (int tag)
void ItemContainer::setSortType (int sortType)
{
mSortType = sortType;
- logger->log("setSortType: %d", sortType);
updateMatrix();
}
diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h
index df7de63ee..845bfb3a9 100644
--- a/src/gui/widgets/itemcontainer.h
+++ b/src/gui/widgets/itemcontainer.h
@@ -125,6 +125,9 @@ class ItemContainer : public gcn::Widget,
void setSortType (int sortType);
+ void setName(std::string str)
+ { mName = str; }
+
void updateMatrix();
private:
@@ -194,6 +197,7 @@ class ItemContainer : public gcn::Widget,
int mDragPosX, mDragPosY;
int mTag;
int mSortType;
+ std::string mName;
ItemPopup *mItemPopup;
int *mShowMatrix;
diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp
index a14b416ce..52b92d0bc 100644
--- a/src/gui/widgets/layout.cpp
+++ b/src/gui/widgets/layout.cpp
@@ -86,12 +86,12 @@ void LayoutCell::computeSizes()
if (mType != ARRAY)
return;
- std::vector< std::vector< LayoutCell * > >::iterator
+ std::vector <std::vector <LayoutCell *> >::const_iterator
i = mArray->mCells.begin();
while (i != mArray->mCells.end())
{
- std::vector< LayoutCell * >::iterator j = i->begin();
+ std::vector <LayoutCell *>::const_iterator j = i->begin();
while (j != i->end())
{
LayoutCell *cell = *j;
@@ -113,7 +113,8 @@ LayoutArray::LayoutArray(): mSpacing(4)
LayoutArray::~LayoutArray()
{
- std::vector< std::vector< LayoutCell * > >::iterator i = mCells.begin();
+ std::vector <std::vector <LayoutCell *> >::iterator
+ i = mCells.begin();
while (i != mCells.end())
{
std::vector< LayoutCell * >::iterator j = i->begin();
@@ -154,7 +155,8 @@ void LayoutArray::resizeGrid(int w, int h)
if (extW)
mSizes[0].resize(w, Layout::AUTO_DEF);
- std::vector< std::vector< LayoutCell * > >::iterator i = mCells.begin();
+ std::vector <std::vector <LayoutCell *> >::iterator
+ i = mCells.begin();
while (i != mCells.end())
{
i->resize(w, 0);
diff --git a/src/gui/widgets/mouseevent.h b/src/gui/widgets/mouseevent.h
index 5e9a46cfd..9484be0a5 100644
--- a/src/gui/widgets/mouseevent.h
+++ b/src/gui/widgets/mouseevent.h
@@ -28,12 +28,12 @@
class MouseEvent : public gcn::MouseEvent
{
public:
- MouseEvent(gcn::Widget* source, bool isShiftPressed,
- bool isControlPressed, bool isAltPressed,
- bool isMetaPressed, unsigned int type, unsigned int button,
+ MouseEvent(gcn::Widget* source, bool shiftPressed,
+ bool controlPressed, bool altPressed,
+ bool metaPressed, unsigned int type, unsigned int button,
int x, int y, int clickCount) :
- gcn::MouseEvent(source, isShiftPressed, isControlPressed,
- isAltPressed, isMetaPressed, type, button, x, y,
+ gcn::MouseEvent(source, shiftPressed, controlPressed,
+ altPressed, metaPressed, type, button, x, y,
clickCount)
{
}
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
index 38088770b..ac282b088 100644
--- a/src/gui/widgets/popup.cpp
+++ b/src/gui/widgets/popup.cpp
@@ -40,12 +40,12 @@
#include "debug.h"
-Popup::Popup(const std::string &name, const std::string &skin):
+Popup::Popup(const std::string &name, std::string skin):
mPopupName(name),
mMinWidth(100),
mMinHeight(40),
- mMaxWidth(graphics->mWidth),
- mMaxHeight(graphics->mHeight),
+ mMaxWidth(mainGraphics->mWidth),
+ mMaxHeight(mainGraphics->mHeight),
mVertexes(new GraphicsVertexes()),
mRedraw(true)
{
@@ -58,8 +58,20 @@ Popup::Popup(const std::string &name, const std::string &skin):
setPadding(3);
+ if (skin == "")
+ skin = "popup.xml";
+
// Loads the skin
- mSkin = Theme::instance()->load(skin);
+ if (Theme::instance())
+ {
+ mSkin = Theme::instance()->load(skin);
+ if (mSkin)
+ setPadding(mSkin->getPadding());
+ }
+ else
+ {
+ mSkin = 0;
+ }
// Add this window to the window container
windowContainer->add(this);
@@ -76,7 +88,11 @@ Popup::~Popup()
mVertexes = 0;
if (mSkin)
- mSkin->instances--;
+ {
+ if (Theme::instance())
+ Theme::instance()->unload(mSkin);
+ mSkin = 0;
+ }
}
void Popup::setWindowContainer(WindowContainer *wc)
@@ -190,9 +206,9 @@ void Popup::position(int x, int y)
int posX = std::max(0, x - getWidth() / 2);
int posY = y + distance;
- if (posX + getWidth() > graphics->mWidth)
- posX = graphics->mWidth - getWidth();
- if (posY + getHeight() > graphics->mHeight)
+ if (posX + getWidth() > mainGraphics->mWidth)
+ posX = mainGraphics->mWidth - getWidth();
+ if (posY + getHeight() > mainGraphics->mHeight)
posY = y - getHeight() - distance;
setPosition(posX, posY);
diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h
index 0ac50f69e..9d4343ba3 100644
--- a/src/gui/widgets/popup.h
+++ b/src/gui/widgets/popup.h
@@ -66,8 +66,7 @@ class Popup : public Container, public gcn::MouseListener,
* debugging purposes.
* @param skin The location where the Popup's skin XML can be found.
*/
- Popup(const std::string &name = "",
- const std::string &skin = "window.xml");
+ Popup(const std::string &name = "", std::string skin = "");
/**
* Destructor. Deletes all the added widgets.
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
index c1d6a9531..7324fc9ad 100644
--- a/src/gui/widgets/progressbar.cpp
+++ b/src/gui/widgets/progressbar.cpp
@@ -70,7 +70,9 @@ ProgressBar::ProgressBar(float progress,
if (mInstances == 0)
{
- Image *dBorders = Theme::getImageFromTheme("vscroll_grey.png");
+ 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);
diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h
index 52a26ddac..36ed96bd2 100644
--- a/src/gui/widgets/progressbar.h
+++ b/src/gui/widgets/progressbar.h
@@ -94,8 +94,8 @@ class ProgressBar : public gcn::Widget, public gcn::WidgetListener
/**
* Sets the text shown on the progress bar.
*/
- void setText(const std::string &text)
- { mText = text; }
+ void setText(const std::string &str)
+ { mText = str; }
/**
* Returns the text shown on the progress bar.
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
index e641be323..feedeae7b 100644
--- a/src/gui/widgets/radiobutton.cpp
+++ b/src/gui/widgets/radiobutton.cpp
@@ -136,23 +136,16 @@ void RadioButton::drawBox(gcn::Graphics* graphics)
}
if (box)
- static_cast<Graphics*>(graphics)->drawImage(box, 2, 2);
+ static_cast<Graphics*>(graphics)->drawImage(box, 3, 3);
}
void RadioButton::draw(gcn::Graphics* graphics)
{
- graphics->pushClipArea(gcn::Rectangle(1, 1, getWidth() - 1,
- getHeight() - 1));
-
drawBox(graphics);
- graphics->popClipArea();
-
graphics->setFont(getFont());
graphics->setColor(getForegroundColor());
-// int h = getHeight() + getHeight() / 2;
-// graphics->drawText(getCaption(), h - 2, 0);
graphics->drawText(getCaption(), 16, 0);
}
@@ -165,4 +158,3 @@ void RadioButton::mouseExited(gcn::MouseEvent& event A_UNUSED)
{
mHasMouse = false;
}
-
diff --git a/src/gui/widgets/setuptabscroll.cpp b/src/gui/widgets/setuptabscroll.cpp
index 30bb66469..e9917b090 100644
--- a/src/gui/widgets/setuptabscroll.cpp
+++ b/src/gui/widgets/setuptabscroll.cpp
@@ -90,25 +90,31 @@ void SetupTabScroll::addControl(SetupItem *widget, std::string event)
void SetupTabScroll::apply()
{
- std::map<std::string, SetupItem*>::iterator iter;
+ std::map<std::string, SetupItem*>::const_iterator iter;
for (iter = mItems.begin(); iter != mItems.end(); ++ iter)
- (*iter).second->apply((*iter).first);
+ {
+ if ((*iter).second)
+ (*iter).second->apply((*iter).first);
+ }
}
void SetupTabScroll::cancel()
{
- std::map<std::string, SetupItem*>::iterator iter;
+ std::map<std::string, SetupItem*>::const_iterator iter;
for (iter = mItems.begin(); iter != mItems.end(); ++ iter)
- (*iter).second->cancel((*iter).first);
+ {
+ if ((*iter).second)
+ (*iter).second->cancel((*iter).first);
+ }
}
void SetupTabScroll::externalUpdated()
{
- std::map<std::string, SetupItem*>::iterator iter;
+ std::map<std::string, SetupItem*>::const_iterator iter;
for (iter = mItems.begin(); iter != mItems.end(); ++ iter)
{
SetupItem *widget = (*iter).second;
- if (!widget->isMainConfig())
+ if (widget && !widget->isMainConfig())
(*iter).second->externalUpdated((*iter).first);
}
}
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index 940dad12a..47b02c925 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -241,6 +241,19 @@ void TabbedArea::setSelectedTab(gcn::Tab *tab)
widgetResized(NULL);
}
+void TabbedArea::setSelectedTab(const std::string &name)
+{
+ for (TabContainer::const_iterator itr = mTabs.begin(),
+ itr_end = mTabs.end(); itr != itr_end; ++itr)
+ {
+ if ((*itr).first && (*itr).first->getCaption() == name)
+ {
+ setSelectedTab((*itr).first);
+ return;
+ }
+ }
+}
+
void TabbedArea::widgetResized(const gcn::Event &event A_UNUSED)
{
int width = getWidth() - 2 * getFrameSize()
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index a91b4c199..3ad113b4c 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -122,6 +122,8 @@ class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener
void setSelectedTab(gcn::Tab *tab);
+ void setSelectedTab(const std::string &name);
+
void widgetResized(const gcn::Event &event);
/*
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index 2729e5407..5d4fbc0b4 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -48,12 +48,14 @@ float TextField::mAlpha = 1.0;
ImageRect TextField::skin;
TextField::TextField(const std::string &text, bool loseFocusOnTab,
- gcn::ActionListener* listener, std::string eventId):
+ gcn::ActionListener* listener, std::string eventId,
+ bool sendAlwaysEvents):
gcn::TextField(text),
mNumeric(false),
mMinimum(0),
mMaximum(0),
- mLastEventPaste(false)
+ mLastEventPaste(false),
+ mSendAlwaysEvents(sendAlwaysEvents)
{
setFrameSize(2);
@@ -276,7 +278,9 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
case Key::ENTER:
distributeActionEvent();
- break;
+ keyEvent.consume();
+ fixScroll();
+ return;
case Key::HOME:
mCaretPosition = 0;
@@ -309,6 +313,10 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
}
break;
+ case 3:
+ handleCopy();
+ break;
+
case 22: // Control code 22, SYNCHRONOUS IDLE, sent on Ctrl+v
// hack to prevent paste key sticking
if (mLastEventPaste && mLastEventPaste > cur_time)
@@ -333,6 +341,9 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
break;
}
+ if (mSendAlwaysEvents)
+ distributeActionEvent();
+
keyEvent.consume();
fixScroll();
}
@@ -348,3 +359,9 @@ void TextField::handlePaste()
setCaretPosition(static_cast<unsigned>(caretPos));
}
}
+
+void TextField::handleCopy()
+{
+ std::string text = getText();
+ sendBuffer(text);
+}
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
index 79197bb7a..7e19099e8 100644
--- a/src/gui/widgets/textfield.h
+++ b/src/gui/widgets/textfield.h
@@ -41,7 +41,7 @@ class TextField : public gcn::TextField
*/
TextField(const std::string &text = "", bool loseFocusOnTab = true,
gcn::ActionListener* listener = NULL,
- std::string eventId = "");
+ std::string eventId = "", bool sendAlwaysEvents = false);
~TextField();
@@ -99,6 +99,8 @@ class TextField : public gcn::TextField
private:
void handlePaste();
+ void handleCopy();
+
static int instances;
static float mAlpha;
static ImageRect skin;
@@ -107,6 +109,7 @@ class TextField : public gcn::TextField
int mMaximum;
bool mLoseFocusOnTab;
int mLastEventPaste;
+ bool mSendAlwaysEvents;
};
#endif
diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp
index ea6b4d520..5e79b7c19 100644
--- a/src/gui/widgets/vertcontainer.cpp
+++ b/src/gui/widgets/vertcontainer.cpp
@@ -73,8 +73,9 @@ void VertContainer::clear()
void VertContainer::widgetResized(const gcn::Event &event A_UNUSED)
{
- for (std::vector<gcn::Widget*>::iterator it = mResizableWidgets.begin();
- it != mResizableWidgets.end(); ++ it)
+ for (std::vector<gcn::Widget*>::const_iterator
+ it = mResizableWidgets.begin();
+ it != mResizableWidgets.end(); ++ it)
{
(*it)->setWidth(getWidth());
}
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 4435496a7..c52bf744e 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -47,7 +47,7 @@ int Window::instances = 0;
int Window::mouseResize = 0;
Window::Window(const std::string &caption, bool modal, Window *parent,
- const std::string &skin):
+ std::string skin):
gcn::Window(caption),
mGrip(0),
mParent(parent),
@@ -63,8 +63,8 @@ Window::Window(const std::string &caption, bool modal, Window *parent,
mStickyButtonLock(false),
mMinWinWidth(100),
mMinWinHeight(40),
- mMaxWinWidth(graphics->mWidth),
- mMaxWinHeight(graphics->mHeight),
+ mMaxWinWidth(mainGraphics->mWidth),
+ mMaxWinHeight(mainGraphics->mHeight),
mVertexes(new GraphicsVertexes()),
mRedraw(true)
{
@@ -79,8 +79,20 @@ Window::Window(const std::string &caption, bool modal, Window *parent,
setPadding(3);
setTitleBarHeight(20);
+ if (skin == "")
+ skin = "window.xml";
+
// Loads the skin
- mSkin = Theme::instance()->load(skin);
+ if (Theme::instance())
+ {
+ mSkin = Theme::instance()->load(skin);
+ if (mSkin)
+ setPadding(mSkin->getPadding());
+ }
+ else
+ {
+ mSkin = 0;
+ }
// Add this window to the window container
windowContainer->add(this);
@@ -113,8 +125,6 @@ Window::~Window()
mWidgets.clear();
-// need mWidgets.clean ?
-
removeWidgetListener(this);
delete mVertexes;
mVertexes = 0;
@@ -122,7 +132,11 @@ Window::~Window()
instances--;
if (mSkin)
- mSkin->instances--;
+ {
+ if (Theme::instance())
+ Theme::instance()->unload(mSkin);
+ mSkin = 0;
+ }
}
void Window::setWindowContainer(WindowContainer *wc)
@@ -244,39 +258,39 @@ void Window::setLocationRelativeTo(ImageRect::ImagePosition position,
}
else if (position == ImageRect::UPPER_CENTER)
{
- offsetX += (graphics->mWidth - getWidth()) / 2;
+ offsetX += (mainGraphics->mWidth - getWidth()) / 2;
}
else if (position == ImageRect::UPPER_RIGHT)
{
- offsetX += graphics->mWidth - getWidth();
+ offsetX += mainGraphics->mWidth - getWidth();
}
else if (position == ImageRect::LEFT)
{
- offsetY += (graphics->mHeight - getHeight()) / 2;
+ offsetY += (mainGraphics->mHeight - getHeight()) / 2;
}
else if (position == ImageRect::CENTER)
{
- offsetX += (graphics->mWidth - getWidth()) / 2;
- offsetY += (graphics->mHeight - getHeight()) / 2;
+ offsetX += (mainGraphics->mWidth - getWidth()) / 2;
+ offsetY += (mainGraphics->mHeight - getHeight()) / 2;
}
else if (position == ImageRect::RIGHT)
{
- offsetX += graphics->mWidth - getWidth();
- offsetY += (graphics->mHeight - getHeight()) / 2;
+ offsetX += mainGraphics->mWidth - getWidth();
+ offsetY += (mainGraphics->mHeight - getHeight()) / 2;
}
else if (position == ImageRect::LOWER_LEFT)
{
- offsetY += graphics->mHeight - getHeight();
+ offsetY += mainGraphics->mHeight - getHeight();
}
else if (position == ImageRect::LOWER_CENTER)
{
- offsetX += (graphics->mWidth - getWidth()) / 2;
- offsetY += graphics->mHeight - getHeight();
+ offsetX += (mainGraphics->mWidth - getWidth()) / 2;
+ offsetY += mainGraphics->mHeight - getHeight();
}
else if (position == ImageRect::LOWER_RIGHT)
{
- offsetX += graphics->mWidth - getWidth();
- offsetY += graphics->mHeight - getHeight();
+ offsetX += mainGraphics->mWidth - getWidth();
+ offsetY += mainGraphics->mHeight - getHeight();
}
setPosition(offsetX, offsetY);
@@ -373,7 +387,7 @@ void Window::widgetHidden(const gcn::Event &event A_UNUSED)
if (!mFocusHandler)
return;
- for (it = mWidgets.begin(); it != mWidgets.end(); it++)
+ for (it = mWidgets.begin(); it != mWidgets.end(); ++ it)
{
if (mFocusHandler->isFocused(*it))
mFocusHandler->focusNone();
@@ -443,7 +457,7 @@ void Window::mousePressed(gcn::MouseEvent &event)
const int y = event.getY();
// Handle close button
- if (mCloseButton)
+ if (mCloseButton && mSkin)
{
Image *img = mSkin->getCloseImage();
if (img)
@@ -464,7 +478,7 @@ void Window::mousePressed(gcn::MouseEvent &event)
}
// Handle sticky button
- if (mStickyButton)
+ if (mStickyButton && mSkin)
{
Image *button = mSkin->getStickyImage(mSticky);
if (button)
@@ -579,8 +593,8 @@ void Window::mouseDragged(gcn::MouseEvent &event)
{
int newX = std::max(0, getX());
int newY = std::max(0, getY());
- newX = std::min(graphics->mWidth - getWidth(), newX);
- newY = std::min(graphics->mHeight - getHeight(), newY);
+ newX = std::min(mainGraphics->mWidth - getWidth(), newX);
+ newY = std::min(mainGraphics->mHeight - getHeight(), newY);
setPosition(newX, newY);
}
@@ -621,14 +635,10 @@ void Window::mouseDragged(gcn::MouseEvent &event)
newDim.height += newDim.y;
newDim.y = 0;
}
- if (newDim.x + newDim.width > graphics->mWidth)
- {
- newDim.width = graphics->mWidth - newDim.x;
- }
- if (newDim.y + newDim.height > graphics->mHeight)
- {
- newDim.height = graphics->mHeight - newDim.y;
- }
+ if (newDim.x + newDim.width > mainGraphics->mWidth)
+ newDim.width = mainGraphics->mWidth - newDim.x;
+ if (newDim.y + newDim.height > mainGraphics->mHeight)
+ newDim.height = mainGraphics->mHeight - newDim.y;
// Update mouse offset when dragging bottom or right border
if (mouseResize & BOTTOM)
@@ -790,39 +800,39 @@ void Window::setDefaultSize(int defaultWidth, int defaultHeight,
}
else if (position == ImageRect::UPPER_CENTER)
{
- x = (graphics->mWidth - defaultWidth) / 2;
+ x = (mainGraphics->mWidth - defaultWidth) / 2;
}
else if (position == ImageRect::UPPER_RIGHT)
{
- x = graphics->mWidth - defaultWidth;
+ x = mainGraphics->mWidth - defaultWidth;
}
else if (position == ImageRect::LEFT)
{
- y = (graphics->mHeight - defaultHeight) / 2;
+ y = (mainGraphics->mHeight - defaultHeight) / 2;
}
else if (position == ImageRect::CENTER)
{
- x = (graphics->mWidth - defaultWidth) / 2;
- y = (graphics->mHeight - defaultHeight) / 2;
+ x = (mainGraphics->mWidth - defaultWidth) / 2;
+ y = (mainGraphics->mHeight - defaultHeight) / 2;
}
else if (position == ImageRect::RIGHT)
{
- x = graphics->mWidth - defaultWidth;
- y = (graphics->mHeight - defaultHeight) / 2;
+ x = mainGraphics->mWidth - defaultWidth;
+ y = (mainGraphics->mHeight - defaultHeight) / 2;
}
else if (position == ImageRect::LOWER_LEFT)
{
- y = graphics->mHeight - defaultHeight;
+ y = mainGraphics->mHeight - defaultHeight;
}
else if (position == ImageRect::LOWER_CENTER)
{
- x = (graphics->mWidth - defaultWidth) / 2;
- y = graphics->mHeight - defaultHeight;
+ x = (mainGraphics->mWidth - defaultWidth) / 2;
+ y = mainGraphics->mHeight - defaultHeight;
}
else if (position == ImageRect::LOWER_RIGHT)
{
- x = graphics->mWidth - defaultWidth;
- y = graphics->mHeight - defaultHeight;
+ x = mainGraphics->mWidth - defaultWidth;
+ y = mainGraphics->mHeight - defaultHeight;
}
mDefaultX = x - offsetX;
@@ -994,11 +1004,11 @@ void Window::checkIfIsOffScreen(bool partially, bool entirely)
// Look if the window is partially off-screen limits...
if (partially)
{
- if (winDimension.x + winDimension.width > graphics->mWidth)
- winDimension.x = graphics->mWidth - winDimension.width;
+ if (winDimension.x + winDimension.width > mainGraphics->mWidth)
+ winDimension.x = mainGraphics->mWidth - winDimension.width;
- if (winDimension.y + winDimension.height > graphics->mHeight)
- winDimension.y = graphics->mHeight - winDimension.height;
+ if (winDimension.y + winDimension.height > mainGraphics->mHeight)
+ winDimension.y = mainGraphics->mHeight - winDimension.height;
setDimension(winDimension);
return;
@@ -1006,11 +1016,11 @@ void Window::checkIfIsOffScreen(bool partially, bool entirely)
if (entirely)
{
- if (winDimension.x > graphics->mWidth)
- winDimension.x = graphics->mWidth - winDimension.width;
+ if (winDimension.x > mainGraphics->mWidth)
+ winDimension.x = mainGraphics->mWidth - winDimension.width;
- if (winDimension.y > graphics->mHeight)
- winDimension.y = graphics->mHeight - winDimension.height;
+ if (winDimension.y > mainGraphics->mHeight)
+ winDimension.y = mainGraphics->mHeight - winDimension.height;
}
setDimension(winDimension);
}
@@ -1021,4 +1031,4 @@ gcn::Rectangle Window::getWindowArea()
getPadding(),
getWidth() - getPadding() * 2,
getHeight() - getPadding() * 2);
-} \ No newline at end of file
+}
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index b9f65dceb..510a68323 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -65,7 +65,7 @@ class Window : public gcn::Window, gcn::WidgetListener
* @param skin The location where the window's skin XML can be found.
*/
Window(const std::string &caption = "Window", bool modal = false,
- Window *parent = NULL, const std::string &skin = "window.xml");
+ Window *parent = NULL, std::string skin = "");
/**
* Destructor. Deletes all the added widgets.