gui/widgets/image.cpp

Go to the documentation of this file.
00001 /* $Id: image.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017 
00018 #include "gui/widgets/image.hpp"
00019 
00020 #include "../../image.hpp"
00021 #include "gui/auxiliary/widget_definition/image.hpp"
00022 #include "gui/auxiliary/window_builder/image.hpp"
00023 #include "gui/auxiliary/log.hpp"
00024 #include "gui/widgets/settings.hpp"
00025 
00026 #include <boost/bind.hpp>
00027 
00028 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
00029 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
00030 
00031 namespace gui2 {
00032 
00033 REGISTER_WIDGET(image)
00034 
00035 tpoint timage::calculate_best_size() const
00036 {
00037     surface image(image::get_image(image::locator(label())));
00038 
00039     if(!image) {
00040         DBG_GUI_L << LOG_HEADER << " empty image return default.\n";
00041         return get_config_default_size();
00042     }
00043 
00044     const tpoint minimum = get_config_default_size();
00045     const tpoint maximum = get_config_maximum_size();
00046 
00047     tpoint result = tpoint(image->w, image->h);
00048 
00049     if(minimum.x > 0 && result.x < minimum.x) {
00050         DBG_GUI_L << LOG_HEADER << " increase width to minimum.\n";
00051         result.x = minimum.x;
00052     } else if(maximum.x > 0 && result.x > maximum.x) {
00053         DBG_GUI_L << LOG_HEADER << " decrease width to maximum.\n";
00054         result.x = maximum.x;
00055     }
00056 
00057     if(minimum.y > 0 && result.y < minimum.y) {
00058         DBG_GUI_L << LOG_HEADER << " increase height to minimum.\n";
00059         result.y = minimum.y;
00060     } else if(maximum.y > 0 && result.y > maximum.y) {
00061         DBG_GUI_L << LOG_HEADER << " decrease height to maximum.\n";
00062         result.y = maximum.y;
00063     }
00064 
00065     DBG_GUI_L << LOG_HEADER
00066         << " result " << result
00067         << ".\n";
00068     return result;
00069 }
00070 
00071 const std::string& timage::get_control_type() const
00072 {
00073     static const std::string type = "image";
00074     return type;
00075 }
00076 
00077 } // namespace gui2
00078 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:54 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs