Commit 2fdd7eb9 authored by twanvl's avatar twanvl

Various tweaks and fixes, mostly to the drop down lists

parent 872d1463
......@@ -442,11 +442,13 @@ init script:
cmc := to_text + {
1 * number_of_items(in: sort_text(order:"SWUBRG")) # colored mana
- 1 * number_of_items(in: sort_text(order:"/")) # guild mana, W/U -> 2 - 1
+ 1 * sort_text(order: "[0123456789]") # colorless mana
+ 1 * filter_text(match: "^[0123456789]+(?!/)") # colorless mana, but not 1/2
+ 1 * (length(sort_text(order:"compound(1/2)")) / 3) # compensate for 1/2. Should actually be 1.5 *
}
colored_mana := to_text + {
number_of_items(in: sort_text(order: "WUBRG")) # colored mana
- number_of_items(in: sort_text(order:"/")) # guild mana, W/U -> 2 - 1
+ 1 * (length(sort_text(order:"compound(1/2)")) / 3) # compensate for 1/2.
}
primary_card_color := {
artifact := chosen(choice:"artifact")
......@@ -1232,14 +1234,18 @@ statistics category:
word list:
name: type
word:
name: Basic
name: Basic
is prefix: true
word:
name: Legendary
line below: true
name: Legendary
is prefix: true
word:
name: Tribal
is prefix: true
line below: true
word: Creature
word: Artifact
word: Artifact Creature
word: Enchantment
word: Instant
word: Sorcery
......@@ -1256,11 +1262,15 @@ word list:
word list:
name: artifact
word:
name:
line below: true
word: Equipment
word list:
name: land
word:
name:
line below: true
word: Plains
word: Island
word: Swamp
......@@ -1270,11 +1280,15 @@ word list:
word list:
name: enchantment
word:
name:
line below: true
word: Aura
word list:
name: spell
word:
name:
line below: true
word: Arcane
......@@ -1455,6 +1469,9 @@ keyword parameter type:
# match: [A-Z][a-z, ]*([A-Z][a-z, ]*\xEB00) # commented out because it stopped prefix param from working, version below allows all "walks", including "Dame Judi Denchwalk", doesn't trigger #in middle of sentences, and doesn't trigger in chains of keywords.
match: [A-Z][A-Z,a-z ]*
example: Forest
keyword parameter type:
name: a
match: an?
############################# All Magic keywords
# By JrEye and Neko_Asakami, Updated by Pichoro and Buttock1234
......@@ -1872,3 +1889,8 @@ keyword:
match: Grandeur
mode: pseudo
rules: Grandeur — Discard another card named ~: [effect].
keyword:
keyword: Champion
match: Champion <atom-param>a</atom-param> <atom-param>name</atom-param>
mode: core
reminder: When this comes into play, sacrifice it unless you remove another {param2} you control from the game. When this leaves play, that card returns to play.
......@@ -6,6 +6,8 @@ A word in a [[type:word list]].
! Property Type Default Description
| @name@ [[type:string]] ''Required'' The word
| @line below@ [[type:boolean]] @false@ Display a line below this item in the list?
| @is prefix@ [[type:boolean]] @false@ Should this word be used as a prefix before another word from the list?<br/>
Think "Legendary ". Note the space after it, words are directly concatenated.
| @words@ [[type:list]] of [[type:word list word]]s A submenu
A word can also be given in a short form, in that case only the name is specified.
......
......@@ -81,18 +81,22 @@ void set_alpha(Image& img, const Image& img_alpha) {
}
if (!img.HasAlpha()) img.InitAlpha();
Byte *im = img.GetAlpha(), *al = img_alpha.GetData();
UInt size = img.GetWidth() * img.GetHeight();
for (UInt i = 0 ; i < size ; ++i) {
size_t size = img.GetWidth() * img.GetHeight();
for (size_t i = 0 ; i < size ; ++i) {
im[i] = (im[i] * al[i*3]) / 255;
}
}
void set_alpha(Image& img, double alpha) {
if (!img.HasAlpha()) img.InitAlpha();
Byte b_alpha = alpha * 255;
Byte *im = img.GetAlpha();
UInt size = img.GetWidth() * img.GetHeight();
for (UInt i = 0 ; i < size ; ++i) {
im[i] = (im[i] * b_alpha) / 255;
if (!img.HasAlpha()) {
img.InitAlpha();
memset(img.GetAlpha(), b_alpha, img.GetWidth() * img.GetHeight());
} else {
Byte *im = img.GetAlpha();
size_t size = img.GetWidth() * img.GetHeight();
for (size_t i = 0 ; i < size ; ++i) {
im[i] = (im[i] * b_alpha) / 255;
}
}
}
......@@ -98,21 +98,30 @@ bool CardViewer::shouldDraw(const ValueViewer& v) const {
}
// helper class for overdrawDC()
class CardViewer::OverdrawDC : private wxClientDC, public wxBufferedDC {
public:
OverdrawDC(CardViewer* window)
class CardViewer::OverdrawDC_aux : private wxClientDC {
protected:
wxBufferedDC bufferedDC;
OverdrawDC_aux(CardViewer* window)
: wxClientDC(window)
{
wxBufferedDC::Init((wxClientDC*)this, window->buffer);
bufferedDC.Init((wxClientDC*)this, window->buffer);
}
};
class CardViewer::OverdrawDC : private OverdrawDC_aux, public RotatedDC {
public:
OverdrawDC(CardViewer* window)
: OverdrawDC_aux(window)
, RotatedDC(bufferedDC, window->getRotation(), QUALITY_LOW)
{}
};
shared_ptr<DC> CardViewer::overdrawDC() {
shared_ptr<RotatedDC> CardViewer::overdrawDC() {
#ifdef _DEBUG
// don't call from onPaint
assert(!inOnPaint());
#endif
return shared_ptr<DC>((wxBufferedDC*)new OverdrawDC(this));
return shared_ptr<RotatedDC>(new OverdrawDC(this));
}
Rotation CardViewer::getRotation() const {
......
......@@ -28,7 +28,7 @@ class CardViewer : public wxControl, public DataViewer {
/// Get a dc to draw on the card outside onPaint
/** May NOT be called while in onPaint/draw */
shared_ptr<DC> overdrawDC();
shared_ptr<RotatedDC> overdrawDC();
/// Invalidate and redraw the entire viewer
void redraw();
......@@ -59,6 +59,7 @@ class CardViewer : public wxControl, public DataViewer {
bool up_to_date; ///< Is the buffer up to date?
class OverdrawDC;
class OverdrawDC_aux;
};
// ----------------------------------------------------------------------------- : EOF
......
......@@ -87,16 +87,16 @@ GraphData::GraphData(const GraphDataPre& d)
left--;
}
}
// drop empty tail
while (a->groups.size() > 1 && a->groups.back().size == 0) {
a->groups.pop_back();
}
// Also keep non-numeric entries
FOR_EACH(c, counts) {
a->groups.push_back(GraphGroup(c.first, c.second));
a->max = max(a->max, c.second);
a->total += c.second;
}
// drop empty tail
while (a->groups.size() > 1 && a->groups.back().size == 0) {
a->groups.pop_back();
}
} else if (a->order) {
// specific group order
FOR_EACH_CONST(gn, *a->order) {
......
......@@ -138,7 +138,7 @@ void DropDownList::show(bool in_place, wxPoint pos, RealRect* rect) {
if (selected_item == NO_SELECTION && itemCount() > 0) selected_item = 0; // select first item by default
mouse_down = false;
Window::Show();
if (!parent_menu && GetParent()->HasCapture()) {
if (isRoot() && GetParent()->HasCapture()) {
// release capture on parent
GetParent()->ReleaseMouse();
}
......@@ -168,7 +168,7 @@ void DropDownList::hide(bool event, bool allow_veto) {
void DropDownList::realHide() {
if (!IsShown()) return;
Window::Hide();
// onHide();
onHide();
hideSubMenu();
if (parent_menu) {
parent_menu->open_sub_menu = nullptr;
......@@ -226,7 +226,12 @@ int DropDownList::itemPosition(size_t item) const {
void DropDownList::redrawArrowOnParent() {
if (viewer) {
ValueEditor* e = viewer->getEditor();
if (e) e->redraw();
if (e && viewer->viewer.nativeLook()) {
CardEditor& editor = static_cast<CardEditor&>(viewer->viewer);
shared_ptr<RotatedDC> dcP = editor.overdrawDC();
RotatedDC& dc = *dcP;
draw_drop_down_arrow(&editor, dc.getDC(), dc.tr(viewer->getStyle()->getRect().grow(1)), IsShown());
}
}
}
......
......@@ -45,6 +45,10 @@ class DropDownList : public wxPopupWindow {
/// Prepare for showing the list
virtual void onShow() {}
/// Do something after hiding the list
virtual void onHide() {}
inline bool isRoot() { return parent_menu == nullptr; }
// --------------------------------------------------- : Selection
static const size_t NO_SELECTION = (size_t)-1;
......@@ -98,9 +102,7 @@ class DropDownList : public wxPopupWindow {
void onPaint(wxPaintEvent&);
void onLeftDown(wxMouseEvent&);
void onLeftUp (wxMouseEvent&);
protected:
virtual void onMotion(wxMouseEvent&); // allow override
private:
void onMotion(wxMouseEvent&);
// --------------------------------------------------- : Privates
......@@ -115,7 +117,8 @@ class DropDownList : public wxPopupWindow {
void draw(DC& dc);
void drawItem(DC& dc, int y, size_t item);
void redrawArrowOnParent();
protected:
virtual void redrawArrowOnParent(); // allow override
};
// ----------------------------------------------------------------------------- : EOF
......
This diff is collapsed.
......@@ -111,6 +111,9 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
/** t specifies what kind of position new_end is */
void moveSelectionNoRedraw(IndexType t, size_t new_end, bool also_move_start=true, Movement dir = MOVE_MID);
/// Redraw the selection
void redrawSelection(size_t old_selection_start_i, size_t old_selection_end_i, bool old_drop_down_shown);
/// Replace the current selection with 'replacement', name the action
/** replacement should be a tagged string (i.e. already escaped) */
void replaceSelection(const String& replacement, const String& name);
......
......@@ -12,6 +12,7 @@
// ----------------------------------------------------------------------------- : SymbolTextElement
void SymbolTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const {
if (!(what & DRAW_NORMAL)) return;
if (font.font) {
font.font->draw(dc, ctx, rect, font.size * scale, font.alignment, content.substr(start - this->start, end-start));
}
......
......@@ -40,9 +40,9 @@ struct TextViewer::Line {
return top + line_height > 0 && top < rot.getInternalSize().height;
}
/// Draws a selection indicator on this line from start to end
/// Get a rectangle of the selection on this line
/** start and end need not be in this line */
void drawSelection(RotatedDC& dc, size_t start, size_t end);
RealRect selectionRectangle(const Rotation& rot, size_t start, size_t end);
};
size_t TextViewer::Line::posToIndex(double x) const {
......@@ -89,6 +89,13 @@ void TextViewer::draw(RotatedDC& dc, const TextStyle& style, DrawWhat what) {
}
}
/// Intersection between two rectangles
RealRect intersect(const RealRect& a, const RealRect& b) {
RealPoint tl = piecewise_max(a.topLeft(), b.topLeft());
RealPoint br = piecewise_min(a.bottomRight(), b.bottomRight());
return RealRect(tl, RealSize(br - tl));
}
void TextViewer::drawSelection(RotatedDC& dc, const TextStyle& style, size_t sel_start, size_t sel_end) {
Rotater r(dc, style.getRotation());
if (sel_start == sel_end) return;
......@@ -96,18 +103,25 @@ void TextViewer::drawSelection(RotatedDC& dc, const TextStyle& style, size_t sel
dc.SetBrush(*wxBLACK_BRUSH);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetLogicalFunction(wxINVERT);
RealRect prev_rect(0,0,0,0);
FOR_EACH(l, lines) {
l.drawSelection(dc, sel_start, sel_end);
RealRect rect = l.selectionRectangle(dc, sel_start, sel_end);
if (rect.height > 0) dc.DrawRectangle(rect);
// compensate for overlap between lines
RealRect overlap = intersect(rect, prev_rect);
if (overlap.height > 0 && overlap.width > 0) dc.DrawRectangle(overlap);
prev_rect = rect;
}
dc.SetLogicalFunction(wxCOPY);
}
void TextViewer::Line::drawSelection(RotatedDC& dc, size_t sel_start, size_t sel_end) {
if (!visible(dc)) return;
if (sel_start < end() && sel_end > start) {
RealRect TextViewer::Line::selectionRectangle(const Rotation& rot, size_t sel_start, size_t sel_end) {
if (visible(rot) && sel_start < end() && sel_end > start) {
double x1 = positions[max(start, sel_start) - start];
double x2 = positions[min(end(), sel_end) - start];
dc.DrawRectangle(RealRect(x1, top, x2 - x1, line_height));
return RealRect(x1, top, x2 - x1, line_height);
} else {
return RealRect(0,0,0,0);
}
}
......
......@@ -37,7 +37,7 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
} else {
img_options.width = (int) dc.trX(style().width);
img_options.height = (int) dc.trY(style().height);
img_options.preserve_aspect = style().alignment == ALIGN_STRETCH ? ASPECT_STRETCH : ASPECT_FIT;
img_options.preserve_aspect = (style().alignment & ALIGN_STRETCH) ? ASPECT_STRETCH : ASPECT_FIT;
}
Image image = img.generate(img_options, true);
ImageCombine combine = img.combine();
......
......@@ -70,8 +70,8 @@ void ColorValueViewer::draw(RotatedDC& dc) {
bool ColorValueViewer::containsPoint(const RealPoint& p) const {
// distance to each side
double left = p.x - style().left, right = style().left + style().width - p.x - 1;
double top = p.y - style().top, bottom = style().top + style().height - p.y - 1;
double left = p.x - style().left, right = style().right - p.x - 1;
double top = p.y - style().top, bottom = style().bottom - p.y - 1;
if (left < 0 || right < 0 || top < 0 || bottom < 0 || // outside bounding box
(left >= style().left_width && right >= style().right_width && // outside horizontal border
top >= style().top_width && bottom >= style().bottom_width)) { // outside vertical border
......
......@@ -29,10 +29,12 @@ void TextValueViewer::draw(RotatedDC& dc) {
if (!v.prepared()) {
v.prepare(dc, value().value(), style(), viewer.getContext());
}
if (viewer.drawFocus() && isCurrent()) {
v.draw(dc, style(), DRAW_ACTIVE);
}
v.draw(dc, style(), (DrawWhat)(
DRAW_NORMAL
| (viewer.drawBorders() ? DRAW_BORDERS : 0)
| (viewer.drawFocus() && isCurrent() ? DRAW_ACTIVE : 0)
));
}
......
......@@ -600,7 +600,7 @@ void init_script_basic_functions(Context& ctx) {
ctx.setVariable(_("tag remove rule"), script_tag_remove_rule);
// collection
ctx.setVariable(_("position"), script_position_of);
ctx.setVariable(_("length"), script_number_of_items);
ctx.setVariable(_("length"), script_length);
ctx.setVariable(_("number of items"), script_number_of_items);
ctx.setVariable(_("filter list"), script_filter_list);
ctx.setVariable(_("sort list"), script_sort_list);
......
......@@ -169,7 +169,8 @@ void mixed_sort(const String& spec, String& input, String& ret) {
/// Sort a string, find a compound item
/** Removed used characters from input! */
void compound_sort(const String& spec, String& input, String& ret) {
while (size_t pos = input.find(spec)) {
size_t pos = input.find(spec);
while (pos != String::npos) {
ret += spec;
for (size_t j = 0 ; j < spec.size() ; ++j) input.SetChar(pos + j, REMOVED);
pos = input.find(spec, pos + 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment