Move the button class into its own file...
...and remove some ancient commented out stuff.
This commit is contained in:
parent
85661240b1
commit
89856be69f
5 changed files with 140 additions and 123 deletions
57
src/gui/widgets/button.cpp
Normal file
57
src/gui/widgets/button.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
copyright (c) 2007 - 2008 by mark de wever <koraq@xs4all.nl>
|
||||
part of the battle for wesnoth project http://www.wesnoth.org/
|
||||
|
||||
this program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the gnu general public license version 2
|
||||
or at your option any later version.
|
||||
this program is distributed in the hope that it will be useful,
|
||||
but without any warranty.
|
||||
|
||||
see the copying file for more details.
|
||||
*/
|
||||
|
||||
#include "gui/widgets/button.hpp"
|
||||
|
||||
#define DBG_GUI LOG_STREAM(debug, widget)
|
||||
#define LOG_GUI LOG_STREAM(info, widget)
|
||||
#define WRN_GUI LOG_STREAM(warn, widget)
|
||||
#define ERR_GUI LOG_STREAM(err, widget)
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
void tbutton::set_width(const int width)
|
||||
{
|
||||
// resize canvasses
|
||||
canvas_up_.set_width(width);
|
||||
canvas_up_mouse_over_.set_width(width);
|
||||
canvas_down_.set_width(width);
|
||||
|
||||
// inherited
|
||||
tcontrol::set_width(width);
|
||||
}
|
||||
|
||||
void tbutton::set_height(const int height)
|
||||
{
|
||||
// resize canvasses
|
||||
canvas_up_.set_height(height);
|
||||
canvas_up_mouse_over_.set_height(height);
|
||||
canvas_down_.set_height(height);
|
||||
|
||||
// inherited
|
||||
tcontrol::set_height(height);
|
||||
}
|
||||
|
||||
void tbutton::draw(surface& canvas)
|
||||
{
|
||||
DBG_GUI << "Drawing button\n";
|
||||
|
||||
canvas_up_.draw();
|
||||
|
||||
// now blit the cached image on the screen
|
||||
SDL_Rect rect = get_rect();
|
||||
SDL_BlitSurface(canvas_up_.surf(), 0, canvas, &rect);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
78
src/gui/widgets/button.hpp
Normal file
78
src/gui/widgets/button.hpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
copyright (c) 2007 - 2008 by mark de wever <koraq@xs4all.nl>
|
||||
part of the battle for wesnoth project http://www.wesnoth.org/
|
||||
|
||||
this program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the gnu general public license version 2
|
||||
or at your option any later version.
|
||||
this program is distributed in the hope that it will be useful,
|
||||
but without any warranty.
|
||||
|
||||
see the copying file for more details.
|
||||
*/
|
||||
|
||||
#ifndef __GUI_WIDGETS_BUTTON_HPP_INCLUDED__
|
||||
#define __GUI_WIDGETS_BUTTON_HPP_INCLUDED__
|
||||
|
||||
#include "gui/widgets/widget.hpp"
|
||||
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
// Class for a simple push button
|
||||
class tbutton : public tcontrol
|
||||
{
|
||||
friend void load_settings();
|
||||
public:
|
||||
tbutton(const std::string& id) :
|
||||
tcontrol()
|
||||
{
|
||||
canvas_up_.set_cfg(tbutton::default_enabled_draw_);
|
||||
}
|
||||
|
||||
virtual void set_width(const int width);
|
||||
|
||||
virtual void set_height(const int height);
|
||||
|
||||
void mouse_down(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse down\n"; }
|
||||
void mouse_up(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse up\n"; }
|
||||
void mouse_click(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse click\n"; }
|
||||
void mouse_double_click(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse double click\n"; }
|
||||
void mouse_enter(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse enter\n"; }
|
||||
void mouse_leave(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse leave\n"; }
|
||||
|
||||
void draw(surface& canvas);
|
||||
|
||||
// note we should check whether the label fits in the button
|
||||
tpoint get_best_size() const { return tpoint(default_width_, default_height_); }
|
||||
|
||||
void set_best_size(const tpoint& origin)
|
||||
{
|
||||
set_x(origin.x);
|
||||
set_y(origin.y);
|
||||
set_width(default_width_);
|
||||
set_height(default_height_);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
tcanvas
|
||||
canvas_up_,
|
||||
canvas_up_mouse_over_,
|
||||
canvas_down_;
|
||||
|
||||
static unsigned default_width_;
|
||||
static unsigned default_height_;
|
||||
static config default_enabled_draw_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "config.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "gui/widgets/widget.hpp"
|
||||
#include "log.hpp"
|
||||
#include "serialization/parser.hpp"
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#define WRN_GUI LOG_STREAM(warn, widget)
|
||||
#define ERR_GUI LOG_STREAM(err, widget)
|
||||
|
||||
namespace gui2{
|
||||
namespace gui2 {
|
||||
|
||||
namespace {
|
||||
static bool initialized_ = false;
|
||||
|
@ -348,75 +348,4 @@ tcontrol::tcontrol(/*const int x, const int y, const int w, const int h*/) :
|
|||
{
|
||||
}
|
||||
|
||||
void tbutton::set_width(const int width)
|
||||
{
|
||||
// resize canvasses
|
||||
canvas_up_.set_width(width);
|
||||
canvas_up_mouse_over_.set_width(width);
|
||||
canvas_down_.set_width(width);
|
||||
|
||||
// inherited
|
||||
tcontrol::set_width(width);
|
||||
}
|
||||
|
||||
void tbutton::set_height(const int height)
|
||||
{
|
||||
// resize canvasses
|
||||
canvas_up_.set_height(height);
|
||||
canvas_up_mouse_over_.set_height(height);
|
||||
canvas_down_.set_height(height);
|
||||
|
||||
// inherited
|
||||
tcontrol::set_height(height);
|
||||
}
|
||||
|
||||
void tbutton::draw(surface& canvas)
|
||||
{
|
||||
// create a dummy config with some objects to draw
|
||||
|
||||
DBG_GUI << "Drawing button\n";
|
||||
#if 0
|
||||
std::string dummy =
|
||||
"[line]\n"
|
||||
" x1, y1 = 0, 0\n"
|
||||
" x2, y2 = -1, 0\n"
|
||||
" colour = 255, 255, 255, 255\n"
|
||||
" thickness = 1\n"
|
||||
"[/line]\n"
|
||||
|
||||
"[line]\n"
|
||||
" x1, y1 = -1, 0\n"
|
||||
" x2, y2 = -1, -1\n"
|
||||
" colour = 255, 255, 255, 255\n"
|
||||
" thickness = 1\n"
|
||||
"[/line]\n"
|
||||
|
||||
"[line]\n"
|
||||
" x1, y1 = -1, -1\n"
|
||||
" x2, y2 = 0, -1\n"
|
||||
" colour = 0, 0, 0, 255\n"
|
||||
" thickness = 1\n"
|
||||
"[/line]\n"
|
||||
|
||||
"[line]\n"
|
||||
" x1, y1 = 0, -1\n"
|
||||
" x2, y2 = 0, 0\n"
|
||||
" colour = 0, 0, 0, 255\n"
|
||||
" thickness = 1\n"
|
||||
"[/line]\n";
|
||||
|
||||
config cfg;
|
||||
read(cfg, dummy);
|
||||
#endif
|
||||
// const config* cfg = button_enabled();
|
||||
|
||||
// canvas_up_.draw(*cfg);
|
||||
|
||||
canvas_up_.draw();
|
||||
|
||||
// now blit the cached image on the screen
|
||||
SDL_Rect rect = get_rect();
|
||||
SDL_BlitSurface(canvas_up_.surf(), 0, canvas, &rect);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace gui2
|
||||
|
|
|
@ -524,55 +524,6 @@ class tgrid : public twidget, public tcontainer
|
|||
*/
|
||||
|
||||
|
||||
// Class for a simple push button
|
||||
class tbutton : public tcontrol
|
||||
{
|
||||
friend void load_settings();
|
||||
public:
|
||||
tbutton(const std::string& id) :
|
||||
tcontrol()
|
||||
{
|
||||
canvas_up_.set_cfg(tbutton::default_enabled_draw_);
|
||||
}
|
||||
|
||||
virtual void set_width(const int width);
|
||||
|
||||
virtual void set_height(const int height);
|
||||
|
||||
void mouse_down(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse down\n"; }
|
||||
void mouse_up(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse up\n"; }
|
||||
void mouse_click(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse click\n"; }
|
||||
void mouse_double_click(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse double click\n"; }
|
||||
void mouse_enter(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse enter\n"; }
|
||||
void mouse_leave(const tevent_info& /*event*/, bool& /*handled*/) { std::cerr << "mouse leave\n"; }
|
||||
|
||||
void draw(surface& canvas);
|
||||
|
||||
// note we should check whether the label fits in the button
|
||||
tpoint get_best_size() const { return tpoint(default_width_, default_height_); }
|
||||
|
||||
void set_best_size(const tpoint& origin)
|
||||
{
|
||||
set_x(origin.x);
|
||||
set_y(origin.y);
|
||||
set_width(default_width_);
|
||||
set_height(default_height_);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
tcanvas
|
||||
canvas_up_,
|
||||
canvas_up_mouse_over_,
|
||||
canvas_down_;
|
||||
|
||||
static unsigned default_width_;
|
||||
static unsigned default_height_;
|
||||
static config default_enabled_draw_;
|
||||
};
|
||||
|
||||
/**
|
||||
* A widget has a mouse over which can either popup directly or after a fixed delay (this is a flag)
|
||||
* A widget has a help after pressing F1 it shows a larger tooltip with more info
|
||||
|
@ -694,6 +645,7 @@ positive numbers are from 0,0 negative from width, height
|
|||
[/image]
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue