summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-20 12:50:26 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-20 12:50:26 +0000
commit90e5ce7e958418f0d39d38112d33d3190a78baea (patch)
tree012150b22e971e44d0f7e795ef48384e15392940 /src/gui
parent9ca202ae89bbe60f2cd1c8e3249a4fe3f8972a2b (diff)
downloadmana-90e5ce7e958418f0d39d38112d33d3190a78baea.tar.gz
mana-90e5ce7e958418f0d39d38112d33d3190a78baea.tar.bz2
mana-90e5ce7e958418f0d39d38112d33d3190a78baea.tar.xz
mana-90e5ce7e958418f0d39d38112d33d3190a78baea.zip
TMW now uses latest Guichan CVS, and doesn't work with Guichan 0.2.0 anymore!
Also fixed a crash on clicking wallpaper in login phase.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/buy.cpp2
-rw-r--r--src/gui/buysell.cpp2
-rw-r--r--src/gui/char_select.cpp4
-rw-r--r--src/gui/char_server.cpp2
-rw-r--r--src/gui/chargedialog.cpp6
-rw-r--r--src/gui/chat.cpp2
-rw-r--r--src/gui/confirm_dialog.cpp2
-rw-r--r--src/gui/equipment.cpp2
-rw-r--r--src/gui/gui.cpp101
-rw-r--r--src/gui/gui.h19
-rw-r--r--src/gui/inventory.cpp2
-rw-r--r--src/gui/item_amount.cpp4
-rw-r--r--src/gui/login.cpp2
-rw-r--r--src/gui/minimap.cpp2
-rw-r--r--src/gui/newskill.cpp2
-rw-r--r--src/gui/npc.cpp2
-rw-r--r--src/gui/npc_text.cpp2
-rw-r--r--src/gui/ok_dialog.cpp2
-rw-r--r--src/gui/sell.cpp2
-rw-r--r--src/gui/setup.cpp2
-rw-r--r--src/gui/skill.cpp2
-rw-r--r--src/gui/slider.cpp4
-rw-r--r--src/gui/stats.cpp2
-rw-r--r--src/gui/status.cpp4
-rw-r--r--src/gui/window.cpp125
-rw-r--r--src/gui/window.h39
-rw-r--r--src/gui/windowcontainer.cpp4
-rw-r--r--src/gui/windowcontainer.h2
28 files changed, 84 insertions, 262 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index de2593d1..e75bdbb1 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -43,7 +43,7 @@ BuyDialog::BuyDialog():
okButton = new Button("OK");
cancelButton = new Button("Cancel");
- setSize(260, 175);
+ setContentSize(260, 175);
scrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110));
itemList->setDimension(gcn::Rectangle(5, 5, 240, 110));
slider->setDimension(gcn::Rectangle(5, 120, 200, 10));
diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp
index cc9cbcc6..c81744dc 100644
--- a/src/gui/buysell.cpp
+++ b/src/gui/buysell.cpp
@@ -38,7 +38,7 @@ BuySellDialog::BuySellDialog():
buyButton->getX() + buyButton->getWidth() + 10, 10);
cancelButton->setPosition(
sellButton->getX() + sellButton->getWidth() + 10, 10);
- setSize(cancelButton->getX() + cancelButton->getWidth() + 10,
+ setContentSize(cancelButton->getX() + cancelButton->getWidth() + 10,
cancelButton->getY() + cancelButton->getHeight() + 10);
buyButton->setEventId("buy");
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 6b10d5a9..e9e8609b 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -67,7 +67,7 @@ CharSelectDialog::CharSelectDialog():
int w = 195;
int h = 195;
- setSize(w, h);
+ setContentSize(w, h);
playerBox->setDimension(gcn::Rectangle(5, 5, w - 10, 90));
nameLabel->setDimension(gcn::Rectangle(10, 100, 128, 16));
levelLabel->setDimension(gcn::Rectangle(10, 116, 128, 16));
@@ -268,7 +268,7 @@ CharCreateDialog::CharCreateDialog(Window *parent):
int w = 200;
int h = 150;
- setSize(w, h);
+ setContentSize(w, h);
playerBox->setDimension(gcn::Rectangle(80, 30, 110, 85));
nameLabel->setPosition(5, 5);
nameField->setDimension(
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index ec7eaefa..cb085053 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -42,7 +42,7 @@ ServerSelectDialog::ServerSelectDialog():
okButton = new Button("OK");
cancelButton = new Button("Cancel");
- setSize(200, 100);
+ setContentSize(200, 100);
cancelButton->setPosition(
200 - cancelButton->getWidth() - 5,
diff --git a/src/gui/chargedialog.cpp b/src/gui/chargedialog.cpp
index 71b0edaf..b5ffce44 100644
--- a/src/gui/chargedialog.cpp
+++ b/src/gui/chargedialog.cpp
@@ -33,10 +33,8 @@
ChargeDialog::ChargeDialog():
Window("")
-{
-
-
- setSize(180,70);
+{
+ setContentSize(180,70);
progBar = new ProgressBar(0.0f,20,40,140,25,128,128,128);
add(progBar);
}
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index d642459c..6b8854ca 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -34,7 +34,7 @@ ChatWindow::ChatWindow(const char *logfile, int item_num):
items = 0;
items_keep = item_num;
- setSize(600, 100);
+ setContentSize(600, 100);
chatInput = new TextField();
chatInput->setPosition(
diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp
index 3a92e3f8..84712f26 100644
--- a/src/gui/confirm_dialog.cpp
+++ b/src/gui/confirm_dialog.cpp
@@ -52,7 +52,7 @@ void ConfirmDialog::init(const std::string &msg, gcn::ActionListener *listener)
w = inWidth + 10;
}
- setSize(w, h);
+ setContentSize(w, h);
userLabel->setPosition(10, 10);
yesButton->setPosition(
(w - inWidth) / 2,
diff --git a/src/gui/equipment.cpp b/src/gui/equipment.cpp
index 74f5df6d..450d985b 100644
--- a/src/gui/equipment.cpp
+++ b/src/gui/equipment.cpp
@@ -29,7 +29,7 @@
EquipmentWindow::EquipmentWindow():
Window("Equipment")
{
- setSize(60, 200);
+ setContentSize(60, 200);
setPosition(40, 40);
ResourceManager *resman = ResourceManager::getInstance();
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 5c77f317..1cb7e3f9 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -34,14 +34,15 @@ Graphics *guiGraphics; // Graphics driver
gcn::SDLInput *guiInput; // GUI input
WindowContainer *guiTop; // The top container
-Gui::Gui(Graphics *graphics):
- topHasMouse(false)
+Gui::Gui(Graphics *graphics)
{
// Set graphics
guiGraphics = graphics;
+ setGraphics(graphics);
// Set input
guiInput = new gcn::SDLInput();
+ setInput(guiInput);
// Set image loader
#ifndef USE_OPENGL
@@ -58,10 +59,7 @@ Gui::Gui(Graphics *graphics):
guiTop->setOpaque(false);
guiTop->addMouseListener(this);
Window::setWindowContainer(guiTop);
-
- // Create focus handler
- focusHandler = new gcn::FocusHandler();
- guiTop->_setFocusHandler(focusHandler);
+ setTop(guiTop);
// Set global font
guiFont = new gcn::ImageFont("./data/core/graphics/gui/fixedfont.png",
@@ -80,82 +78,6 @@ Gui::~Gui()
delete hostImageLoader;
#endif
delete guiInput;
- delete focusHandler;
-}
-
-void Gui::logic()
-{
- while (!guiInput->isMouseQueueEmpty())
- {
- gcn::MouseInput mi = guiInput->dequeueMouseInput();
- gcn::Widget* focused = focusHandler->getFocused();
-
- if (mi.x > 0 && mi.y > 0 &&
- guiTop->getDimension().isPointInRect(mi.x, mi.y))
- {
- if (!topHasMouse) {
- guiTop->_mouseInMessage();
- topHasMouse = true;
- }
-
- gcn::MouseInput mio = mi;
- mio.x -= guiTop->getX();
- mio.y -= guiTop->getY();
-
- if (!guiTop->hasFocus()) {
- guiTop->_mouseInputMessage(mio);
- }
- }
- else {
- if (topHasMouse) {
- guiTop->_mouseOutMessage();
- topHasMouse = false;
- }
- }
-
- if (focusHandler->getFocused() && focused == focusHandler->getFocused())
- {
- int xOffset, yOffset;
- focused->getAbsolutePosition(xOffset, yOffset);
-
- gcn::MouseInput mio = mi;
- mio.x -= xOffset;
- mio.y -= yOffset;
- focused->_mouseInputMessage(mio);
- }
- }
-
- while (!guiInput->isKeyQueueEmpty())
- {
- gcn::KeyInput ki = guiInput->dequeueKeyInput();
-
- // Handle tabbing
- if (ki.getKey().getValue() == gcn::Key::TAB &&
- ki.getType() == gcn::KeyInput::PRESS)
- {
- if (ki.getKey().isShiftPressed()) {
- focusHandler->tabPrevious();
- }
- else {
- focusHandler->tabNext();
- }
- }
- else {
- // Send key inputs to the focused widgets
- gcn::Widget* focused = focusHandler->getFocused();
- if (focused)
- {
- if (focused->isFocusable()) {
- focused->_keyInputMessage(ki);
- }
- else {
- focusHandler->focusNone();
- }
- }
- }
- }
-
- guiTop->logic();
}
void Gui::draw()
@@ -165,11 +87,6 @@ void Gui::draw()
guiGraphics->popClipArea();
}
-void Gui::focusNone()
-{
- focusHandler->focusNone();
-}
-
void Gui::mousePress(int mx, int my, int button)
{
// Mouse pressed on window container (basically, the map)
@@ -177,8 +94,10 @@ void Gui::mousePress(int mx, int my, int button)
int tiley = my / 32 + camera_y;
// Experimental mouse walk support
- walk(mx, my, 0);
- player_node->setPath(tiledMap->findPath(
- player_node->x, player_node->y,
- tilex, tiley));
+ if (state == GAME) {
+ walk(mx, my, 0);
+ player_node->setPath(tiledMap->findPath(
+ player_node->x, player_node->y,
+ tilex, tiley));
+ }
}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 3bcffc5d..5051b788 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -38,7 +38,7 @@
*
* \ingroup GUI
*/
-class Gui : public gcn::MouseListener
+class Gui : public gcn::Gui, public gcn::MouseListener
{
public:
/**
@@ -52,21 +52,6 @@ class Gui : public gcn::MouseListener
~Gui();
/**
- * Focus none of the Widgets in the Gui.
- */
- void focusNone();
-
- /**
- * Performs the Gui:s logic by calling all logic functions
- * down in the Gui heirarchy. Logic can be just about anything
- * like adjusting a Widgets size or doing some calculations.
- *
- * NOTE: Logic also deals with user input (Mouse and Keyboard)
- * for Widgets.
- */
- void logic();
-
- /**
* Draws the whole Gui by calling draw functions down in the
* Gui hierarchy. It also draws the mouse pointer.
*/
@@ -86,8 +71,6 @@ class Gui : public gcn::MouseListener
gcn::ImageFont *guiFont; /**< The global GUI font */
bool topHasMouse;
-
- gcn::FocusHandler *focusHandler;
};
extern Gui *gui;
diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp
index 76d81fab..21724927 100644
--- a/src/gui/inventory.cpp
+++ b/src/gui/inventory.cpp
@@ -34,7 +34,7 @@
InventoryWindow::InventoryWindow():
Window("Inventory")
{
- setSize(322, 100);
+ setContentSize(322, 100);
useButton = new Button("Use");
useButton->setPosition(20, 50);
dropButton = new Button("Drop");
diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp
index e627659e..a63d5a8e 100644
--- a/src/gui/item_amount.cpp
+++ b/src/gui/item_amount.cpp
@@ -52,7 +52,7 @@ ItemAmountWindow::ItemAmountWindow():
itemAmountOkButton->setPosition(10, 40);
itemAmountCancelButton->setPosition(60, 40);
- // Assemble
+ // Assemble
add(itemAmountLabel);
add(itemAmountPlusButton);
add(itemAmountMinusButton);
@@ -66,7 +66,7 @@ ItemAmountWindow::ItemAmountWindow():
resetAmount();
- setSize(200, 80);
+ setContentSize(200, 80);
setLocationRelativeTo(getParent());
}
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 6dc2597c..f5e51d8d 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -43,7 +43,7 @@ LoginDialog::LoginDialog():
okButton = new Button("OK");
cancelButton = new Button("Cancel");
- setSize(200, 75);
+ setContentSize(200, 75);
userLabel->setPosition(5, 5);
passLabel->setPosition(5, 14 + userLabel->getHeight());
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index a58ed83c..df9d2f42 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -29,7 +29,7 @@
Minimap::Minimap()
{
- setSize(MINIMAP_W, MINIMAP_H);
+ setContentSize(MINIMAP_W, MINIMAP_H);
setPosition(20, 20);
mapBackground = SDL_AllocSurface(SDL_SWSURFACE, MINIMAP_W, MINIMAP_H,
diff --git a/src/gui/newskill.cpp b/src/gui/newskill.cpp
index a3747705..b826d753 100644
--- a/src/gui/newskill.cpp
+++ b/src/gui/newskill.cpp
@@ -116,7 +116,7 @@ NewSkillDialog::NewSkillDialog():
closeButton->setEventId("close");
// positioning
- setSize(350, 250);
+ setContentSize(350, 250);
catButton[0]->setDimension(gcn::Rectangle(0,0,60,20));
catButton[0]->setPosition(290, 0);
catButton[1]->setDimension(gcn::Rectangle(0,0,60,20));
diff --git a/src/gui/npc.cpp b/src/gui/npc.cpp
index 9b08fd35..1753178b 100644
--- a/src/gui/npc.cpp
+++ b/src/gui/npc.cpp
@@ -36,7 +36,7 @@ NpcListDialog::NpcListDialog():
okButton = new Button("OK");
cancelButton = new Button("Cancel");
- setSize(260, 175);
+ setContentSize(260, 175);
scrollArea->setDimension(gcn::Rectangle(
5, 5, 250, 160 - okButton->getHeight()));
cancelButton->setPosition(
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 1aaebd45..9b94fac6 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -36,7 +36,7 @@ NpcTextDialog::NpcTextDialog():
scrollArea = new ScrollArea(textBox);
okButton = new Button("OK");
- setSize(260, 175);
+ setContentSize(260, 175);
scrollArea->setDimension(gcn::Rectangle(
5, 5, 250, 160 - okButton->getHeight()));
okButton->setPosition(
diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp
index 9164cfa3..e7ff1449 100644
--- a/src/gui/ok_dialog.cpp
+++ b/src/gui/ok_dialog.cpp
@@ -50,7 +50,7 @@ void OkDialog::init(const std::string &msg, gcn::ActionListener *listener)
w = okButton->getWidth() + 10;
}
- setSize(w, h);
+ setContentSize(w, h);
userLabel->setPosition(10, 10);
okButton->setPosition(
(w - okButton->getWidth()) / 2,
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index fe2cd960..4ab41cd2 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -43,7 +43,7 @@ SellDialog::SellDialog():
okButton = new Button("OK");
cancelButton = new Button("Cancel");
- setSize(260, 175);
+ setContentSize(260, 175);
scrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110));
itemList->setDimension(gcn::Rectangle(5, 5, 240, 110));
slider->setDimension(gcn::Rectangle(5, 120, 200, 10));
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index 2f1fc36b..6e3197cd 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -116,7 +116,7 @@ Setup::Setup():
cancelButton->setEventId("cancel");
// Set dimensions/positions
- setSize(240, 216);
+ setContentSize(240, 216);
scrollArea->setDimension(gcn::Rectangle(10, 40, 90, 50));
modeList->setDimension(gcn::Rectangle(0, 0, 60, 50));
displayLabel->setDimension(gcn::Rectangle(10, 10, 100,16));
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 1d4bc7e4..c5aaab45 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -66,7 +66,7 @@ SkillDialog::SkillDialog():
incButton->setEventId("inc");
closeButton->setEventId("close");
- setSize(240, 240);
+ setContentSize(240, 240);
skillScrollArea->setDimension(gcn::Rectangle(5, 5, 229, 180));
pointsLabel->setDimension(gcn::Rectangle(8, 190, 200, 16));
incButton->setPosition(64, 210);
diff --git a/src/gui/slider.cpp b/src/gui/slider.cpp
index c0f494c4..eb7ac1aa 100644
--- a/src/gui/slider.cpp
+++ b/src/gui/slider.cpp
@@ -68,7 +68,7 @@ void Slider::init()
w = 9; h = 10;
hGrip = slider->getSubImage(x, y, w, h);
- mMarkerWidth = hGrip->getWidth();
+ setMarkerLength(hGrip->getWidth());
}
void Slider::draw(gcn::Graphics *graphics)
@@ -99,7 +99,7 @@ void Slider::drawMarker(gcn::Graphics *graphics)
int x, y;
getAbsolutePosition(x, y);
- x += mMarkerPosition;
+ x += getMarkerPosition();
y += (h - hGrip->getHeight()) / 2;
hGrip->draw(screen, x, y);
diff --git a/src/gui/stats.cpp b/src/gui/stats.cpp
index 4629d5fa..655e217a 100644
--- a/src/gui/stats.cpp
+++ b/src/gui/stats.cpp
@@ -71,7 +71,7 @@ StatsWindow::StatsWindow():
update();
- setSize(200, 180);
+ setContentSize(200, 180);
setLocationRelativeTo(getParent());
}
diff --git a/src/gui/status.cpp b/src/gui/status.cpp
index a515b6c5..f8db9808 100644
--- a/src/gui/status.cpp
+++ b/src/gui/status.cpp
@@ -75,7 +75,7 @@ StatusWindow::StatusWindow():
inventoryButton->setPosition(skillsButton->getX() + skillsButton->getWidth() + CONTROLS_SEPARATOR, statsButton->getY());
setupButton->setPosition(inventoryButton->getX() + inventoryButton->getWidth() + CONTROLS_SEPARATOR, statsButton->getY());
- setSize(250, statsButton->getY() + statsButton->getHeight() + WIN_BORDER);
+ setContentSize(250, statsButton->getY() + statsButton->getHeight() + WIN_BORDER);
add(hp);
add(sp);
@@ -117,7 +117,7 @@ void StatusWindow::update()
sprintf(tempstr, "%s Lvl: % 2i Job: % 2i",
char_info->name, char_info->lv, char_info->job_lv);
- setTitle(tempstr);
+ setCaption(tempstr);
sprintf(tempstr, "%d / %d", char_info->hp, char_info->max_hp);
hpValue->setCaption(tempstr);
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 13f0cc9a..0d8ce5ff 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -28,24 +28,16 @@
WindowContainer *Window::windowContainer = NULL;
-Window::Window(const std::string& text, bool modal, Window *parent):
+Window::Window(const std::string& caption, bool modal, Window *parent):
+ gcn::Window(caption),
parent(parent),
- caption(text),
- mousePX(0),
- mousePY(0),
snapSize(8),
- mouseDown(false),
- modal(modal),
- titlebarHeight(20),
- padding(3)
+ modal(modal)
{
log("Window::Window(\"%s\")", caption.c_str());
- titlebarColor.r = 203;
- titlebarColor.g = 203;
- titlebarColor.b = 203;
-
- setBaseColor(gcn::Color(255, 255, 255));
+ setBorderSize(0);
+ setPadding(3);
// Load dialog title bar image
ResourceManager *resman = ResourceManager::getInstance();
@@ -62,14 +54,10 @@ Window::Window(const std::string& text, bool modal, Window *parent):
border.grid[7] = dBorders->getSubImage(4, 15, 3, 4);
border.grid[8] = dBorders->getSubImage(7, 15, 4, 4);
- // Register mouse listener
- addMouseListener(this);
-
// Add chrome
chrome = new gcn::Container();
chrome->setOpaque(false);
- chrome->setPosition(padding, titlebarHeight + padding);
- gcn::Container::add(chrome);
+ setContent(chrome);
// Add this window to the window container
if (windowContainer) {
@@ -85,7 +73,7 @@ Window::Window(const std::string& text, bool modal, Window *parent):
Window::~Window()
{
- log("Window::~Window(\"%s\")", caption.c_str());
+ log("Window::~Window(\"%s\")", getCaption().c_str());
// Free dialog bitmaps
//release_bitmap(dLeft);
@@ -113,37 +101,29 @@ void Window::draw(gcn::Graphics* graphics)
// Draw title
graphics->setFont(getFont());
- graphics->drawText(caption, 7, 5, gcn::Graphics::LEFT);
-
- drawChildren(graphics);
-}
-
-void Window::setTitle(const std::string& text)
-{
- caption = std::string(text);
-}
+ graphics->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT);
-void Window::setDimension(const gcn::Rectangle &dimension)
-{
- gcn::Container::setDimension(gcn::Rectangle(
- dimension.x,
- dimension.y - titlebarHeight,
- dimension.width,
- dimension.height + titlebarHeight));
- chrome->setDimension(gcn::Rectangle(0, titlebarHeight,
- dimension.width, dimension.height));
+ if (mContent != NULL)
+ {
+ graphics->pushClipArea(getContentDimension());
+ graphics->pushClipArea(gcn::Rectangle(
+ 0, 0, mContent->getWidth(), mContent->getHeight()));
+ mContent->draw(graphics);
+ graphics->popClipArea();
+ graphics->popClipArea();
+ }
}
-void Window::setWidth(int width)
+void Window::setContentWidth(int width)
{
- gcn::Container::setWidth(width + 2 * padding);
chrome->setWidth(width);
+ resizeToContent();
}
-void Window::setHeight(int height)
+void Window::setContentHeight(int height)
{
- gcn::Container::setHeight(height + titlebarHeight + 2 * padding);
chrome->setHeight(height);
+ resizeToContent();
}
void Window::setLocationRelativeTo(gcn::Widget* widget)
@@ -159,10 +139,10 @@ void Window::setLocationRelativeTo(gcn::Widget* widget)
getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y));
}
-void Window::setSize(int width, int height)
+void Window::setContentSize(int width, int height)
{
- setWidth(width);
- setHeight(height);
+ setContentWidth(width);
+ setContentHeight(height);
}
Window *Window::getParentWindow()
@@ -185,62 +165,25 @@ void Window::add(gcn::Widget *w, int x, int y)
chrome->add(w, x, y);
}
-void Window::mousePress(int mx, int my, int button)
-{
- mouseDown = true;
-
- mousePX = mx;
- mousePY = my;
-}
-
-void Window::mouseRelease(int mx, int my, int button)
-{
- mouseDown = false;
-}
-
void Window::mouseMotion(int mx, int my)
{
- if (mouseDown)
+ if (mMouseDrag && isMovable())
{
- int winWidth = this->getDimension().width;
- int winHeight = this->getDimension().height;
- int x = this->getDimension().x;
- int y = this->getDimension().y;
-
- x = x - (mousePX - mx);
- y = y - (mousePY - my);
+ int x = mx - mMouseXOffset + getX();
+ int y = my - mMouseYOffset + getY();
// Keep guichan window inside window
if (x < 0) x = 0;
if (y < 0) y = 0;
- if (x + winWidth > screen->w) x = screen->w - winWidth;
- if (y + winHeight > screen->h) y = screen->h - winHeight;
+ if (x + getWidth() > screen->w) x = screen->w - getWidth();
+ if (y + getHeight() > screen->h) y = screen->h - getHeight();
// Snap window to edges
- /*
- if (x < snapSize) x = 0;
- if (y < snapSize) y = 0;
- if (x + winWidth + snapSize > screen->w) x = screen->w - winWidth;
- if (y + winHeight + snapSize > screen->h) y = screen->h - winHeight;
- */
-
- this->setPosition(x, y);
- }
-}
+ //if (x < snapSize) x = 0;
+ //if (y < snapSize) y = 0;
+ //if (x + winWidth + snapSize > screen->w) x = screen->w - winWidth;
+ //if (y + winHeight + snapSize > screen->h) y = screen->h - winHeight;
-void Window::mouseOut()
-{
- mouseDown = false;
-}
-
-void Window::_mouseInputMessage(const gcn::MouseInput &mouseInput)
-{
- if (mouseInput.getType() == gcn::MouseInput::MOTION && mouseDown) {
- // It's a window drag event
- gcn::Widget::_mouseInputMessage(mouseInput);
- }
- else {
- // It's something else
- gcn::Container::_mouseInputMessage(mouseInput);
+ setPosition(x, y);
}
}
diff --git a/src/gui/window.h b/src/gui/window.h
index deb00583..2b98bebf 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -35,21 +35,13 @@
*
* \ingroup GUI
*/
-class Window : public gcn::Container, public gcn::MouseListener
+class Window : public gcn::Window
{
protected:
gcn::Container *chrome; /**< Contained container */
Window *parent; /**< The parent window */
- std::string caption; /**< Title bar caption */
- int z; /**< Z position of the window */
- int mousePX; /**< Mouse down location */
- int mousePY; /**< Mouse down location */
int snapSize; /**< Snap distance to window edge */
- bool mouseDown; /**< Mouse button state */
bool modal; /**< Window is modal */
- gcn::Color titlebarColor; /**< Title bar color */
- int titlebarHeight; /**< Height of title bar */
- int padding; /**< Space between contents and border */
float guiAlpha; /**< Opacity of GUI windows */
Image *dBackground; /**< Left side of title bar */
@@ -71,7 +63,7 @@ class Window : public gcn::Container, public gcn::MouseListener
* this one in the window hiearchy. When reordering,
* a window will never go below its parent window.
*/
- Window(const std::string& text = "Window", bool modal = false,
+ Window(const std::string &caption = "Window", bool modal = false,
Window *parent = NULL);
/**
@@ -100,24 +92,14 @@ class Window : public gcn::Container, public gcn::MouseListener
void add(gcn::Widget *w, int x, int y);
/**
- * Sets the title of the window.
- */
- void setTitle(const std::string& text);
-
- /**
- * Sets the dimension of the window contents.
- */
- void setDimension(const gcn::Rectangle& dimension);
-
- /**
* Sets the width of the window contents.
*/
- void setWidth(int width);
+ void setContentWidth(int width);
/**
* Sets the height of the window contents.
*/
- void setHeight(int height);
+ void setContentHeight(int height);
/**
* Sets the location relative to the given widget.
@@ -127,7 +109,7 @@ class Window : public gcn::Container, public gcn::MouseListener
/**
* Sets the size of this window.
*/
- void setSize(int width, int height);
+ void setContentSize(int width, int height);
/**
* Returns the parent window.
@@ -142,14 +124,11 @@ class Window : public gcn::Container, public gcn::MouseListener
*/
bool isModal();
- // Mouse handling
-
- void mousePress(int mx, int my, int button);
- void mouseRelease(int mx, int my, int button);
+ /**
+ * Window dragging. This method also makes sure the window is not
+ * dragged outside of the screen.
+ */
void mouseMotion(int mx, int my);
- void mouseOut();
-
- void _mouseInputMessage(const gcn::MouseInput &mouseInput);
};
#endif
diff --git a/src/gui/windowcontainer.cpp b/src/gui/windowcontainer.cpp
index c7e466fe..fad46137 100644
--- a/src/gui/windowcontainer.cpp
+++ b/src/gui/windowcontainer.cpp
@@ -41,7 +41,7 @@ void WindowContainer::logic()
gcn::Container::logic();
}
-
+/*
void WindowContainer::_mouseInputMessage(const gcn::MouseInput &mouseInput)
{
if (mouseInput.getType() == gcn::MouseInput::PRESS)
@@ -96,7 +96,7 @@ void WindowContainer::_mouseInputMessage(const gcn::MouseInput &mouseInput)
gcn::Widget::_mouseInputMessage(mouseInput);
}
}
-
+*/
void WindowContainer::add(gcn::Widget *widget)
{
gcn::Container::add(widget);
diff --git a/src/gui/windowcontainer.h b/src/gui/windowcontainer.h
index 582faf7a..d9c49a2f 100644
--- a/src/gui/windowcontainer.h
+++ b/src/gui/windowcontainer.h
@@ -50,7 +50,7 @@ class WindowContainer : public gcn::Container {
* Handles mouse input messages. Differs from standard behaviour in
* that widget with mouse doesn't change while a button is pressed.
*/
- void _mouseInputMessage(const gcn::MouseInput &mouseInput);
+ //void _mouseInputMessage(const gcn::MouseInput &mouseInput);
/**
* Adds a widget. The widget can be set to be modal, which will ensure