diff -r fdb4b5ab8099 src/newgrf_gui.cpp --- a/src/newgrf_gui.cpp Sun May 23 11:30:13 2010 +0200 +++ b/src/newgrf_gui.cpp Sun May 23 13:10:45 2010 +0200 @@ -187,6 +187,7 @@ bool execute; ///< On pressing 'apply changes' are grf changes applied immediately, or only list is updated. int query_widget; ///< Widget that opened the last query. int preset; ///< Selected preset. + int active_over; ///< Active GRF item over which another one is dragged, \c -1 if none NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool execute, GRFConfig **orig_list) : QueryStringBaseWindow(EDITBOX_MAX_SIZE) { @@ -199,6 +200,7 @@ this->execute = execute; this->show_params = show_params; this->preset = -1; + this->active_over = -1; CopyGRFConfigList(&this->actives, *orig_list, false); GetGRFPresetList(&_grf_preset_list); @@ -361,6 +363,12 @@ PaletteID pal = this->GetPalette(c); if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, 156); + if (!h && i == this->active_over) { // Higlight the destination of the dragged NewGRF file. + uint active_sel_pos = 0; + for (GRFConfig *c = this->actives; c != NULL && c != this->active_sel; c = c->next, active_sel_pos++) {} + uint top = (((uint) this->active_over) < active_sel_pos ? y + 1 : y + step_height - 2); + GfxFillRect(r.left + WD_FRAMERECT_LEFT, top - 1, r.right - WD_FRAMERECT_RIGHT, top + 1, 156); + } DrawSprite(SPR_SQUARE, pal, square_left, y + sprite_offset_y); if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, warning_left, y + sprite_offset_y); uint txtoffset = c->error == NULL ? 0 : 10; @@ -691,6 +699,33 @@ } ResetObjectToPlace(); + + if (this->active_over != -1) { + /* End of drag-and-drop, hide dragged destination highlight. */ + this->active_over = -1; + this->SetWidgetDirty(SNGRFS_FILE_LIST); + } + } + + virtual void OnMouseDrag(Point pt, int widget) + { + if (this->active_sel != NULL && widget == SNGRFS_FILE_LIST) { + /* An active NewGRF file is dragged… */ + NWidgetBase *nw = this->GetWidget(widget); + uint active_to = (pt.y - nw->pos_y) / nw->resize_y + this->vscroll.GetPosition(); + + uint active_sel_pos = 0; + for (GRFConfig *c = this->actives; c != NULL && c != this->active_sel; c = c->next, active_sel_pos++) {} + + if (active_to >= this->vscroll.GetPosition() && + active_to < (uint) min(this->vscroll.GetPosition() + this->vscroll.GetCapacity(), this->vscroll.GetCount())) { // …over an existing NewGRF file. + this->active_over = active_to; + this->SetWidgetDirty(widget); + } else if (active_to != active_sel_pos && this->active_over != -1) { // …outside of the NewGRF file list. + this->active_over = -1; + this->SetWidgetDirty(widget); + } + } } virtual void OnDropdownSelect(int widget, int index)