Commit 203282d0 authored by twanvl's avatar twanvl

Eliminated most build errors (gcc,linux,wxGTK).

What is left is mostly:
 - warning: converting double to int
     -> add a cast/to_int or ignore
 - wrong initialization order in ctor
     -> just swap the order to match the class
 - errors about wxCursors
     -> add a function loadResourceCursor
parent 8b272b15
......@@ -18,7 +18,7 @@ inline double sgn(double v) { return v > 0 ? 1 : -1; }
Vector2D constrainVector(const Vector2D& v, bool constrain, bool onlyDiagonal) {
if (!constrain) return v;
double ax = abs(v.x), ay = abs(v.y);
double ax = fabs(v.x), ay = fabs(v.y);
if (ax * 2 < ay && !onlyDiagonal) {
return Vector2D(0, v.y); // vertical
} else if(ay * 2 < ax && !onlyDiagonal) {
......
......@@ -11,6 +11,8 @@
#include <util/prec.hpp>
#include <util/reflect.hpp>
#include <util/error.hpp>
#include <data/field.hpp> // for Card::value
class Game;
class Dependency;
......
......@@ -35,7 +35,7 @@ class Font {
/// Update the scritables, returns true if there is a change
bool update(Context& ctx);
/// Add the given dependency to the dependent_scripts list for the variables this font depends on
virtual void initDependencies(Context&, const Dependency&) const;
void initDependencies(Context&, const Dependency&) const;
/// Does this font have a shadow?
inline bool hasShadow() { return shadow_displacement.width != 0 || shadow_displacement.height != 0; }
......
......@@ -38,7 +38,7 @@ void read_compat(Reader& tag, Keyword* k) {
KeywordExpansionP e(new KeywordExpansion);
size_t start = separator.find_first_of('[');
size_t end = separator.find_first_of(']');
if (start != String.npos && end != String.npos) {
if (start != String::npos && end != String::npos) {
e->after += separator.substr(start + 1, end - start - 1);
}
if (!parameter.empty()) {
......
......@@ -37,8 +37,8 @@ Set::Set(const GameP& game)
}
Set::Set(const StyleSheetP& stylesheet)
: stylesheet(stylesheet)
, game(stylesheet->game)
: game(stylesheet->game)
, stylesheet(stylesheet)
, script_manager(new SetScriptManager(*this))
{
data.init(game->set_fields);
......
......@@ -83,13 +83,13 @@ IMPLEMENT_REFLECTION(StyleSheetSettings) {
Settings settings;
Settings::Settings()
: set_window_maximized (false)
: locale (_("en"))
, set_window_maximized (false)
, set_window_width (790)
, set_window_height (300)
, card_notes_height (40)
, updates_url (_("http://magicseteditor.sourceforge.net/updates"))
, check_updates (CHECK_IF_CONNECTED)
, locale (_("en"))
, updates_url (_("http://magicseteditor.sourceforge.net/updates"))
{}
void Settings::addRecentFile(const String& filename) {
......
......@@ -26,12 +26,12 @@ class StatsDimension {
StatsDimension();
StatsDimension(const Field&);
bool automatic; ///< Based on a card field?
String name; ///< Name of this dimension
String description; ///< Description, used in status bar
String icon_filename; ///< Icon for lists
OptionalScript script; ///< Script that determines the value(s)
bool numeric; ///< Are the values numeric? If so, they require special sorting
bool automatic; ///< Based on a card field?
DECLARE_REFLECTION();
};
......@@ -51,13 +51,13 @@ class StatsCategory {
StatsCategory();
StatsCategory(const StatsDimensionP&);
bool automatic; ///< Automatically generated?
String name; ///< Name/label
String description; ///< Description, used in status bar
String icon_filename; ///< Icon for lists
Bitmap icon; ///< The loaded icon (optional of course)
vector<StatsDimensionP> dimensions; ///< The dimensions to use, higher dimensions may be null
GraphType type; ///< Type of graph to use
bool automatic; ///< Automatically generated?
DECLARE_REFLECTION();
};
......
......@@ -41,16 +41,16 @@ ControlPoint::ControlPoint()
, lock(LOCK_FREE)
{}
ControlPoint::ControlPoint(double x, double y)
: segment_before(SEGMENT_LINE), segment_after(SEGMENT_LINE)
: pos(x,y)
, segment_before(SEGMENT_LINE), segment_after(SEGMENT_LINE)
, lock(LOCK_FREE)
, pos(x,y)
{}
ControlPoint::ControlPoint(double x, double y, double xb, double yb, double xa, double ya, LockMode lock)
: segment_before(SEGMENT_CURVE), segment_after(SEGMENT_CURVE)
, lock(lock)
, pos(x,y)
: pos(x,y)
, delta_before(xb,yb)
, delta_after(xa,ya)
, segment_before(SEGMENT_CURVE), segment_after(SEGMENT_CURVE)
, lock(lock)
{}
void ControlPoint::onUpdateHandle(WhichHandle wh) {
......
......@@ -100,7 +100,7 @@ struct CompareTabIndex {
Field& af = *as.fieldP, &bf = *bs.fieldP;
if (af.tab_index < bf.tab_index) return true;
if (af.tab_index > bf.tab_index) return false;
if (abs(as.top - bs.top) < 15) {
if (fabs(as.top - bs.top) < 15) {
// the fields are almost on the same 'row'
// compare horizontally first
if (as.left < bs.left) return true; // horizontal sorting
......
......@@ -79,8 +79,10 @@ void CardListColumnSelectDialog::initList() {
// check
int i = list->GetCount() - 1;
list->Check(i, c.settings.visible);
// fix the background color
list->GetItem(i)->SetBackgroundColour(window_color);
#ifdef _WX_MSW_
// fix the background color
list->GetItem(i)->SetBackgroundColour(window_color);
#endif
}
}
......
......@@ -80,7 +80,7 @@ void CardViewer::drawViewer(RotatedDC& dc, ValueViewer& v) {
}
bool CardViewer::shouldDraw(const ValueViewer& v) const {
return GetUpdateRegion().Contains((wxRect)v.boundingBox()) != wxOutRegion;
return GetUpdateRegion().Contains(v.boundingBox().toRect()) != wxOutRegion;
}
// helper class for overdrawDC()
......
......@@ -22,13 +22,13 @@ const int BORDER = 1; // margin between items
GalleryList::GalleryList(Window* parent, int id, int direction)
: wxScrolledWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER | (direction == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL) )
, direction(direction)
, selection(NO_SELECTION)
, direction(direction)
{}
void GalleryList::update() {
const int w = item_size.width + MARGIN + 2*BORDER;
const int h = item_size.height + MARGIN + 2*BORDER;
const int w = (int)item_size.width + MARGIN + 2*BORDER;
const int h = (int)item_size.height + MARGIN + 2*BORDER;
// resize and scroll
if (direction == wxHORIZONTAL) {
SetVirtualSize(w * (int)itemCount() + MARGIN, h + MARGIN);
......@@ -56,11 +56,11 @@ void GalleryList::update() {
size_t GalleryList::findItem(const wxMouseEvent& ev) const {
if (direction == wxHORIZONTAL) {
int x, w = item_size.width + MARGIN + 2*BORDER;
int x, w = (int)item_size.width + MARGIN + 2*BORDER;
GetViewStart (&x, 0);
return static_cast<size_t>( x + ev.GetX() / w );
} else { // wxVERTICAL
int y, h = item_size.height + MARGIN + 2*BORDER;
int y, h = (int)item_size.height + MARGIN + 2*BORDER;
GetViewStart (0, &y);
return static_cast<size_t>( y + ev.GetY() / h );
}
......
......@@ -40,14 +40,14 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
dc.SetFont(*wxNORMAL_FONT);
dc.DrawText(capitalize_sentence(s.fieldP->name), RealPoint(margin_left, s.top + 1));
// draw 3D border
draw_control_border(this, dc.getDC(), wxRect(s.left - 1, s.top - 1, s.width + 2, s.height + 2));
draw_control_border(this, dc.getDC(), RealRect(s.left - 1, s.top - 1, s.width + 2, s.height + 2));
// draw viewer
v.draw(dc);
}
void NativeLookEditor::resizeViewers() {
// size stuff
UInt y = margin;
double y = margin;
int w;
GetClientSize(&w, 0);
const int default_height = 17;
......
......@@ -35,12 +35,12 @@ void PackageList::drawItem(DC& dc, int x, int y, size_t item, bool selected) {
dc.SetFont(wxFont(12,wxSWISS,wxNORMAL,wxBOLD,false,_("Arial")));
dc.GetTextExtent(capitalize(d.package->short_name), &w, &h);
pos = align_in_rect(ALIGN_CENTER, RealSize(w,h), rect);
dc.DrawText(capitalize(d.package->short_name), pos.x, pos.y + 110);
dc.DrawText(capitalize(d.package->short_name), (int)pos.x, (int)pos.y + 110);
// draw name
dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
dc.GetTextExtent(d.package->full_name, &w, &h);
RealPoint text_pos = align_in_rect(ALIGN_CENTER, RealSize(w,h), rect);
dc.DrawText(d.package->full_name, text_pos.x, text_pos.y + 130);
dc.DrawText(d.package->full_name, (int)text_pos.x, (int)text_pos.y + 130);
}
void PackageList::showData(const String& pattern) {
......
......@@ -10,6 +10,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/error.hpp>
#include <gui/control/gallery_list.hpp>
DECLARE_POINTER_TYPE(Packaged);
......
......@@ -11,6 +11,7 @@
#include <util/prec.hpp>
#include <gui/control/card_list.hpp>
#include <set>
// ----------------------------------------------------------------------------- : SelectCardList
......@@ -30,7 +31,7 @@ class SelectCardList : public CardListBase {
private:
DECLARE_EVENT_TABLE();
set<CardP> selected; ///< which cards are selected?
std::set<CardP> selected; ///< which cards are selected?
void toggle(const CardP& card);
......
......@@ -55,7 +55,7 @@ void TextCtrl::setValue(String* value) {
style->width = cs.GetWidth() - 2;
style->height = cs.GetHeight() - 2;
viewers.front()->getEditor()->determineSize(true);
SetMinSize(wxSize(style->width + 6, style->height + 6));
SetMinSize(RealSize(style->width + 6, style->height + 6));
}
valueChanged();
}
......
......@@ -56,15 +56,15 @@ class DropDownHider : public wxEvtHandler {
DropDownList::DropDownList(Window* parent, bool is_submenu, ValueViewer* viewer)
: wxPopupWindow(parent)
, mouse_down(false)
, text_offset(1)
, item_size(100,1)
, icon_size(0,0)
, selected_item(NO_SELECTION)
, mouse_down(false)
, open_sub_menu(nullptr)
, parent_menu(nullptr)
, hider(is_submenu ? nullptr : new DropDownHider(*this))
, viewer(viewer)
, item_size(100,1)
, icon_size(0,0)
, text_offset(1)
, hider(is_submenu ? nullptr : new DropDownHider(*this))
{
if (is_submenu) {
parent_menu = &dynamic_cast<DropDownList&>(*GetParent());
......@@ -110,16 +110,16 @@ void DropDownList::show(bool in_place, wxPoint pos) {
// Position the drop down list below the editor control (based on the style)
RealRect r = viewer->viewer.getRotation().trNoNeg(viewer->getStyle()->getRect());
if (viewer->viewer.nativeLook()) {
pos = wxPoint(r.x - 3, r.y - 3);
pos = RealPoint(r.x - 3, r.y - 3);
size.width = max(size.width, r.width + 6);
parent_height = r.height + 6;
parent_height = (int)r.height + 6;
} else {
pos = wxPoint(r.x - 1, r.y - 1);
pos = RealPoint(r.x - 1, r.y - 1);
size.width = max(size.width, r.width + 2);
parent_height = r.height;
parent_height = (int)r.height;
}
} else if (parent_menu) {
parent_height = -item_size.height - 1;
parent_height = -(int)item_size.height - 1;
}
pos = GetParent()->ClientToScreen(pos);
// move & resize
......@@ -191,7 +191,7 @@ bool DropDownList::showSubMenu(size_t item, int y) {
wxSize size = GetSize();
sub_menu->show(true,
sub_menu->GetParent()->ScreenToClient(ClientToScreen(
wxPoint(size.GetWidth() - 1, y + item_size.height)
wxPoint(size.GetWidth() - 1, y + (int)item_size.height)
)));
return true;
}
......@@ -201,7 +201,7 @@ int DropDownList::itemPosition(size_t item) const {
size_t count = itemCount();
for (size_t i = 0 ; i < count ; ++i) {
if (i == item) return y;
y += item_size.height + lineBelow(item);
y += (int)item_size.height + lineBelow(item);
}
// not found
assert(false);
......@@ -237,7 +237,7 @@ void DropDownList::draw(DC& dc) {
size_t count = itemCount();
for (size_t i = 0 ; i < count ; ++i) {
drawItem(dc, y, i);
y += item_size.height + lineBelow(i);
y += (int)item_size.height + lineBelow(i);
}
}
......@@ -247,27 +247,27 @@ void DropDownList::drawItem(DC& dc, int y, size_t item) {
if (item == selected_item) {
dc.SetBrush (wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
dc.DrawRectangle(marginW, y, item_size.width, item_size.height);
dc.DrawRectangle(marginW, y, (int)item_size.width, (int)item_size.height);
} else if (highlightItem(item)) {
// mix a color between selection and window
dc.SetBrush (lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT),
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW), 0.75));
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
dc.DrawRectangle(marginW, y, item_size.width, item_size.height);
dc.DrawRectangle(marginW, y, (int)item_size.width, (int)item_size.height);
} else {
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
}
// draw text and icon
drawIcon(dc, marginW, y, item, item == selected_item);
dc.DrawText(capitalize(itemText(item)), marginW + icon_size.width + 1, y + text_offset);
dc.DrawText(capitalize(itemText(item)), marginW + (int)icon_size.width + 1, y + text_offset);
// draw popup icon
if (submenu(item)) {
draw_menu_arrow(this, dc, wxRect(marginW, y, item_size.width, item_size.height), item == selected_item);
draw_menu_arrow(this, dc, RealRect(marginW, y, item_size.width, item_size.height), item == selected_item);
}
// draw line below
if (lineBelow(item)) {
dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW));
dc.DrawLine(marginW, y + item_size.height, marginW + item_size.width, y + item_size.height);
dc.DrawLine(marginW, y + (int)item_size.height, marginW + (int)item_size.width, y + (int)item_size.height);
}
}
......@@ -293,7 +293,7 @@ void DropDownList::onMotion(wxMouseEvent& ev) {
int startY = marginH;
size_t count = itemCount();
for (size_t i = 0 ; i < count ; ++i) {
int endY = startY + item_size.height;
int endY = startY + (int)item_size.height;
if (ev.GetY() >= startY && ev.GetY() < endY) {
selected_item = i;
showSubMenu(i, startY);
......
......@@ -47,15 +47,24 @@ Image generateDisabledImage(const Image& imgIn) {
// ----------------------------------------------------------------------------- : IconMenu
void IconMenu::Append(int id, const String& resource, const String& text, const String& help, int style, wxMenu* submenu) {
// load bitmap
Bitmap bitmap(resource);
bitmap = bitmap.GetSubBitmap(wxRect(0,0,16,16));
Image disabledImage = generateDisabledImage(bitmap.ConvertToImage());
// add menu item
wxMenuItem* item = new wxMenuItem(this, id, text, help, style, submenu);
item->SetBitmaps(bitmap, bitmap);
item->SetDisabledBitmap(disabledImage);
wxMenu::Append(item);
#ifdef __WXMSW__
// load bitmap
Bitmap bitmap(resource);
bitmap = bitmap.GetSubBitmap(wxRect(0,0,16,16));
Image disabledImage = generateDisabledImage(bitmap.ConvertToImage());
// add menu item
wxMenuItem* item = new wxMenuItem(this, id, text, help, style, submenu);
item->SetBitmaps(bitmap, bitmap);
item->SetDisabledBitmap(disabledImage);
wxMenu::Append(item);
#else
// load bitmap
Bitmap bitmap = loadResourceImage(resource);
// add menu
wxMenuItem* item = new wxMenuItem(this, id, text, help, style, submenu);
item->SetBitmaps(bitmap);
wxMenu::Append(item);
#endif
}
void IconMenu::Append(int id, const String& text, const String& help) {
......
......@@ -126,7 +126,7 @@ DisplayPreferencesPage::DisplayPreferencesPage(Window* parent)
borders-> SetValue( settings.default_stylesheet_settings.card_borders());
non_normal_export->SetValue(!settings.default_stylesheet_settings.card_normal_export());
zoom->SetRange(1, 1000);
zoom-> SetValue( settings.default_stylesheet_settings.card_zoom() * 100);
zoom-> SetValue(static_cast<int>(settings.default_stylesheet_settings.card_zoom() * 100));
// init sizer
wxSizer* s = new wxBoxSizer(wxVERTICAL);
wxSizer* s2 = new wxStaticBoxSizer(wxVERTICAL, this, _("Card Display"));
......
......@@ -149,7 +149,7 @@ class StatsFilter : public CardListFilter {
virtual bool keep(const CardP& card) {
Context& ctx = set.getContext(card);
FOR_EACH(v, values) {
if ((String)*v.first->script.invoke(ctx) != v.second) return false;
if (v.first->script.invoke(ctx)->toString() != v.second) return false;
}
return true;
}
......
......@@ -160,10 +160,10 @@ void SymbolBasicShapeEditor::makeShape(const Vector2D& a, const Vector2D& b, boo
// constrain
Vector2D size = b - a;
if (constrained) {
if (abs(size.x) > abs(size.y)) {
size.y = sgn(size.y) * abs(size.x);
if (fabs(size.x) > fabs(size.y)) {
size.y = sgn(size.y) * fabs(size.x);
} else {
size.x = sgn(size.x) * abs(size.y);
size.x = sgn(size.x) * fabs(size.y);
}
}
// make shape
......
......@@ -12,7 +12,7 @@
#include <wx/mstream.h>
#include <wx/renderer.h>
#if wxUSE_UXTHEME
#if wxUSE_UXTHEME && defined(__WXMSW__)
#include <wx/msw/uxtheme.h>
#include <tmschema.h>
#include <shlobj.h>
......@@ -109,7 +109,7 @@ void draw3DBorder(DC& dc, int x1, int y1, int x2, int y2) {
}
void draw_control_border(Window* win, DC& dc, const wxRect& rect) {
#if wxUSE_UXTHEME
#if wxUSE_UXTHEME && defined(__WXMSW__)
RECT r;
wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
if (themeEngine && themeEngine->IsAppThemed()) {
......
......@@ -23,8 +23,8 @@ class ChoiceThumbnailRequest : public ThumbnailRequest {
virtual Image generate();
virtual void store(const Image&);
private:
int id;
StyleSheetP stylesheet;
int id;
};
ChoiceThumbnailRequest::ChoiceThumbnailRequest(ChoiceValueEditor* cve, int id)
......@@ -84,8 +84,8 @@ void ChoiceThumbnailRequest::store(const Image& img) {
DropDownChoiceList::DropDownChoiceList(Window* parent, bool is_submenu, ChoiceValueEditor& cve, ChoiceField::ChoiceP group)
: DropDownList(parent, is_submenu, is_submenu ? nullptr : &cve)
, group(group)
, cve(cve)
, group(group)
{
icon_size.width = 16;
icon_size.height = 16;
......
......@@ -53,7 +53,7 @@ DropDownColorList::DropDownColorList(Window* parent, ColorValueEditor& cve)
{
icon_size.width = 25;
if (item_size.height < 16) {
text_offset = (16 - item_size.height) / 2;
text_offset = (16 - (int)item_size.height) / 2;
item_size.height = 16;
}
}
......@@ -86,7 +86,7 @@ void DropDownColorList::drawIcon(DC& dc, int x, int y, size_t item, bool selecte
// draw a rectangle with the right color
dc.SetPen(wxSystemSettings::GetColour(selected ? wxSYS_COLOUR_HIGHLIGHTTEXT : wxSYS_COLOUR_WINDOWTEXT));
dc.SetBrush(col);
dc.DrawRectangle(x+1, y+1, icon_size.width-2, item_size.height-2);
dc.DrawRectangle(x+1, y+1, (int)icon_size.width-2, (int)item_size.height-2);
}
......
......@@ -31,6 +31,7 @@
*/
class ValueEditor {
public:
virtual ~ValueEditor();
// --------------------------------------------------- : Events
/// This editor gains focus
......
......@@ -605,10 +605,10 @@ void TextValueEditor::determineSize(bool force_fit) {
if (!force_fit) style().height = 100;
int sbw = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
scrollbar->SetSize(
style().left + style().width - sbw + 1,
style().top - 1,
sbw,
style().height + 2);
(int)style().left + style().width - sbw + 1,
(int)style().top - 1,
(int)sbw,
(int)style().height + 2);
v.reset();
} else {
// Height depends on font
......@@ -681,4 +681,4 @@ void TextValueEditor::prepareDrawScrollbar(RotatedDC& dc) {
updateScrollbar();
style().width.mutate() += scrollbar_width;
}
}
\ No newline at end of file
}
......@@ -84,8 +84,9 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
private:
size_t selection_start, selection_end; ///< Cursor position/selection (if any), cursor positions
size_t selection_start_i, selection_end_i; ///< Cursor position/selection, character indices
TextValueEditorScrollBar* scrollbar; ///< Scrollbar for multiline fields in native look
bool select_words; ///< Select whole words when dragging the mouse?
bool select_words; ///< Select whole words when dragging the mouse?
TextValueEditorScrollBar* scrollbar; ///< Scrollbar for multiline fields in native look
bool scroll_with_cursor; ///< When the cursor moves, should the scrollposition change?
// --------------------------------------------------- : Selection / movement
......@@ -126,10 +127,7 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
// --------------------------------------------------- : Scrolling
friend class TextValueEditorScrollBar;
/// When the cursor moves, should the scrollposition change?
bool scroll_with_cursor;
/// Scroll to the given position, called by scrollbar
void scrollTo(int pos);
/// Update the scrollbar to show the current scroll position
......
......@@ -107,8 +107,8 @@ END_EVENT_TABLE ()
HoverButtonExt::HoverButtonExt(Window* parent, int id, const String& icon_name, const String& label, const String& sub_label)
: HoverButton(parent, id, _("BTN"))
, label(label), sub_label(sub_label)
, icon(load_resource_image(icon_name))
, label(label), sub_label(sub_label)
, font_large(14, wxSWISS, wxNORMAL, wxNORMAL, false, _("Arial"))
, font_small(8, wxSWISS, wxNORMAL, wxNORMAL, false, _("Arial"))
{}
......
......@@ -122,7 +122,7 @@ AColor LinearGradientSymbolFilter::color(double x, double y, SymbolSet point) co
}
double LinearGradientSymbolFilter::t(double x, double y) const {
double t= abs( (x - center_x) * (end_x - center_x) + (y - center_y) * (end_y - center_y)) / len;
double t= fabs( (x - center_x) * (end_x - center_x) + (y - center_y) * (end_y - center_y)) / len;
return min(1.,max(0.,t));
}
......
......@@ -48,10 +48,10 @@ struct CharInfo {
/// A section of text that can be rendered using a TextViewer
class TextElement {
public:
/// What section of the input string is this element?
size_t start, end;
/// The text of which a subsection is drawn
String text;
/// What section of the input string is this element?
size_t start, end;
inline TextElement(const String& text, size_t start ,size_t end) : text(text), start(start), end(end) {}
virtual ~TextElement() {}
......
......@@ -43,7 +43,7 @@ void ColorValueViewer::draw(RotatedDC& dc) {
style().top_width < style().height && style().bottom_width < style().height;
if (clip) {
// clip away the inside of the rectangle
wxRegion r = dc.tr(style().getRect());
wxRegion r = dc.tr(style().getRect()).toRect();
r.Subtract(dc.tr(RealRect(
style().left + style().left_width,
style().top + style().top_width,
......
......@@ -22,7 +22,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
InputStreamP image_file = getSet().openIn(value().filename);
Image image;
if (image.LoadFile(*image_file)) {
image.Rescale(dc.trS(style().width), dc.trS(style().height));
image.Rescale((int)dc.trS(style().width), (int)dc.trS(style().height));
// apply mask to image
loadMask(dc);
if (alpha_mask) alpha_mask->setAlpha(image);
......@@ -34,7 +34,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
}
// if there is no image, generate a placeholder, only if there is enough room for it
if (!bitmap.Ok() && style().width > 40) {
bitmap = imagePlaceholder(dc, dc.trS(style().width), dc.trS(style().height), viewer.drawEditing());
bitmap = imagePlaceholder(dc, (int)dc.trS(style().width), (int)dc.trS(style().height), viewer.drawEditing());
loadMask(dc);
if (alpha_mask) alpha_mask->setAlpha(bitmap);
}
......@@ -45,15 +45,15 @@ void ImageValueViewer::draw(RotatedDC& dc) {
}
bool ImageValueViewer::containsPoint(const RealPoint& p) const {
int x = p.x - style().left;
int y = p.y - style().top;
if (x < 0 || y < 0 || x >= (int)style().width || y >= (int)style().height) {
double x = p.x - style().left;
double y = p.y - style().top;
if (x < 0 || y < 0 || x >= style().width || y >= style().height) {
return false; // outside rectangle
}
// check against mask
if (!style().mask_filename().empty()) {
loadMask(viewer.getRotation());
return !alpha_mask || !alpha_mask->isTransparent(x, y);
return !alpha_mask || !alpha_mask->isTransparent((int)x, (int)y);
} else {
return true;
}
......@@ -70,12 +70,13 @@ void ImageValueViewer::onStyleChange() {
void ImageValueViewer::loadMask(const Rotation& rot) const {
if (style().mask_filename().empty()) return; // no mask
if (alpha_mask && alpha_mask->size == wxSize(rot.trS(style().width), rot.trS(style().height))) return; // mask loaded and right size
int w = rot.trS(style().width), h = rot.trS(style().height);
if (alpha_mask && alpha_mask->size == wxSize(w,h)) return; // mask loaded and right size
// (re) load the mask
Image image;
InputStreamP image_file = viewer.stylesheet->openIn(style().mask_filename);
if (image.LoadFile(*image_file)) {
Image resampled(rot.trS(style().width), rot.trS(style().height));
Image resampled(w,h);
resample(image, resampled);
alpha_mask = new_shared1<AlphaMask>(resampled);
}
......
......@@ -238,11 +238,11 @@ void instrUnary (UnaryInstructionType i, ScriptValueP& a) {
// operator on strings or doubles or ints
#define OPERATOR_SDI(OP) \
if (at == SCRIPT_STRING || bt == SCRIPT_STRING) { \
a = toScript((String)*a OP (String)*b); \
a = toScript(a->toString() OP b->toString()); \
} else if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { \
a = toScript((double)*a OP (double)*b); \
a = toScript((double)*a OP (double)*b); \
} else { \
a = toScript((int)*a OP (int)*b); \
a = toScript((int)*a OP (int)*b); \
} \
break
......@@ -282,13 +282,13 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP&
} else if (at == SCRIPT_FUNCTION && bt == SCRIPT_FUNCTION) {
a = new_intrusive2<ScriptCompose>(a, b);
} else if (at == SCRIPT_STRING || bt == SCRIPT_STRING) {
a = toScript((String)*a + (String)*b);
a = toScript(a->toString() + b->toString());
} else if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) {
a = toScript((double)*a + (double)*b);
a = toScript((double)*a + (double)*b);
} else if (at == SCRIPT_INT || bt == SCRIPT_INT) {
a = toScript((int)*a + (int)*b);
a = toScript((int)*a + (int)*b);
} else {
a = toScript((String)*a + (String)*b);
a = toScript(a->toString() + b->toString());
}
break;
case I_SUB: OPERATOR_DI(-);
......
......@@ -56,7 +56,7 @@ class ScriptReplaceRule : public ScriptValue {
ctx.setVariable(name, toScript(value));
}
// call
inside = (String)*replacement_function->eval(ctx);
inside = replacement_function->eval(ctx)->toString();
} else {
regex.Replace(&inside, replacement, 1); // replace inside
}
......@@ -92,7 +92,7 @@ SCRIPT_FUNCTION(replace_rule) {
if (replace->type() == SCRIPT_FUNCTION) {
ret->replacement_function = replace;
} else {
ret->replacement = (String)*replace;
ret->replacement = replace->toString();
}
// in_context
SCRIPT_OPTIONAL_PARAM_N(String, _("in context"), in_context) {
......@@ -354,7 +354,7 @@ String replace_tag_contents(String input, const String& tag, const ScriptValueP&
// replace
ret += input.substr(0, pos); // before tag
ret += tag;
ret += *contents->eval(ctx);// new contents (call)
ret += contents->eval(ctx)->toString();// new contents (call)
ret += close_tag(tag);
// next
input = input.substr(skip_tag(input,end));
......@@ -387,7 +387,7 @@ bool equal(const ScriptValue& a, const ScriptValue& b) {
} else if (at == SCRIPT_DOUBLE) {
return (double)a == (double)b;
} else if (at == SCRIPT_STRING) {
return (String)a == (String)b;
return a.toString() == b.toString();
} else if (at == SCRIPT_OBJECT) {
// HACK for ScriptObject<shared_ptr<X> >
// assumes different types are layed out the same, and that
......@@ -405,7 +405,7 @@ int position_in_vector(const ScriptValueP& of, const ScriptValueP& in, const Scr
ScriptType of_t = of->type(), in_t = in->type();
if (of_t == SCRIPT_STRING || in_t == SCRIPT_STRING) {
// string finding
return (int)((String)*of).find(*in); // (int)npos == -1
return (int)of->toString().find(in->toString()); // (int)npos == -1
} else if (order_by) {
ScriptObject<Set*>* s = dynamic_cast<ScriptObject<Set*>* >(in.get());
ScriptObject<CardP>* c = dynamic_cast<ScriptObject<CardP>*>(of.get());
......
......@@ -153,7 +153,7 @@ template <> void Reader::handle(ScriptableImage& s) {
if (starts_with(s.script.unparsed, _("script:"))) {
s.script.unparsed = s.script.unparsed.substr(7);
s.script.parse(*this);
} else if (s.script.unparsed.find_first_of('{') != String.npos) {
} else if (s.script.unparsed.find_first_of('{') != String::npos) {
s.script.parse(*this, true);
} else {
// script is a constant function
......
......@@ -38,10 +38,10 @@ struct Token {
String value;
bool newline; ///< Is there a newline between this token and the previous one?
inline operator == (TokenType t) const { return type == t; }
inline operator != (TokenType t) const { return type != t; }
inline operator == (const String& s) const { return type != TOK_STRING && value == s; }
inline operator != (const String& s) const { return type == TOK_STRING || value != s; }
inline bool operator == (TokenType t) const { return type == t; }
inline bool operator != (TokenType t) const { return type != t; }
inline bool operator == (const String& s) const { return type != TOK_STRING && value == s; }
inline bool operator != (const String& s) const { return type == TOK_STRING || value != s; }
};
enum OpenBrace
......@@ -521,7 +521,7 @@ void parseOper(TokenIterator& input, Script& script, Precedence minPrec, Instruc
// for smart strings: "x" {{ e }} "y"
// optimize: "" + e -> e
Instruction i = script.getInstructions().back();
if (i.instr == I_PUSH_CONST && String(*script.getConstants()[i.data]).empty()) {
if (i.instr == I_PUSH_CONST && script.getConstants()[i.data]->toString().empty()) {
script.getInstructions().pop_back();
parseOper(input, script, PREC_ALL); // e
} else {
......@@ -531,7 +531,7 @@ void parseOper(TokenIterator& input, Script& script, Precedence minPrec, Instruc
parseOper(input, script, PREC_NONE); // y
// optimize: e + "" -> e
i = script.getInstructions().back();
if (i.instr == I_PUSH_CONST && String(*script.getConstants()[i.data]).empty()) {
if (i.instr == I_PUSH_CONST && script.getConstants()[i.data]->toString().empty()) {
script.getInstructions().pop_back();
} else {
script.addInstruction(I_BINARY, I_ADD);
......
......@@ -14,7 +14,7 @@
// ----------------------------------------------------------------------------- : Store
void store(const ScriptValueP& val, String& var) { var = static_cast<String>(*val); }
void store(const ScriptValueP& val, String& var) { var = val->toString(); }
void store(const ScriptValueP& val, int& var) { var = *val; }
void store(const ScriptValueP& val, double& var) { var = *val; }
void store(const ScriptValueP& val, bool& var) { var = static_cast<int>(*val); }
......@@ -25,8 +25,8 @@ void store(const ScriptValueP& val, Defaultable<Color>& var) { var.assign(*val)
// ----------------------------------------------------------------------------- : OptionalScript
OptionalScript::OptionalScript(const String& script_)
: unparsed(script_)
, script(::parse(script_))
: script(::parse(script_))
, unparsed(script_)
{}
OptionalScript::~OptionalScript() {}
......
......@@ -57,7 +57,12 @@ class ScriptValue : public IntrusivePtrBase {
virtual operator int() const;
/// Convert this value to a color
virtual operator Color() const;
/// Explicit overload to convert to a string
/** This is sometimes necessary, because wxString has an int constructor,
* which confuses gcc. */
inline String toString() const { return *this; }
/// Get a member variable from this value
virtual ScriptValueP getMember(const String& name) const;
/// Signal that a script depends on a member of this value
......@@ -246,10 +251,11 @@ class ScriptObject : public ScriptValue {
// ----------------------------------------------------------------------------- : Creating
/// Convert a value to a script value
ScriptValueP toScript(int v);
ScriptValueP toScript(double v);
ScriptValueP toScript(const String& v);
ScriptValueP toScript(const Color& v);
ScriptValueP toScript(int v);
inline ScriptValueP toScript(long v) { return toScript((int) v); }
ScriptValueP toScript(double v);
ScriptValueP toScript(const String& v);
ScriptValueP toScript(const Color& v);
inline ScriptValueP toScript(bool v) { return v ? script_true : script_false; }
template <typename T>
inline ScriptValueP toScript(const vector<T>* v) { return new_intrusive1<ScriptCollection<vector<T> > >(v); }
......
......@@ -16,7 +16,7 @@
// ----------------------------------------------------------------------------- : AtomicInt : windows
#ifdef _WX_MSW_
#ifdef __WXMSW__
#ifdef _MSC_VER
extern "C" {
......
......@@ -57,14 +57,14 @@ OrderCache<T>::OrderCache(const vector<T>& keys, const vector<String>& values) {
// initialize positions, use pos to point back to the values vector
positions.reserve(keys.size());
int i = 0;
for (vector<T>::const_iterator it = keys.begin() ; it != keys.end() ; ++it, ++i) {
for (typename vector<T>::const_iterator it = keys.begin() ; it != keys.end() ; ++it, ++i) {
positions.push_back(KV(&**it, i));
}
// sort the KVs by the values
sort(positions.begin(), positions.end(), CompareValues(values));
// update positions, to point to sorted list
i = 0;
for (vector<KV>::iterator it = positions.begin() ; it != positions.end() ; ++it, ++i) {
for (typename vector<KV>::iterator it = positions.begin() ; it != positions.end() ; ++it, ++i) {
it->second = i;
}
// sort the KVs by the keys
......
......@@ -152,6 +152,11 @@ class RealRect : private RealPoint, private RealSize {
int i_t = to_int(y), i_b = to_int(bottom());
return wxRect(i_l, i_t, i_r - i_l, i_b - i_t);
}
/// Explicit conversion to wxRect, to not confuse gcc
inline wxRect toRect() const {
return *this;
}
};
/// Split a rectangle horizontally
......
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