mail[Wesnoth-commits] r13971 - in /trunk/src: game.cpp widgets/menu.cpp widgets/menu.hpp widgets/menu_style.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by patrick_X99 on October 15, 2006 - 04:18:
Author: sapient
Date: Sun Oct 15 04:18:00 2006
New Revision: 13971

URL: http://svn.gna.org/viewcvs/wesnoth?rev=13971&view=rev
Log:
scale the images in the Get Add-ons dialog to maximum 72x72 (relative_size)

Modified:
    trunk/src/game.cpp
    trunk/src/widgets/menu.cpp
    trunk/src/widgets/menu.hpp
    trunk/src/widgets/menu_style.cpp

Modified: trunk/src/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=13971&r1=13970&r2=13971&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Sun Oct 15 04:18:00 2006
@@ -993,8 +993,14 @@
                gui::menu::basic_sorter sorter;
                
sorter.set_alpha_sort(1).set_alpha_sort(2).set_alpha_sort(3).set_numeric_sort(4).set_position_sort(5,sizes);
 
-               const int index = gui::show_dialog2(disp(),NULL,_("Get 
Add-ons"),_("Choose the add-on to download."),gui::OK_CANCEL,&options,
-                       NULL, "", NULL, 256, NULL, NULL, -1, -1, NULL, NULL, 
"", &sorter);
+               gui::dialog addon_dialog(disp(), _("Get Add-ons"), _("Choose 
the add-on to download."),
+                       gui::OK_CANCEL);
+               gui::menu::style addon_style(gui::menu::default_style);
+               addon_style.scale_images(font::relative_size(72), 
font::relative_size(72));
+               gui::menu *addon_menu = new gui::menu(disp().video(), 
options, false, -1,
+                       gui::dialog::max_menu_width, &sorter, &addon_style, 
false);
+               addon_dialog.set_menu(addon_menu);
+               const int index = addon_dialog.show();
                if(index < 0) {
                        return;
                }

Modified: trunk/src/widgets/menu.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/widgets/menu.cpp?rev=13971&r1=13970&r2=13971&view=diff
==============================================================================
--- trunk/src/widgets/menu.cpp (original)
+++ trunk/src/widgets/menu.cpp Sun Oct 15 04:18:00 2006
@@ -671,7 +671,7 @@
                const std::string str = *it;
                if (!str.empty() && str[0] == IMAGE_PREFIX) {
                        const std::string image_name(str.begin()+1,str.end());
-                       surface const img = 
image::get_image(image_name,image::UNSCALED);
+                       surface const img = get_item_image(image_name);
                        if(img != NULL) {
                                res.w += img->w;
                                res.h = maximum<int>(img->h, res.h);
@@ -805,7 +805,7 @@
                        str = *it;
                        if (!str.empty() && str[0] == IMAGE_PREFIX) {
                                const std::string 
image_name(str.begin()+1,str.end());
-                               const surface img = 
image::get_image(image_name,image::UNSCALED);
+                               const surface img = 
style_->get_item_image(image_name);
                                const int remaining_width = max_width_ < 0 ? 
area.w :
                                minimum<int>(max_width_, ((lang_rtl)? xpos - 
rect.x : rect.x + rect.w - xpos));
                                if(img != NULL && img->w <= remaining_width

Modified: trunk/src/widgets/menu.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/widgets/menu.hpp?rev=13971&r1=13970&r2=13971&view=diff
==============================================================================
--- trunk/src/widgets/menu.hpp (original)
+++ trunk/src/widgets/menu.hpp Sun Oct 15 04:18:00 2006
@@ -20,6 +20,7 @@
 #include <vector>
 
 
+#include "../image.hpp"
 #include "../events.hpp"
 #include "../sdl_utils.hpp"
 
@@ -48,7 +49,9 @@
                virtual SDL_Rect item_size(const std::string& item) const;
                virtual void draw_row_bg(menu& menu_ref, const size_t 
row_index, const SDL_Rect& rect, ROW_TYPE type);
                virtual void draw_row(menu& menu_ref, const size_t row_index, 
const SDL_Rect& rect, ROW_TYPE type);
-
+               void scale_images(int max_width, int max_height);
+
+               surface get_item_image(const image::locator &i_locator) const;
                size_t get_font_size() const;
                size_t get_cell_padding() const;
                size_t get_thickness() const;
@@ -60,6 +63,7 @@
 
                int normal_rgb_, selected_rgb_, heading_rgb_;
                double normal_alpha_, selected_alpha_, heading_alpha_;
+               int max_img_w_, max_img_h_;
        };
 
        //image-border selction style

Modified: trunk/src/widgets/menu_style.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/widgets/menu_style.cpp?rev=13971&r1=13970&r2=13971&view=diff
==============================================================================
--- trunk/src/widgets/menu_style.cpp (original)
+++ trunk/src/widgets/menu_style.cpp Sun Oct 15 04:18:00 2006
@@ -54,7 +54,8 @@
 menu::style::style() : font_size_(font::SIZE_NORMAL),
                cell_padding_(font::SIZE_NORMAL * 3/5), thickness_(0),
                normal_rgb_(0x000000), selected_rgb_(0x000099), 
heading_rgb_(0x333333),
-               normal_alpha_(0.2),  selected_alpha_(0.6), heading_alpha_(0.3)
+               normal_alpha_(0.2),  selected_alpha_(0.6), 
heading_alpha_(0.3),
+               max_img_w_(-1), max_img_h_(-1)
 {}
 
 menu::style::~style()
@@ -73,6 +74,31 @@
 size_t menu::style::get_cell_padding() const { return cell_padding_; }
 size_t menu::style::get_thickness() const { return thickness_; }
 
+void menu::style::scale_images(int max_width, int max_height)
+{
+       max_img_w_ = max_width;
+       max_img_h_ = max_height;
+}
+
+surface menu::style::get_item_image(const image::locator& img_loc) const
+{
+       surface surf = image::get_image(img_loc, image::UNSCALED);
+       if(!surf.null())
+       {
+               int scale = 100;
+               if(max_img_w_ > 0 && surf->w > max_img_w_) {
+                       scale = (max_img_w_ * 100) / surf->w;
+               }
+               if(max_img_h_ > 0 && surf->h > max_img_h_) {
+                       scale = minimum<int>(scale, ((max_img_h_ * 100) / 
surf->h));
+               }
+               if(scale != 100)
+               {
+                       return scale_surface(surf, (scale * surf->w)/100, 
(scale * surf->h)/100);
+               }
+       }
+       return surf;
+}
 
 bool menu::imgsel_style::load_image(const std::string &img_sub)
 {




Related Messages


Powered by MHonArc, Updated Sun Oct 15 08:20:17 2006