Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop down list code cleanups #7357

Merged
merged 3 commits into from Mar 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/company_gui.cpp
Expand Up @@ -519,8 +519,6 @@ class DropDownListColourItem : public DropDownListItem {
public:
DropDownListColourItem(int result, bool masked) : DropDownListItem(result, masked) {}

virtual ~DropDownListColourItem() {}

StringID String() const
{
return this->result >= COLOUR_END ? STR_COLOUR_DEFAULT : _colour_dropdown[this->result];
Expand All @@ -536,7 +534,7 @@ class DropDownListColourItem : public DropDownListItem {
return true;
}

void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
{
bool rtl = _current_text_dir == TD_RTL;
int height = bottom - top;
Expand Down
20 changes: 1 addition & 19 deletions src/newgrf_gui.cpp
Expand Up @@ -567,24 +567,6 @@ void ShowNewGRFTextfileWindow(TextfileType file_type, const GRFConfig *c)

static GRFPresetList _grf_preset_list; ///< List of known NewGRF presets. @see GetGRFPresetList

class DropDownListPresetItem : public DropDownListItem {
public:
DropDownListPresetItem(int result) : DropDownListItem(result, false) {}

virtual ~DropDownListPresetItem() {}

bool Selectable() const
{
return true;
}

void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
{
DrawString(left + 2, right + 2, top, _grf_preset_list[this->result], sel ? TC_WHITE : TC_BLACK);
}
};


typedef std::map<uint32, const GRFConfig *> GrfIdMap; ///< Map of grfid to the grf config.

/**
Expand Down Expand Up @@ -949,7 +931,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {

for (uint i = 0; i < _grf_preset_list.Length(); i++) {
if (_grf_preset_list[i] != NULL) {
*list->Append() = new DropDownListPresetItem(i);
*list->Append() = new DropDownListCharStringItem(_grf_preset_list[i], i, false);
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/toolbar_gui.cpp
Expand Up @@ -97,14 +97,12 @@ class DropDownListCheckedItem : public DropDownListStringItem {
this->checkmark_width = GetStringBoundingBox(STR_JUST_CHECKMARK).width + 3;
}

virtual ~DropDownListCheckedItem() {}

uint Width() const
{
return DropDownListStringItem::Width() + this->checkmark_width;
}

void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
{
bool rtl = _current_text_dir == TD_RTL;
if (this->checked) {
Expand All @@ -129,8 +127,6 @@ class DropDownListCompanyItem : public DropDownListItem {
this->lock_size = GetSpriteSize(SPR_LOCK);
}

virtual ~DropDownListCompanyItem() {}

bool Selectable() const
{
return true;
Expand All @@ -149,7 +145,7 @@ class DropDownListCompanyItem : public DropDownListItem {
return max(max(this->icon_size.height, this->lock_size.height) + 2U, (uint)FONT_HEIGHT_NORMAL);
}

void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
{
CompanyID company = (CompanyID)this->result;
bool rtl = _current_text_dir == TD_RTL;
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/dropdown.cpp
Expand Up @@ -22,7 +22,7 @@
#include "../safeguards.h"


void DropDownListItem::Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
void DropDownListItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
{
int c1 = _colour_gradient[bg_colour][3];
int c2 = _colour_gradient[bg_colour][7];
Expand All @@ -39,7 +39,7 @@ uint DropDownListStringItem::Width() const
return GetStringBoundingBox(buffer).width;
}

void DropDownListStringItem::Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
void DropDownListStringItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
{
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, this->String(), sel ? TC_WHITE : TC_BLACK);
}
Expand Down
7 changes: 2 additions & 5 deletions src/widgets/dropdown_type.h
Expand Up @@ -32,7 +32,7 @@ class DropDownListItem {
virtual bool Selectable() const { return false; }
virtual uint Height(uint width) const { return FONT_HEIGHT_NORMAL; }
virtual uint Width() const { return 0; }
virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const;
virtual void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const;
};

/**
Expand All @@ -43,11 +43,10 @@ class DropDownListStringItem : public DropDownListItem {
StringID string; ///< String ID of item

DropDownListStringItem(StringID string, int result, bool masked) : DropDownListItem(result, masked), string(string) {}
virtual ~DropDownListStringItem() {}

virtual bool Selectable() const { return true; }
virtual uint Width() const;
virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const;
virtual void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const;
virtual StringID String() const { return this->string; }

static int CDECL NatSortFunc(const DropDownListItem * const *first, const DropDownListItem * const *second);
Expand All @@ -61,7 +60,6 @@ class DropDownListParamStringItem : public DropDownListStringItem {
uint64 decode_params[10]; ///< Parameters of the string

DropDownListParamStringItem(StringID string, int result, bool masked) : DropDownListStringItem(string, result, masked) {}
virtual ~DropDownListParamStringItem() {}

virtual StringID String() const;
virtual void SetParam(uint index, uint64 value) { decode_params[index] = value; }
Expand All @@ -75,7 +73,6 @@ class DropDownListCharStringItem : public DropDownListStringItem {
const char *raw_string;

DropDownListCharStringItem(const char *raw_string, int result, bool masked) : DropDownListStringItem(STR_JUST_RAW_STRING, result, masked), raw_string(raw_string) {}
virtual ~DropDownListCharStringItem() {}

virtual StringID String() const;
};
Expand Down