|
@@ -12,51 +12,49 @@
|
|
|
#include "../string_func.h"
|
|
|
#include "../strings_func.h"
|
|
|
#include "../window_func.h"
|
|
|
#include "../guitimer_func.h"
|
|
|
#include "../zoom_func.h"
|
|
|
#include "dropdown_type.h"
|
|
|
|
|
|
#include "dropdown_widget.h"
|
|
|
|
|
|
#include "../safeguards.h"
|
|
|
|
|
|
|
|
|
void DropDownListItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
|
|
|
{
|
|
|
int c1 = _colour_gradient[bg_colour][3];
|
|
|
int c2 = _colour_gradient[bg_colour][7];
|
|
|
|
|
|
int mid = CenterBounds(r.top, r.bottom, 0);
|
|
|
GfxFillRect(r.left, mid - WidgetDimensions::scaled.bevel.bottom, r.right, mid - 1, c1);
|
|
|
GfxFillRect(r.left, mid, r.right, mid + WidgetDimensions::scaled.bevel.top - 1, c2);
|
|
|
}
|
|
|
|
|
|
uint DropDownListStringItem::Width() const
|
|
|
{
|
|
|
char buffer[512];
|
|
|
GetString(buffer, this->String(), lastof(buffer));
|
|
|
return GetStringBoundingBox(buffer).width + WidgetDimensions::scaled.dropdowntext.Horizontal();
|
|
|
return GetStringBoundingBox(this->String()).width + WidgetDimensions::scaled.dropdowntext.Horizontal();
|
|
|
}
|
|
|
|
|
|
void DropDownListStringItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
|
|
|
{
|
|
|
Rect ir = r.Shrink(WidgetDimensions::scaled.dropdowntext);
|
|
|
DrawString(ir.left, ir.right, r.top, this->String(), sel ? TC_WHITE : TC_BLACK);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Natural sorting comparator function for DropDownList::sort().
|
|
|
* @param first Left side of comparison.
|
|
|
* @param second Right side of comparison.
|
|
|
* @return true if \a first precedes \a second.
|
|
|
* @warning All items in the list need to be derivates of DropDownListStringItem.
|
|
|
*/
|
|
|
/* static */ bool DropDownListStringItem::NatSortFunc(std::unique_ptr<const DropDownListItem> const &first, std::unique_ptr<const DropDownListItem> const &second)
|
|
|
{
|
|
|
char buffer1[512], buffer2[512];
|
|
|
GetString(buffer1, static_cast<const DropDownListStringItem*>(first.get())->String(), lastof(buffer1));
|
|
|
GetString(buffer2, static_cast<const DropDownListStringItem*>(second.get())->String(), lastof(buffer2));
|
|
|
return strnatcmp(buffer1, buffer2) < 0;
|
|
|
}
|
|
|
|
|
|
StringID DropDownListParamStringItem::String() const
|