Skip to content

Commit

Permalink
Introducing room button #16
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaudic committed Jan 5, 2020
1 parent 97cc4ed commit e6cbc2f
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
93 changes: 93 additions & 0 deletions src/ui/roombutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* \file roombutton.hpp
* \brief Button overload for rooms in serverview
* \author G. B.
* \version 0.1a
* \date 02/11/2016
*/
/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is “Incompatible With Secondary Licenses”,
* as defined by the Mozilla Public License, v. 2.0.
*/

#include "../config.hpp"
#include "roombutton.hpp"
using namespace std;

/**
* Constructor
*/
LB_RoomButton::LB_RoomButton(const Uint16 nb, const std::string &name, const GameMode mode) : gcn::ImageButton(RESOURCE_PREFIX + "room_button.png"),
number(nb), roomName(name), gameMode(mode) {

}

LB_RoomButton::~LB_RoomButton() {

}

void LB_RoomButton::draw(gcn::Graphics* graphics) {
//TODO

gcn::Color faceColor = getBaseColor();
gcn::Color highlightColor, shadowColor;
int alpha = getBaseColor().a;

if (isPressed())
{
faceColor = faceColor - 0x303030;
faceColor.a = alpha;
highlightColor = faceColor - 0x303030;
highlightColor.a = alpha;
shadowColor = faceColor + 0x303030;
shadowColor.a = alpha;
}
else
{
highlightColor = faceColor + 0x303030;
highlightColor.a = alpha;
shadowColor = faceColor - 0x303030;
shadowColor.a = alpha;
}

graphics->setColor(faceColor);
graphics->fillRectangle(gcn::Rectangle(1, 1, getDimension().width-1, getHeight() - 1));

graphics->setColor(highlightColor);
graphics->drawLine(0, 0, getWidth() - 1, 0);
graphics->drawLine(0, 1, 0, getHeight() - 1);

graphics->setColor(shadowColor);
graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);

graphics->setColor(getForegroundColor());

if(isPressed()) {
graphics->drawImage(mImage, 0 + 1, 0 + 1);
graphics->drawText(to_string(number), 2 + 1, 2 + 1, gcn::Graphics::LEFT);
graphics->drawText(roomName, 20 + 1, 2 + 1, gcn::Graphics::LEFT);
//Draw room image
//Draw status image
} else {
graphics->drawImage(mImage, 0, 0);
graphics->drawText(to_string(number), 2, 2, gcn::Graphics::LEFT);
graphics->drawText(roomName, 20, 2, gcn::Graphics::LEFT);

if (isFocused()) {
graphics->drawRectangle(gcn::Rectangle(2, 2, getWidth() - 4, getHeight() - 4));
}
}

}

/**
* May be necessary for GUI interaction
* \return the number for the room represented by this button on the GUI
*/
Uint16 LB_RoomButton::getNumber() {
return number;
}
40 changes: 40 additions & 0 deletions src/ui/roombutton.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* \file roombutton.hpp
* \brief Button overload for rooms in serverview
* \author G. B.
* \version 0.1a
* \date 02/11/2016
*/
/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is “Incompatible With Secondary Licenses”,
* as defined by the Mozilla Public License, v. 2.0.
*/

#ifndef _H_ROOMBUTTON_
#define _H_ROOMBUTTON_

#include <string>
#include <guisan.hpp>
#include "../constants.hpp"

/**
* @brief An improved button to represent a room
*/
class LB_RoomButton : public gcn::ImageButton {
public:
LB_RoomButton(const Uint16 nb, const std::string &name, const GameMode mode);
virtual ~LB_RoomButton();
virtual void draw(gcn::Graphics* graphics);
Uint16 getNumber();

private:
Uint16 number;
std::string roomName;
GameMode gameMode;
gcn::Image* mStatusImages;
};

#endif //! _H_ROOMBUTTON_

0 comments on commit e6cbc2f

Please sign in to comment.