File diff r28029:39d90f4d66b8 → r28030:99c289b7c6ba
src/toolbar_gui.cpp
Show inline comments
 
@@ -1355,13 +1355,12 @@ static MenuClickedProc * const _menu_cli
 
	MenuClickNewspaper,   // 28
 
	MenuClickHelp,        // 29
 
};
 

	
 
/** Full blown container to make it behave exactly as we want :) */
 
class NWidgetToolbarContainer : public NWidgetContainer {
 
	bool visible[WID_TN_END]; ///< The visible headers
 
protected:
 
	uint spacers;          ///< Number of spacer widgets in this toolbar
 

	
 
public:
 
	NWidgetToolbarContainer() : NWidgetContainer(NWID_HORIZONTAL)
 
	{
 
@@ -1417,22 +1416,19 @@ public:
 
		this->pos_x = x;
 
		this->pos_y = y;
 
		this->current_x = given_width;
 
		this->current_y = given_height;
 

	
 
		/* Figure out what are the visible buttons */
 
		memset(this->visible, 0, sizeof(this->visible));
 
		uint arrangable_count, button_count, spacer_count;
 
		const byte *arrangement = GetButtonArrangement(given_width, arrangable_count, button_count, spacer_count);
 
		for (uint i = 0; i < arrangable_count; i++) {
 
			this->visible[arrangement[i]] = true;
 
		}
 

	
 
		/* Create us ourselves a quick lookup table */
 
		NWidgetBase *widgets[WID_TN_END];
 
		for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
			child_wid->current_x = 0; /* Hide widget, it will be revealed in the next step. */
 
			if (child_wid->type == NWID_SPACER) continue;
 
			widgets[((NWidgetCore*)child_wid)->index] = child_wid;
 
		}
 

	
 
		/* Now assign the widgets to their rightful place */
 
		uint position = 0; // Place to put next child relative to origin of the container.
 
@@ -1458,12 +1454,14 @@ public:
 

	
 
			/* Buttons can be scaled, the others not. */
 
			if (this->IsButton(child_wid->type)) {
 
				child_wid->current_x = button_space / (button_count - button_i);
 
				button_space -= child_wid->current_x;
 
				button_i++;
 
			} else {
 
				child_wid->current_x = child_wid->smallest_x;
 
			}
 
			child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
 
			position += child_wid->current_x;
 

	
 
			if (rtl) {
 
				cur_wid--;
 
@@ -1478,27 +1476,21 @@ public:
 
		/* Draw brown-red toolbar bg. */
 
		GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, PC_VERY_DARK_RED);
 
		GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, PC_DARK_RED, FILLRECT_CHECKER);
 

	
 
		bool rtl = _current_text_dir == TD_RTL;
 
		for (NWidgetBase *child_wid = rtl ? this->tail : this->head; child_wid != nullptr; child_wid = rtl ? child_wid->prev : child_wid->next) {
 
			if (child_wid->type == NWID_SPACER) continue;
 
			if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
 

	
 
			child_wid->Draw(w);
 
		}
 
	}
 

	
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override
 
	{
 
		if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
 

	
 
		for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
			if (child_wid->type == NWID_SPACER) continue;
 
			if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
 

	
 
			NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
 
			if (nwid != nullptr) return nwid;
 
		}
 
		return nullptr;
 
	}