File diff r24596:eddf98238034 → r24597:afde5721a3b6
src/story_gui.cpp
Show inline comments
 
@@ -428,26 +428,26 @@ protected:
 

	
 
		/* Build layout */
 
		for (const StoryPageElement *pe : this->story_page_elements) {
 
			ElementFloat fl = this->GetPageElementFloat(*pe);
 

	
 
			if (fl == ElementFloat::None) {
 
				/* Verify available width */
 
				const int min_required_width = 10 * FONT_HEIGHT_NORMAL;
 
				int left_offset = (left_width == 0) ? 0 : (left_width + element_dist);
 
				int right_offset = (right_width == 0) ? 0 : (right_width + element_dist);
 
				if (left_offset + right_offset + min_required_width >= max_width) {
 
					/* Width of floats leave too little for main content, push down */
 
					main_y = max(main_y, left_y);
 
					main_y = max(main_y, right_y);
 
					main_y = std::max(main_y, left_y);
 
					main_y = std::max(main_y, right_y);
 
					left_width = right_width = 0;
 
					left_offset = right_offset = 0;
 
					/* Do not add element_dist here, to keep together elements which were supposed to float besides each other. */
 
				}
 
				/* Determine height */
 
				const int available_width = max_width - left_offset - right_offset;
 
				const int height = GetPageElementHeight(*pe, available_width);
 
				/* Check for button that needs extra margin */
 
				if (left_offset == 0 && right_offset == 0) {
 
					switch (pe->type) {
 
						case SPET_BUTTON_PUSH:
 
						case SPET_BUTTON_TILE:
 
@@ -460,34 +460,34 @@ protected:
 
				}
 
				/* Position element in main column */
 
				LayoutCacheElement ce{ pe, {} };
 
				ce.bounds.left = left_offset;
 
				ce.bounds.right = max_width - right_offset;
 
				ce.bounds.top = main_y;
 
				main_y += height;
 
				ce.bounds.bottom = main_y;
 
				this->layout_cache.push_back(ce);
 
				main_y += element_dist;
 
				/* Clear all floats */
 
				left_width = right_width = 0;
 
				left_y = right_y = main_y = max(main_y, max(left_y, right_y));
 
				left_y = right_y = main_y = std::max({main_y, left_y, right_y});
 
				left_floats.clear();
 
				right_floats.clear();
 
			} else {
 
				/* Prepare references to correct column */
 
				int &cur_width = (fl == ElementFloat::Left) ? left_width : right_width;
 
				int &cur_y = (fl == ElementFloat::Left) ? left_y : right_y;
 
				std::vector<size_t> &cur_floats = (fl == ElementFloat::Left) ? left_floats : right_floats;
 
				/* Position element */
 
				cur_width = max(cur_width, this->GetPageElementFloatWidth(*pe));
 
				cur_width = std::max(cur_width, this->GetPageElementFloatWidth(*pe));
 
				LayoutCacheElement ce{ pe, {} };
 
				ce.bounds.left = (fl == ElementFloat::Left) ? 0 : (max_width - cur_width);
 
				ce.bounds.right = (fl == ElementFloat::Left) ? cur_width : max_width;
 
				ce.bounds.top = cur_y;
 
				cur_y += GetPageElementHeight(*pe, cur_width);
 
				ce.bounds.bottom = cur_y;
 
				cur_floats.push_back(this->layout_cache.size());
 
				this->layout_cache.push_back(ce);
 
				cur_y += element_dist;
 
				/* Update floats in column to all have the same width */
 
				for (size_t index : cur_floats) {
 
					LayoutCacheElement &ce = this->layout_cache[index];
 
@@ -498,44 +498,44 @@ protected:
 
		}
 
	}
 

	
 
	/**
 
	 * Get the total height of the content displayed in this window.
 
	 * @return the height in pixels
 
	 */
 
	uint GetContentHeight()
 
	{
 
		this->EnsureStoryPageElementLayout();
 

	
 
		/* The largest bottom coordinate of any element is the height of the content */
 
		uint max_y = std::accumulate(this->layout_cache.begin(), this->layout_cache.end(), 0, [](uint max_y, const LayoutCacheElement &ce) -> uint { return max<uint>(max_y, ce.bounds.bottom); });
 
		uint max_y = std::accumulate(this->layout_cache.begin(), this->layout_cache.end(), 0, [](uint max_y, const LayoutCacheElement &ce) -> uint { return std::max<uint>(max_y, ce.bounds.bottom); });
 

	
 
		return max_y;
 
	}
 

	
 
	/**
 
	 * Draws a page element that is composed of a sprite to the left and a single line of
 
	 * text after that. These page elements are generally clickable and are thus called
 
	 * action elements.
 
	 * @param y_offset Current y_offset which will get updated when this method has completed its drawing.
 
	 * @param width Width of the region available for drawing.
 
	 * @param line_height Height of one line of text.
 
	 * @param action_sprite The sprite to draw.
 
	 * @param string_id The string id to draw.
 
	 * @return the number of lines.
 
	 */
 
	void DrawActionElement(int &y_offset, int width, int line_height, SpriteID action_sprite, StringID string_id = STR_JUST_RAW_STRING) const
 
	{
 
		Dimension sprite_dim = GetSpriteSize(action_sprite);
 
		uint element_height = max(sprite_dim.height, (uint)line_height);
 
		uint element_height = std::max(sprite_dim.height, (uint)line_height);
 

	
 
		uint sprite_top = y_offset + (element_height - sprite_dim.height) / 2;
 
		uint text_top = y_offset + (element_height - line_height) / 2;
 

	
 
		DrawSprite(action_sprite, PAL_NONE, 0, sprite_top);
 
		DrawString(sprite_dim.width + WD_FRAMETEXT_LEFT, width, text_top, string_id, TC_BLACK);
 

	
 
		y_offset += element_height;
 
	}
 

	
 
	/**
 
	 * Internal event handler for when a page element is clicked.