[Widelands-cvs] SF.net SVN: widelands: [3172] trunk/src
Status: Beta
Brought to you by:
sirver
From: <si...@us...> - 2008-04-09 20:55:11
|
Revision: 3172 http://widelands.svn.sourceforge.net/widelands/?rev=3172&view=rev Author: sigra Date: 2008-04-09 13:54:46 -0700 (Wed, 09 Apr 2008) Log Message: ----------- * In Editor_Main_Menu_New_Map: set default map size to size of current map instead of 64x64. * In Surface::Surface(Surface const &): initialize m_offsx and m_offsy and call SDL_DisplayFormatAlpha instead of SDL_DisplayFormat. * Implement Graphic::create_grayed_out_pic(uint32_t) and use it to create a grayed out version of button images and empty ware slots. Modified Paths: -------------- trunk/src/building_ui.cc trunk/src/editor/ui_menus/editor_main_menu_new_map.cc trunk/src/graphic.cc trunk/src/graphic.h trunk/src/render.cc trunk/src/ui/ui_basic/ui_button.cc Modified: trunk/src/building_ui.cc =================================================================== --- trunk/src/building_ui.cc 2008-04-09 12:46:44 UTC (rev 3171) +++ trunk/src/building_ui.cc 2008-04-09 20:54:46 UTC (rev 3172) @@ -277,20 +277,11 @@ This passive class displays the status of a WaresQueue. It updates itself automatically through think(). */ -class WaresQueueDisplay : public UI::Panel { -public: +struct WaresQueueDisplay : public UI::Panel { enum { CellWidth = WARE_MENU_PIC_WIDTH, - CellHeight = WARE_MENU_PIC_HEIGHT, Border = 4, - - Height = CellHeight + 2 * Border, - - BG_LeftBorderX = 0, - BG_CellX = BG_LeftBorderX + Border, - BG_RightBorderX = BG_CellX + CellWidth, - BG_ContinueCellX = BG_RightBorderX + Border, - BG_ContinueBorderX = BG_ContinueCellX + CellWidth, + Height = WARE_MENU_PIC_HEIGHT + 2 * Border, }; public: @@ -307,7 +298,6 @@ Widelands::WaresQueue * m_queue; uint32_t m_max_width; uint32_t m_icon; //< Index to ware's picture - uint32_t m_fade_mask; //< Mask to show faded version of icons uint32_t m_pic_background; uint32_t m_cache_size; @@ -341,13 +331,8 @@ set_tooltip(ware.descname().c_str()); m_icon = ware.get_icon(); + m_pic_background = g_gr->create_grayed_out_pic(m_icon); - // Prepare a fadeout mask for undelivered wares - Surface *s = new Surface(*g_gr->get_picture_surface(m_pic_background)); - - SDL_SetAlpha(s->get_sdl_surface(), SDL_SRCALPHA, 175); - m_fade_mask = g_gr->get_picture(PicMod_Game, *s); - recalc_size(); set_think(true); @@ -359,7 +344,9 @@ Cleanup =============== */ -WaresQueueDisplay::~WaresQueueDisplay() {} +WaresQueueDisplay::~WaresQueueDisplay() { + g_gr->free_surface(m_pic_background); +} /* @@ -408,62 +395,18 @@ */ void WaresQueueDisplay::draw(RenderTarget* dst) { - int32_t x; - if (!m_display_size) return; m_cache_filled = m_queue->get_filled(); - // Draw it - compile_assert(0 <= BG_LeftBorderX); - dst->blitrect - (Point(0, 0), - m_pic_background, - Rect(Point(BG_LeftBorderX, 0), Border, Height)); - - x = Border; - - compile_assert(0 <= BG_ContinueCellX); - compile_assert(0 <= BG_CellX); - for (uint32_t cells = 0; cells < m_display_size; ++cells, x += CellWidth) { - dst->blitrect - (Point(x, 0), - m_pic_background, - Rect - (Point - (cells + 1 == m_display_size and m_cache_size > m_display_size - ? BG_ContinueCellX : BG_CellX, - 0), - CellWidth, Height)); - - // Fill ware queue with ware's icon - dst->blit(Point(x, Border), m_icon); - - // If ware is undelivered, gray it out. - if (cells >= m_cache_filled) - dst->blitrect - (Point(x, 0), m_fade_mask, - Rect - (Point - (cells + 1 == m_display_size and - m_cache_size > m_display_size - ? - BG_ContinueCellX : BG_CellX, - 0), - CellWidth, Height)); - } - - compile_assert(0 <= BG_RightBorderX); - dst->blitrect - (Point(x, 0), - m_pic_background, - Rect - (Point - (m_cache_size > m_display_size ? - BG_ContinueBorderX : BG_RightBorderX, - 0), - Border, Height)); + uint32_t nr_wares_to_draw = std::min(m_cache_filled, m_display_size); + uint32_t nr_empty_to_draw = m_display_size - nr_wares_to_draw; + Point point(Border, Border); + for (; nr_wares_to_draw; --nr_wares_to_draw, point.x += CellWidth) + dst->blit(point, m_icon); + for (; nr_empty_to_draw; --nr_empty_to_draw, point.x += CellWidth) + dst->blit(point, m_pic_background); } Modified: trunk/src/editor/ui_menus/editor_main_menu_new_map.cc =================================================================== --- trunk/src/editor/ui_menus/editor_main_menu_new_map.cc 2008-04-09 12:46:44 UTC (rev 3171) +++ trunk/src/editor/ui_menus/editor_main_menu_new_map.cc 2008-04-09 20:54:46 UTC (rev 3172) @@ -58,7 +58,11 @@ int32_t const height = 20; int32_t posx = offsx; int32_t posy = offsy; - m_w = 0; m_h = 0; + { + Widelands::Extent const map_extent = parent->egbase().map().extent(); + for (m_w = 0; Widelands::MAP_DIMENSIONS[m_w] < map_extent.w; ++m_w); + for (m_h = 0; Widelands::MAP_DIMENSIONS[m_h] < map_extent.h; ++m_h); + } snprintf (buffer, sizeof(buffer), _("Width: %u"), Widelands::MAP_DIMENSIONS[m_w]); m_width = Modified: trunk/src/graphic.cc =================================================================== --- trunk/src/graphic.cc 2008-04-09 12:46:44 UTC (rev 3171) +++ trunk/src/graphic.cc 2008-04-09 20:54:46 UTC (rev 3172) @@ -542,6 +542,27 @@ pic.module = 0; } + +uint32_t Graphic::create_grayed_out_pic(uint32_t const picid) { + if (picid) { + Surface & s = + *new Surface(*get_picture_surface(picid)); + SDL_PixelFormat const & format = s.format(); + uint32_t const w = s.get_w(), h = s.get_h(); + for (uint32_t y = 0; y < h; ++y) + for (uint32_t x = 0; x < w; ++x) { + uint8_t r, g, b, a; + SDL_GetRGBA(s.get_pixel(x, y), &const_cast<SDL_PixelFormat &>(format), &r, &g, &b, &a); // FIXME need for const_cast is SDL bug #421 + uint8_t const gray = + static_cast<uint8_t>(.30 * r + .59 * g + .11 * b); + s.set_pixel(x, y, SDL_MapRGBA(&format, gray, gray, gray, a)); + } + return get_picture(PicSurface, s); + } else + return 0; +} + + /** * Returns the RenderTarget for the given surface */ Modified: trunk/src/graphic.h =================================================================== --- trunk/src/graphic.h 2008-04-09 12:46:44 UTC (rev 3171) +++ trunk/src/graphic.h 2008-04-09 20:54:46 UTC (rev 3172) @@ -77,6 +77,7 @@ void save_png(uint32_t, StreamWrite *); uint32_t create_surface(int32_t w, int32_t h); void free_surface(uint32_t pic); + uint32_t create_grayed_out_pic(uint32_t const picid); RenderTarget* get_surface_renderer(uint32_t pic); enum ResizeMode { Modified: trunk/src/render.cc =================================================================== --- trunk/src/render.cc 2008-04-09 12:46:44 UTC (rev 3171) +++ trunk/src/render.cc 2008-04-09 20:54:46 UTC (rev 3172) @@ -47,12 +47,16 @@ /* * Create a Surface from a surface */ -Surface::Surface(const Surface& surf) { - m_w = surf.m_w; - m_h = surf.m_h; - m_surface = SDL_DisplayFormat(surf.m_surface); // HACK: assume this should be picture format; there is no SDL_CopySurface -} +Surface::Surface(Surface const & other) +: +// HACK: assume this should be picture format; there is no SDL_CopySurface +m_surface(SDL_DisplayFormatAlpha(other.m_surface)), + +m_offsx(other.m_offsx), m_offsy(other.m_offsx), m_w(other.m_w), m_h(other.m_h) +{} + + /* * Updating the whole Surface */ Modified: trunk/src/ui/ui_basic/ui_button.cc =================================================================== --- trunk/src/ui/ui_basic/ui_button.cc 2008-04-09 12:46:44 UTC (rev 3171) +++ trunk/src/ui/ui_basic/ui_button.cc 2008-04-09 20:54:46 UTC (rev 3172) @@ -26,17 +26,6 @@ namespace UI { -static uint32_t create_grayed_out_pic(uint32_t const picid) { - if (picid) { - Surface & s = - *new Surface(*g_gr->get_picture_surface(picid)); - SDL_SetAlpha(s.get_sdl_surface(), SDL_SRCALPHA, 175); - return g_gr->get_picture(PicSurface, s); - } else - return 0; -} - - /** * Initialize a Basic_Button */ @@ -57,7 +46,7 @@ m_title (title_text), m_pic_background(background_picture_id), m_pic_custom (foreground_picture_id), - m_pic_custom_disabled(create_grayed_out_pic(foreground_picture_id)), + m_pic_custom_disabled(g_gr->create_grayed_out_pic(foreground_picture_id)), m_clr_down (229, 161, 2), m_draw_caret (false) { @@ -95,7 +84,7 @@ m_pic_custom = picid; if (m_pic_custom_disabled) g_gr->free_surface(m_pic_custom_disabled); - m_pic_custom_disabled = create_grayed_out_pic(picid); + m_pic_custom_disabled = g_gr->create_grayed_out_pic(picid); update(0, 0, get_w(), get_h()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |