Button is a FbWindow
This commit is contained in:
parent
5855c7825b
commit
eac153c43c
2 changed files with 25 additions and 68 deletions
|
@ -19,7 +19,7 @@
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// $Id: Button.cc,v 1.10 2003/08/11 14:40:15 fluxgen Exp $
|
// $Id: Button.cc,v 1.11 2003/08/13 09:25:16 fluxgen Exp $
|
||||||
|
|
||||||
#include "Button.hh"
|
#include "Button.hh"
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ namespace FbTk {
|
||||||
|
|
||||||
Button::Button(int screen_num, int x, int y,
|
Button::Button(int screen_num, int x, int y,
|
||||||
unsigned int width, unsigned int height):
|
unsigned int width, unsigned int height):
|
||||||
m_win(screen_num, x, y, width, height,
|
FbWindow(screen_num, x, y, width, height,
|
||||||
ExposureMask | ButtonPressMask | ButtonReleaseMask),
|
ExposureMask | ButtonPressMask | ButtonReleaseMask),
|
||||||
m_foreground_pm(0),
|
m_foreground_pm(0),
|
||||||
m_background_pm(0),
|
m_background_pm(0),
|
||||||
|
@ -40,24 +40,24 @@ Button::Button(int screen_num, int x, int y,
|
||||||
m_pressed(false) {
|
m_pressed(false) {
|
||||||
|
|
||||||
// add this to eventmanager
|
// add this to eventmanager
|
||||||
FbTk::EventManager::instance()->add(*this, m_win);
|
FbTk::EventManager::instance()->add(*this, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::Button(const FbWindow &parent, int x, int y,
|
Button::Button(const FbWindow &parent, int x, int y,
|
||||||
unsigned int width, unsigned int height):
|
unsigned int width, unsigned int height):
|
||||||
m_win(parent, x, y, width, height,
|
FbWindow(parent, x, y, width, height,
|
||||||
ExposureMask | ButtonPressMask | ButtonReleaseMask),
|
ExposureMask | ButtonPressMask | ButtonReleaseMask),
|
||||||
m_foreground_pm(0),
|
m_foreground_pm(0),
|
||||||
m_background_pm(0),
|
m_background_pm(0),
|
||||||
m_pressed_pm(0),
|
m_pressed_pm(0),
|
||||||
m_gc(DefaultGC(FbTk::App::instance()->display(), m_win.screenNumber())),
|
m_gc(DefaultGC(FbTk::App::instance()->display(), screenNumber())),
|
||||||
m_pressed(false) {
|
m_pressed(false) {
|
||||||
// add this to eventmanager
|
// add this to eventmanager
|
||||||
FbTk::EventManager::instance()->add(*this, m_win);
|
FbTk::EventManager::instance()->add(*this, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::~Button() {
|
Button::~Button() {
|
||||||
FbTk::EventManager::instance()->remove(m_win);
|
FbTk::EventManager::instance()->remove(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::setOnClick(RefCount<Command> &cmd, int button) {
|
void Button::setOnClick(RefCount<Command> &cmd, int button) {
|
||||||
|
@ -68,18 +68,6 @@ void Button::setOnClick(RefCount<Command> &cmd, int button) {
|
||||||
m_onclick[button - 1] = cmd;
|
m_onclick[button - 1] = cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::move(int x, int y) {
|
|
||||||
window().move(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::resize(unsigned int w, unsigned int h) {
|
|
||||||
window().resize(w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::moveResize(int x, int y, unsigned int width, unsigned int height) {
|
|
||||||
window().moveResize(x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::setPixmap(Pixmap pm) {
|
void Button::setPixmap(Pixmap pm) {
|
||||||
m_foreground_pm = pm;
|
m_foreground_pm = pm;
|
||||||
}
|
}
|
||||||
|
@ -90,40 +78,28 @@ void Button::setPressedPixmap(Pixmap pm) {
|
||||||
|
|
||||||
void Button::setBackgroundColor(const Color &color) {
|
void Button::setBackgroundColor(const Color &color) {
|
||||||
m_background_color = color;
|
m_background_color = color;
|
||||||
window().setBackgroundColor(color);
|
FbTk::FbWindow::setBackgroundColor(color);
|
||||||
clear();
|
|
||||||
window().updateTransparent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::setBackgroundPixmap(Pixmap pm) {
|
void Button::setBackgroundPixmap(Pixmap pm) {
|
||||||
m_background_pm = pm;
|
m_background_pm = pm;
|
||||||
window().setBackgroundPixmap(pm);
|
FbTk::FbWindow::setBackgroundPixmap(pm);
|
||||||
clear();
|
|
||||||
window().updateTransparent();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::show() {
|
|
||||||
m_win.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::hide() {
|
|
||||||
m_win.hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::buttonPressEvent(XButtonEvent &event) {
|
void Button::buttonPressEvent(XButtonEvent &event) {
|
||||||
if (m_pressed_pm != 0)
|
if (m_pressed_pm != 0)
|
||||||
m_win.setBackgroundPixmap(m_pressed_pm);
|
FbWindow::setBackgroundPixmap(m_pressed_pm);
|
||||||
m_pressed = true;
|
m_pressed = true;
|
||||||
clear();
|
clear();
|
||||||
window().updateTransparent();
|
FbWindow::updateTransparent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::buttonReleaseEvent(XButtonEvent &event) {
|
void Button::buttonReleaseEvent(XButtonEvent &event) {
|
||||||
m_pressed = false;
|
m_pressed = false;
|
||||||
if (m_background_pm)
|
if (m_background_pm)
|
||||||
m_win.setBackgroundPixmap(m_background_pm);
|
FbWindow::setBackgroundPixmap(m_background_pm);
|
||||||
else
|
else
|
||||||
m_win.setBackgroundColor(m_background_color);
|
FbWindow::setBackgroundColor(m_background_color);
|
||||||
|
|
||||||
clear(); // clear background
|
clear(); // clear background
|
||||||
|
|
||||||
|
@ -131,26 +107,26 @@ void Button::buttonReleaseEvent(XButtonEvent &event) {
|
||||||
Display *disp = App::instance()->display();
|
Display *disp = App::instance()->display();
|
||||||
|
|
||||||
if (m_gc == 0) // get default gc if we dont have one
|
if (m_gc == 0) // get default gc if we dont have one
|
||||||
m_gc = DefaultGC(disp, m_win.screenNumber());
|
m_gc = DefaultGC(disp, screenNumber());
|
||||||
|
|
||||||
XCopyArea(disp, m_foreground_pm, m_win.window(), m_gc, 0, 0, width(), height(), 0, 0);
|
XCopyArea(disp, m_foreground_pm, window(), m_gc, 0, 0, width(), height(), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.button > 0 && event.button <= 5 &&
|
if (event.button > 0 && event.button <= 5 &&
|
||||||
m_onclick[event.button -1].get() != 0)
|
m_onclick[event.button -1].get() != 0)
|
||||||
m_onclick[event.button - 1]->execute();
|
m_onclick[event.button - 1]->execute();
|
||||||
|
|
||||||
window().updateTransparent();
|
FbWindow::updateTransparent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::exposeEvent(XExposeEvent &event) {
|
void Button::exposeEvent(XExposeEvent &event) {
|
||||||
if (m_background_pm)
|
if (m_background_pm)
|
||||||
m_win.setBackgroundPixmap(m_background_pm);
|
FbWindow::setBackgroundPixmap(m_background_pm);
|
||||||
else
|
else
|
||||||
m_win.setBackgroundColor(m_background_color);
|
FbWindow::setBackgroundColor(m_background_color);
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
window().updateTransparent(event.x, event.y, event.width, event.height);
|
FbWindow::updateTransparent(event.x, event.y, event.width, event.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // end namespace FbTk
|
}; // end namespace FbTk
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// $Id: Button.hh,v 1.4 2003/04/28 22:22:25 fluxgen Exp $
|
// $Id: Button.hh,v 1.5 2003/08/13 09:25:16 fluxgen Exp $
|
||||||
|
|
||||||
#ifndef FBTK_BUTTON_HH
|
#ifndef FBTK_BUTTON_HH
|
||||||
#define FBTK_BUTTON_HH
|
#define FBTK_BUTTON_HH
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
namespace FbTk {
|
namespace FbTk {
|
||||||
|
|
||||||
class Button:public EventHandler,
|
class Button:public FbTk::FbWindow, public EventHandler,
|
||||||
private NotCopyable {
|
private NotCopyable {
|
||||||
public:
|
public:
|
||||||
Button(int screen_num, int x, int y, unsigned int width, unsigned int height);
|
Button(int screen_num, int x, int y, unsigned int width, unsigned int height);
|
||||||
|
@ -46,10 +46,6 @@ public:
|
||||||
/// sets action when the button is clicked with #button mouse btn
|
/// sets action when the button is clicked with #button mouse btn
|
||||||
void setOnClick(RefCount<Command> &com, int button = 1);
|
void setOnClick(RefCount<Command> &com, int button = 1);
|
||||||
|
|
||||||
virtual void move(int x, int y);
|
|
||||||
virtual void resize(unsigned int width, unsigned int height);
|
|
||||||
virtual void moveResize(int x, int y, unsigned int width, unsigned int height);
|
|
||||||
|
|
||||||
/// sets foreground pixmap
|
/// sets foreground pixmap
|
||||||
void setPixmap(Pixmap pm);
|
void setPixmap(Pixmap pm);
|
||||||
/// sets the pixmap to be viewed when the button is pressed
|
/// sets the pixmap to be viewed when the button is pressed
|
||||||
|
@ -60,11 +56,7 @@ public:
|
||||||
void setBackgroundPixmap(Pixmap pm);
|
void setBackgroundPixmap(Pixmap pm);
|
||||||
/// sets background color
|
/// sets background color
|
||||||
void setBackgroundColor(const Color &color);
|
void setBackgroundColor(const Color &color);
|
||||||
/// show button
|
|
||||||
void show();
|
|
||||||
/// hide button
|
|
||||||
void hide();
|
|
||||||
virtual void clear() { m_win.clear(); }
|
|
||||||
/**
|
/**
|
||||||
@name eventhandlers
|
@name eventhandlers
|
||||||
*/
|
*/
|
||||||
|
@ -76,21 +68,10 @@ public:
|
||||||
|
|
||||||
/// @return true if the button is pressed, else false
|
/// @return true if the button is pressed, else false
|
||||||
bool pressed() const { return m_pressed; }
|
bool pressed() const { return m_pressed; }
|
||||||
/**
|
|
||||||
@name position and size of the button
|
|
||||||
*/
|
|
||||||
//@{
|
|
||||||
int x() const { return m_win.x(); }
|
|
||||||
int y() const { return m_win.y(); }
|
|
||||||
unsigned int width() const { return m_win.width(); }
|
|
||||||
unsigned int height() const { return m_win.height(); }
|
|
||||||
//@}
|
|
||||||
FbWindow &window() { return m_win; }
|
|
||||||
const FbWindow &window() const { return m_win; }
|
|
||||||
GC gc() const { return m_gc; }
|
GC gc() const { return m_gc; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FbTk::FbWindow m_win; ///< window for button
|
|
||||||
Pixmap m_foreground_pm; ///< foreground pixmap
|
Pixmap m_foreground_pm; ///< foreground pixmap
|
||||||
Pixmap m_background_pm; ///< background pixmap
|
Pixmap m_background_pm; ///< background pixmap
|
||||||
Color m_background_color; ///< background color
|
Color m_background_color; ///< background color
|
||||||
|
|
Loading…
Reference in a new issue