//+----------------------------------------------------------------------------+ //| Description: Magic Set Editor - Program to make card games | //| Copyright: (C) Twan van Laarhoven and the other MSE developers | //| License: GNU General Public License 2 or later (see file COPYING) | //+----------------------------------------------------------------------------+ // ----------------------------------------------------------------------------- : Includes #include #include #include #include // ----------------------------------------------------------------------------- : PackageChoiceValueViewer IMPLEMENT_VALUE_VIEWER(PackageChoice); struct PackageChoiceValueViewer::ComparePackagePosHint { bool operator () (const PackagedP& a, const PackagedP& b) { // use position_hints to determine order if (a->position_hint < b->position_hint) return true; if (a->position_hint > b->position_hint) return false; // ensure a deterministic order: use the names return a->name() < b->name(); } }; void PackageChoiceValueViewer::initItems() { vector choices; package_manager.findMatching(field().match, choices); sort(choices.begin(), choices.end(), ComparePackagePosHint()); FOR_EACH(p, choices) { Item i; i.package_name = p->relativeFilename(); i.name = capitalize_sentence(p->short_name); Image image; auto stream = p->openIconFile(); if (stream && image_load_file(image, *stream)) { i.image = Bitmap(resample(image, 16,16)); } items.push_back(i); } } void PackageChoiceValueViewer::draw(RotatedDC& dc) { drawFieldBorder(dc); // draw background if (nativeLook()) { dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(RealRect(0, 0, dc.getWidth(), dc.getHeight())); } // find item String text = value().package_name; Bitmap image; if (value().package_name.empty()) { text = field().empty_name; } else { FOR_EACH(i, items) { if (i.package_name == value().package_name) { text = i.name; image = i.image; } } } // draw image if (image.Ok()) { dc.DrawBitmap(image, RealPoint(0,0)); } // draw text FontRef& font = style().font; Color font_color = font.color; RealSize margin(0, 0); if (nativeLook()) { font.color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); margin = RealSize(1., 0); } dc.SetFont(font, 1.0); RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(17., 0) + margin; dc.DrawTextWithShadowOrStroke(text, font, pos); if (nativeLook()) font.color = font_color; }