From 27bf9549d60798d4324bd9b0e68a5d91f0658099 Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 13 Nov 2013 21:39:14 +0000 Subject: [PATCH] (svn r25983) [1.3] -Backport from trunk: - Fix: NWidgetMatrix used pip_pre and pip_post inconsistently and incorrectly, causing misalignment for RTL [FS#5686] (r25727) - Fix: Right side of object class string was misaligned (r25726) - Fix: [OSX] Do not pass -mmacosx-version-min to compilers that do not support it (r25706) - Fix: Autoreplace/renew also refits free wagons [FS#5700] (r25698) --- config.lib | 2 +- src/object_gui.cpp | 2 +- src/train_cmd.cpp | 2 +- src/vehicle_cmd.cpp | 9 ++++++--- src/widget.cpp | 37 +++++++++++++++++++------------------ src/widget_type.h | 4 ++-- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/config.lib b/config.lib index a2f19113dd..93c03a568c 100644 --- a/config.lib +++ b/config.lib @@ -1558,7 +1558,7 @@ make_cflags_and_ldflags() { LDFLAGS="$OSX_LD_SYSROOT $LDFLAGS" fi - if [ "$enable_universal" = "0" ] && [ $cc_version -ge 40 ]; then + if [ "$enable_universal" = "0" ] && [ $cc_version -gt 40 ]; then # Only set the min version when not doing an universal build. # Universal builds set the version elsewhere. if [ "$cpu_type" = "64" ]; then diff --git a/src/object_gui.cpp b/src/object_gui.cpp index a5e065cbd0..59cee1b66c 100644 --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -176,7 +176,7 @@ public: if (objclass->GetUISpecCount() == 0) continue; if (!this->vscroll->IsVisible(pos++)) continue; SetDParam(0, objclass->name); - DrawString(r.left + WD_MATRIX_LEFT, r.right + WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, STR_JUST_STRING, + DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, STR_JUST_STRING, ((int)i == _selected_object_class) ? TC_WHITE : TC_BLACK); y += this->line_height; } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 650e52d41a..3daea33a22 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -419,7 +419,7 @@ int Train::GetCurrentMaxSpeed() const /** Update acceleration of the train from the cached power and weight. */ void Train::UpdateAcceleration() { - assert(this->IsFrontEngine()); + assert(this->IsFrontEngine() || this->IsFreeWagon()); uint power = this->gcache.cached_power; uint weight = this->gcache.cached_weight; diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 7271d27b03..e47180fb2a 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -434,11 +434,12 @@ CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint if (ret.Failed()) return ret; bool auto_refit = HasBit(p2, 6); + bool free_wagon = v->type == VEH_TRAIN && Train::From(front)->IsFreeWagon(); // used by autoreplace/renew /* Don't allow shadows and such to be refitted. */ if (v != front && (v->type == VEH_SHIP || v->type == VEH_AIRCRAFT)) return CMD_ERROR; /* Allow auto-refitting only during loading and normal refitting only in a depot. */ - if ((!auto_refit || !front->current_order.IsType(OT_LOADING)) && !front->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type); + if (!free_wagon && (!auto_refit || !front->current_order.IsType(OT_LOADING)) && !front->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type); if (front->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED); /* Check cargo */ @@ -478,9 +479,11 @@ CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint default: NOT_REACHED(); } - InvalidateWindowData(WC_VEHICLE_DETAILS, front->index); + if (!free_wagon) { + InvalidateWindowData(WC_VEHICLE_DETAILS, front->index); + InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); + } SetWindowDirty(WC_VEHICLE_DEPOT, front->tile); - InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); } else { /* Always invalidate the cache; querycost might have filled it. */ v->InvalidateNewGRFCacheOfChain(); diff --git a/src/widget.cpp b/src/widget.cpp index 17644fe538..ed8921818e 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1553,24 +1553,25 @@ NWidgetCore *NWidgetMatrix::GetWidgetFromPos(int x, int y) int start_x, start_y, base_offs_x, base_offs_y; this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y); - /* Swap the x offset around for RTL, so it'll behave like LTR for RTL as well. */ bool rtl = _current_text_dir == TD_RTL; - if (rtl) base_offs_x -= (this->widgets_x - 1) * this->widget_w; - int widget_col = (x - base_offs_x - (int)this->pip_pre - (int)this->pos_x) / this->widget_w; + int widget_col = (rtl ? + -x + (int)this->pip_post + (int)this->pos_x + base_offs_x + (int)this->widget_w - 1 - (int)this->pip_inter : + x - (int)this->pip_pre - (int)this->pos_x - base_offs_x + ) / this->widget_w; + int widget_row = (y - base_offs_y - (int)this->pip_pre - (int)this->pos_y) / this->widget_h; - if (widget_row * this->widgets_x + widget_col >= this->count) return NULL; + int sub_wid = (widget_row + start_y) * this->widgets_x + start_x + widget_col; + if (sub_wid >= this->count) return NULL; NWidgetCore *child = dynamic_cast(this->head); child->AssignSizePosition(ST_RESIZE, - this->pos_x + this->pip_pre + widget_col * this->widget_w + base_offs_x, + this->pos_x + (rtl ? this->pip_post - widget_col * this->widget_w : this->pip_pre + widget_col * this->widget_w) + base_offs_x, this->pos_y + this->pip_pre + widget_row * this->widget_h + base_offs_y, child->smallest_x, child->smallest_y, rtl); - /* "Undo" the RTL swap here to get the right widget index. */ - if (rtl) widget_col = this->widgets_x - widget_col - 1; - SB(child->index, 16, 16, (widget_row + start_y) * this->widgets_x + widget_col + start_x); + SB(child->index, 16, 16, sub_wid); return child->GetWidgetFromPos(x, y); } @@ -1581,14 +1582,14 @@ NWidgetCore *NWidgetMatrix::GetWidgetFromPos(int x, int y) GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, _colour_gradient[this->colour & 0xF][5]); /* Set up a clipping area for the previews. */ + bool rtl = _current_text_dir == TD_RTL; DrawPixelInfo tmp_dpi; - if (!FillDrawPixelInfo(&tmp_dpi, this->pos_x + this->pip_pre, this->pos_y + this->pip_pre, this->current_x - this->pip_pre - this->pip_post, this->current_y - this->pip_pre - this->pip_post)) return; + if (!FillDrawPixelInfo(&tmp_dpi, this->pos_x + (rtl ? this->pip_post : this->pip_pre), this->pos_y + this->pip_pre, this->current_x - this->pip_pre - this->pip_post, this->current_y - this->pip_pre - this->pip_post)) return; DrawPixelInfo *old_dpi = _cur_dpi; _cur_dpi = &tmp_dpi; /* Get the appropriate offsets so we can draw the right widgets. */ NWidgetCore *child = dynamic_cast(this->head); - bool rtl = _current_text_dir == TD_RTL; int start_x, start_y, base_offs_x, base_offs_y; this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y); @@ -1624,28 +1625,28 @@ NWidgetCore *NWidgetMatrix::GetWidgetFromPos(int x, int y) /** * Get the different offsets that are influenced by scrolling. - * @param [out] start_x The start position in columns, + * @param [out] start_x The start position in columns (index of the left-most column, swapped in RTL). * @param [out] start_y The start position in rows. - * @param [out] base_offs_x The base horizontal offset in pixels. - * @param [out] base_offs_y The base vertical offset in pixels. + * @param [out] base_offs_x The base horizontal offset in pixels (X position of the column \a start_x). + * @param [out] base_offs_y The base vertical offset in pixels (Y position of the column \a start_y). */ void NWidgetMatrix::GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y) { - base_offs_x = 0; + base_offs_x = _current_text_dir == TD_RTL ? this->widget_w * (this->widgets_x - 1) : 0; base_offs_y = 0; start_x = 0; start_y = 0; if (this->sb != NULL) { if (this->sb->IsVertical()) { start_y = this->sb->GetPosition() / this->widget_h; - base_offs_y = -this->sb->GetPosition() + start_y * this->widget_h; - if (_current_text_dir == TD_RTL) base_offs_x = this->pip_pre + this->widget_w * (this->widgets_x - 1) - this->pip_inter; + base_offs_y += -this->sb->GetPosition() + start_y * this->widget_h; } else { start_x = this->sb->GetPosition() / this->widget_w; + int sub_x = this->sb->GetPosition() - start_x * this->widget_w; if (_current_text_dir == TD_RTL) { - base_offs_x = this->sb->GetCapacity() + this->sb->GetPosition() - (start_x + 1) * this->widget_w + this->pip_inter - this->pip_post - this->pip_pre; + base_offs_x += sub_x; } else { - base_offs_x = -this->sb->GetPosition() + start_x * this->widget_w; + base_offs_x -= sub_x; } } } diff --git a/src/widget_type.h b/src/widget_type.h index 1bd4f88fea..eed23f0089 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -179,9 +179,9 @@ public: NWidgetBase *prev; ///< Pointer to previous widget in container. Managed by parent container widget. uint8 padding_top; ///< Paddings added to the top of the widget. Managed by parent container widget. - uint8 padding_right; ///< Paddings added to the right of the widget. Managed by parent container widget. + uint8 padding_right; ///< Paddings added to the right of the widget. Managed by parent container widget. (parent container may swap this with padding_left for RTL) uint8 padding_bottom; ///< Paddings added to the bottom of the widget. Managed by parent container widget. - uint8 padding_left; ///< Paddings added to the left of the widget. Managed by parent container widget. + uint8 padding_left; ///< Paddings added to the left of the widget. Managed by parent container widget. (parent container may swap this with padding_right for RTL) protected: inline void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height);