Add some files I forgot in my last commit.

This commit is contained in:
Mark de Wever 2008-09-22 21:33:43 +00:00
parent d3751f85ea
commit 18bf6fc2b0
2 changed files with 126 additions and 0 deletions

56
src/gui/widgets/image.cpp Normal file
View file

@ -0,0 +1,56 @@
/* $Id$ */
/*
copyright (C) 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/image.hpp"
#include "../../image.hpp"
#include "log.hpp"
#define DBG_G LOG_STREAM_INDENT(debug, gui)
#define LOG_G LOG_STREAM_INDENT(info, gui)
#define WRN_G LOG_STREAM_INDENT(warn, gui)
#define ERR_G LOG_STREAM_INDENT(err, gui)
#define DBG_G_D LOG_STREAM_INDENT(debug, gui_draw)
#define LOG_G_D LOG_STREAM_INDENT(info, gui_draw)
#define WRN_G_D LOG_STREAM_INDENT(warn, gui_draw)
#define ERR_G_D LOG_STREAM_INDENT(err, gui_draw)
#define DBG_G_E LOG_STREAM_INDENT(debug, gui_event)
#define LOG_G_E LOG_STREAM_INDENT(info, gui_event)
#define WRN_G_E LOG_STREAM_INDENT(warn, gui_event)
#define ERR_G_E LOG_STREAM_INDENT(err, gui_event)
#define DBG_G_P LOG_STREAM_INDENT(debug, gui_parse)
#define LOG_G_P LOG_STREAM_INDENT(info, gui_parse)
#define WRN_G_P LOG_STREAM_INDENT(warn, gui_parse)
#define ERR_G_P LOG_STREAM_INDENT(err, gui_parse)
namespace gui2 {
tpoint timage::get_best_size() const
{
surface image(get_image(image::locator(label())));
if(image) {
return tpoint(image->w, image->h);
}
return tpoint(0, 0);
}
} // namespace gui2

70
src/gui/widgets/image.hpp Normal file
View file

@ -0,0 +1,70 @@
/* $Id$ */
/*
copyright (C) 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_IMAGE_HPP_INCLUDED
#define GUI_WIDGETS_IMAGE_HPP_INCLUDED
#include "gui/widgets/control.hpp"
namespace gui2 {
/** An image. */
class timage : public tcontrol
{
public:
timage()
: tcontrol(COUNT)
{
}
/** Inherited from twidget. */
tpoint get_minimum_size() const { return get_best_size(); }
/** Inherited from twidget. */
tpoint get_best_size() const;
/** Import overloaded versions. */
using tcontrol::get_best_size;
/** Inherited from twidget. */
tpoint get_maximum_size() const { return get_best_size(); }
/** Inherited from tcontrol. */
void set_active(const bool /*active*/) {}
/** Inherited from tcontrol. */
bool get_active() const { return true; }
/** Inherited from tcontrol. */
unsigned get_state() const { return ENABLED; }
private:
/**
* Possible states of the widget.
*
* Note the order of the states must be the same as defined in settings.hpp.
*/
enum tstate { ENABLED, COUNT };
/** Inherited from tcontrol. */
const std::string& get_control_type() const
{ static const std::string type = "image"; return type; }
};
} // namespace gui2
#endif