From db7b78d239eb718888937e5a7ed776d7407c8b8e Mon Sep 17 00:00:00 2001 From: gazer Date: Sat, 19 Dec 2015 10:00:26 +0300 Subject: [PATCH] Many tiny fixes --- src/dlangui/core/editable.d | 9 ++++----- src/dlangui/core/files.d | 3 +-- src/dlangui/core/i18n.d | 1 - src/dlangui/core/linestream.d | 16 +++++++-------- src/dlangui/core/textsource.d | 2 +- src/dlangui/core/types.d | 2 +- src/dlangui/dml/dmlhighlight.d | 6 +----- src/dlangui/dml/parser.d | 4 ++-- src/dlangui/graphics/drawbuf.d | 3 +-- src/dlangui/graphics/fonts.d | 2 +- src/dlangui/graphics/ftfonts.d | 2 +- src/dlangui/graphics/gldrawbuf.d | 8 +++----- src/dlangui/graphics/glsupport.d | 27 +++++++++++++------------ src/dlangui/graphics/images.d | 4 +--- src/dlangui/graphics/resources.d | 4 ---- src/dlangui/graphics/xpm/colors.d | 3 ++- src/dlangui/platforms/common/platform.d | 3 +-- src/dlangui/widgets/editors.d | 1 - src/dlangui/widgets/lists.d | 4 ++-- src/dlangui/widgets/metadata.d | 2 +- src/dlangui/widgets/styles.d | 3 --- src/dlangui/widgets/tabs.d | 1 - src/dlangui/widgets/widget.d | 4 ++-- 23 files changed, 47 insertions(+), 67 deletions(-) diff --git a/src/dlangui/core/editable.d b/src/dlangui/core/editable.d index 80de09f8..0cdc7888 100644 --- a/src/dlangui/core/editable.d +++ b/src/dlangui/core/editable.d @@ -103,7 +103,6 @@ ubyte tokenCategory(ubyte t) { dstring[] splitDString(dstring source, dchar delimiter = EOL) { int start = 0; dstring[] res; - dchar lastchar; for (int i = 0; i <= source.length; i++) { if (i == source.length || source[i] == delimiter) { if (i >= start) { @@ -173,10 +172,10 @@ struct TextPosition { return 1; return 0; } - inout bool opEquals(ref inout TextPosition v) { + bool opEquals(ref inout TextPosition v) inout { return line == v.line && pos == v.pos; } - @property string toString() { + @property string toString() const { return to!string(line) ~ ":" ~ to!string(pos); } /// adds deltaPos to position and returns result @@ -212,7 +211,7 @@ struct TextRange { @property int lines() const { return end.line - start.line + 1; } - @property string toString() { + @property string toString() const { return "[" ~ start.toString ~ ":" ~ end.toString ~ "]"; } } @@ -856,7 +855,7 @@ class EditableContent { /// returns text range for whole line lineIndex TextRange lineRange(int lineIndex) { - return TextRange(TextPosition(lineIndex, 0), lineIndex < _lines.length - 1 ? lineBegin(lineIndex + 1) : lineEnd(lineIndex)); + return TextRange(TextPosition(lineIndex, 0), lineIndex < cast(int)_lines.length - 1 ? lineBegin(lineIndex + 1) : lineEnd(lineIndex)); } /// find nearest next tab position diff --git a/src/dlangui/core/files.d b/src/dlangui/core/files.d index b74d7f18..5e92a088 100644 --- a/src/dlangui/core/files.d +++ b/src/dlangui/core/files.d @@ -359,8 +359,7 @@ string[] splitPath(string path) { /// for executable name w/o path, find absolute path to executable string findExecutablePath(string executableName) { - import std.algorithm; - import std.string; + import std.string : split; version (Windows) { if (!executableName.endsWith(".exe")) executableName = executableName ~ ".exe"; diff --git a/src/dlangui/core/i18n.d b/src/dlangui/core/i18n.d index 1390ee97..552e7500 100644 --- a/src/dlangui/core/i18n.d +++ b/src/dlangui/core/i18n.d @@ -280,7 +280,6 @@ synchronized class UIStringTranslator { /** Looks for i18n directory inside one of passed dirs, and uses first found as directory to read i18n files from */ void findTranslationsDir(string[] dirs ...) { _resourceDirs.length = 0; - import std.file; foreach(dir; dirs) { string path = appendPath(dir, "i18n/"); if (exists(path) && isDir(path)) { diff --git a/src/dlangui/core/linestream.d b/src/dlangui/core/linestream.d index ff72b241..766e0c63 100644 --- a/src/dlangui/core/linestream.d +++ b/src/dlangui/core/linestream.d @@ -72,7 +72,7 @@ public enum EncodingType : int { ASCII, /// encoding is unknown UNKNOWN -}; +} /// Line ending style public enum LineEnding : int { /// LF (0x0A) - unix style @@ -95,7 +95,7 @@ struct TextFileFormat { LineEnding lineEnding; /// byte order mark character flag bool bom; - string toString() { + string toString() const { return to!string(encoding) ~ " " ~ to!string(lineEnding) ~ (bom ? " bom" : ""); } } @@ -236,7 +236,7 @@ class LineStream { public enum ErrorCodes { /// invalid character for current encoding INVALID_CHARACTER - }; + } private InputStream _stream; private string _filename; @@ -596,7 +596,7 @@ private class Utf8LineStream : LineStream { invalidCharFlag = true; break; } - ch = ((ch0 & 0x1F) << 6) | ((ch1 & 0x3F)); + ch = ((ch0 & 0x1F) << 6) | (ch1 & 0x3F); bread = 2; } if ((ch0 & 0xF0) == 0xE0) { // three bytes 1110xxxx 10xxxxxx 10xxxxxx @@ -608,7 +608,7 @@ private class Utf8LineStream : LineStream { invalidCharFlag = true; break; } - ch = ((ch0 & 0x0F) << 12) | ((ch1 & 0x1F) << 6) | ((ch2 & 0x3F)); + ch = ((ch0 & 0x0F) << 12) | ((ch1 & 0x1F) << 6) | (ch2 & 0x3F); bread = 3; } if ((ch0 & 0xF8) == 0xF0) { // four bytes 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx @@ -621,7 +621,7 @@ private class Utf8LineStream : LineStream { invalidCharFlag = true; break; } - ch = ((ch0 & 0x07) << 18) | ((ch1 & 0x3F) << 12) | ((ch2 & 0x3F) << 6) | ((ch3 & 0x3F)); + ch = ((ch0 & 0x07) << 18) | ((ch1 & 0x3F) << 12) | ((ch2 & 0x3F) << 6) | (ch3 & 0x3F); bread = 4; } if ((ch0 & 0xFC) == 0xF8) { // five bytes 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx @@ -635,7 +635,7 @@ private class Utf8LineStream : LineStream { invalidCharFlag = true; break; } - ch = ((ch0 & 0x03) << 24) | ((ch1 & 0x3F) << 18) | ((ch2 & 0x3F) << 12) | ((ch3 & 0x3F) << 6) | ((ch4 & 0x3F)); + ch = ((ch0 & 0x03) << 24) | ((ch1 & 0x3F) << 18) | ((ch2 & 0x3F) << 12) | ((ch3 & 0x3F) << 6) | (ch4 & 0x3F); bread = 5; } if ((ch0 & 0xFE) == 0xFC) { // six bytes 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx @@ -650,7 +650,7 @@ private class Utf8LineStream : LineStream { invalidCharFlag = true; break; } - ch = ((ch0 & 0x01) << 30) | ((ch1 & 0x3F) << 24) | ((ch2 & 0x3F) << 18) | ((ch3 & 0x3F) << 12) | ((ch4 & 0x3F) << 6) | ((ch5 & 0x3F)); + ch = ((ch0 & 0x01) << 30) | ((ch1 & 0x3F) << 24) | ((ch2 & 0x3F) << 18) | ((ch3 & 0x3F) << 12) | ((ch4 & 0x3F) << 6) | (ch5 & 0x3F); bread = 5; } if ((ch >= 0xd800 && ch < 0xe000) || (ch > 0x10FFFF)) { diff --git a/src/dlangui/core/textsource.d b/src/dlangui/core/textsource.d index 537099bd..0dc58a34 100644 --- a/src/dlangui/core/textsource.d +++ b/src/dlangui/core/textsource.d @@ -13,7 +13,7 @@ class SourceFile { public this(string filename) { _filename = filename; } - override @property string toString() { + override @property string toString() const { return _filename; } } diff --git a/src/dlangui/core/types.d b/src/dlangui/core/types.d index c13eeab5..38e8256d 100644 --- a/src/dlangui/core/types.d +++ b/src/dlangui/core/types.d @@ -170,7 +170,7 @@ struct Rect { return left >= rc.left && right <= rc.right && top >= rc.top && bottom <= rc.bottom; } - bool opEquals(Rect rc) { + bool opEquals(Rect rc) const { return left == rc.left && right == rc.right && top == rc.top && bottom == rc.bottom; } } diff --git a/src/dlangui/dml/dmlhighlight.d b/src/dlangui/dml/dmlhighlight.d index 09ecfa1e..e20f8e79 100644 --- a/src/dlangui/dml/dmlhighlight.d +++ b/src/dlangui/dml/dmlhighlight.d @@ -267,7 +267,7 @@ class DMLSyntaxSupport : SyntaxSupport { static struct TokenWithRange { Token token; TextRange range; - @property string toString() { + @property string toString() const { return token.toString ~ range.toString; } } @@ -431,7 +431,6 @@ class DMLSyntaxSupport : SyntaxSupport { for (int i = range.start.line; i <= range.end.line; i++) { dstring s = content.line(i); int charsRemoved = 0; - int minp = 0; if (i == range.start.line) { int maxp = content.lineLength(range.start.line); if (i == range.end.line) @@ -594,7 +593,6 @@ class DMLSyntaxSupport : SyntaxSupport { if (line == 0) return; // not for first line int prevLine = line - 1; - dstring lineText = _content.line(line); TextLineMeasure lineMeasurement = _content.measureLine(line); TextLineMeasure prevLineMeasurement = _content.measureLine(prevLine); while (prevLineMeasurement.empty && prevLine > 0) { @@ -636,8 +634,6 @@ class DMLSyntaxSupport : SyntaxSupport { if (lineMeasurement.firstNonSpace != op.newRange.start.pos) return; // not in beginning of line if (lineMeasurement.firstNonSpaceX >= 0 && lineMeasurement.firstNonSpaceX != prevLineMeasurement.firstNonSpaceX) { - dstring prevLineText = _content.line(prevLine); - TokenPropString prevLineTokenProps = _content.lineTokenProps(prevLine); int spacex = prevLineMeasurement.firstNonSpaceX; if (spacex != lineMeasurement.firstNonSpaceX) { dstring txt = _content.fillSpace(spacex); diff --git a/src/dlangui/dml/parser.d b/src/dlangui/dml/parser.d index ddafa475..5f10c419 100644 --- a/src/dlangui/dml/parser.d +++ b/src/dlangui/dml/parser.d @@ -134,7 +134,7 @@ struct Token { int intvalue; double floatvalue; } - public @property string toString() { + public @property string toString() const { if (type == TokenType.integer) return "" ~ to!string(line) ~ ":" ~ to!string(pos) ~ " " ~ to!string(type) ~ " " ~ to!string(intvalue); else if (type == TokenType.floating) @@ -163,7 +163,7 @@ class Tokenizer { enum : int { EOF_CHAR = 0x001A, EOL_CHAR = 0x000A - }; + } this(string source, string filename = "") { _filename = filename; diff --git a/src/dlangui/graphics/drawbuf.d b/src/dlangui/graphics/drawbuf.d index 58a284d1..17d0b557 100644 --- a/src/dlangui/graphics/drawbuf.d +++ b/src/dlangui/graphics/drawbuf.d @@ -871,7 +871,6 @@ class GrayDrawBuf : DrawBuf { int srcdx = glyph.blackBoxX; int srcdy = glyph.blackBoxY; bool clipping = true; //!_clipRect.empty(); - ubyte cl = cast(ubyte)(color & 255); for (int yy = 0; yy < srcdy; yy++) { int liney = y + yy; if (clipping && (liney < _clipRect.top || liney >= _clipRect.bottom)) @@ -1115,4 +1114,4 @@ private bool CohenSutherlandLineClipAndDraw(ref Rect clipRect, ref double x0, re } } return accept; -} \ No newline at end of file +} diff --git a/src/dlangui/graphics/fonts.d b/src/dlangui/graphics/fonts.d index 232d7db3..c6508757 100644 --- a/src/dlangui/graphics/fonts.d +++ b/src/dlangui/graphics/fonts.d @@ -886,7 +886,7 @@ struct glyph_gamma_table(int maxv = 65) private: ubyte[maxv] _map; double _gamma = 1.0; -}; +} __gshared glyph_gamma_table!65 _gamma65; __gshared glyph_gamma_table!256 _gamma256; diff --git a/src/dlangui/graphics/ftfonts.d b/src/dlangui/graphics/ftfonts.d index 59b9c826..63af8938 100644 --- a/src/dlangui/graphics/ftfonts.d +++ b/src/dlangui/graphics/ftfonts.d @@ -554,7 +554,7 @@ class FreeTypeFontManager : FontManager { Log.v("DerelictFT: Missing symbols callback is registered"); DerelictFT.load(); Log.v("DerelictFT: Loaded"); - } catch (Throwable e) { + } catch (Exception e) { Log.e("Derelict: cannot load freetype shared library: ", e.msg); throw new Exception("Cannot load freetype library"); } diff --git a/src/dlangui/graphics/gldrawbuf.d b/src/dlangui/graphics/gldrawbuf.d index 5804b9ed..1d284bdf 100644 --- a/src/dlangui/graphics/gldrawbuf.d +++ b/src/dlangui/graphics/gldrawbuf.d @@ -554,7 +554,7 @@ private class GLImageCache { removePage(item.page); } _map.remove(objectId); - delete item; + destroy(item); } } } @@ -659,7 +659,6 @@ private class GLGlyphCache { return; } //Log.d("updateTexture for font glyph page - setting image ", _drawbuf.width, "x", _drawbuf.height, " tx=", _texture.ID); - int len = _drawbuf.width * _drawbuf.height; if (!glSupport.setTextureImage(_texture, _drawbuf.width, _drawbuf.height, cast(ubyte *)_drawbuf.scanLine(0))) { destroy(_texture); _texture = null; @@ -839,7 +838,7 @@ private class GLGlyphCache { removePage(item.page); } _map.remove(objectId); - delete item; + destroy(item); } } } @@ -924,8 +923,7 @@ public: } override void draw() { if (_handler) { - import derelict.opengl3.gl3; - import derelict.opengl3.gl; + import derelict.opengl3.gl3 : glViewport; glViewport(_rc.left, _rc.top, _rc.right, _rc.bottom); _handler(_buf, _rc); glSupport.setOrthoProjection(Rect(0, 0, _buf.width, _buf.height)); diff --git a/src/dlangui/graphics/glsupport.d b/src/dlangui/graphics/glsupport.d index fc3694e3..1baf67ec 100644 --- a/src/dlangui/graphics/glsupport.d +++ b/src/dlangui/graphics/glsupport.d @@ -103,14 +103,19 @@ class GLProgram { private void compatibilityFixes(ref char[] code, GLuint type) { if (glslversionInt < 150) { code = replace(code, " texture(", " texture2D("); - code = replace(code, "in ", ""); - code = replace(code, "out ", ""); - } + if(type == GL_VERTEX_SHADER) + { + code = replace(code, "in ", "attribute "); + code = replace(code, "out ", "varying "); + } else + { + code = replace(code, "in ", "varying "); + } + } } private GLuint compileShader(string src, GLuint type) { - import core.stdc.stdlib; - import std.string; + import std.string : toStringz, fromStringz; char[] sourceCode; sourceCode ~= "#version "; @@ -202,10 +207,6 @@ class GLProgram { } } -immutable string HIGHP = ""; -immutable string LOWP = ""; -immutable string MEDIUMP = ""; - class SolidFillProgram : GLProgram { @property override string vertexSource() { return q{ @@ -698,8 +699,8 @@ class GLSupport { // don't flip for framebuffer if (currentFBO) { - dsty0 = cast(float)((yy)); - dsty1 = cast(float)((yy + dy)); + dsty0 = cast(float)(yy); + dsty1 = cast(float)(yy + dy); } float srcx0 = srcx / cast(float)tdx; @@ -763,8 +764,8 @@ class GLSupport { // don't flip for framebuffer if (currentFBO) { - dsty0 = cast(float)((yy)); - dsty1 = cast(float)((yy + dy)); + dsty0 = cast(float)(yy); + dsty1 = cast(float)(yy + dy); } float srcx0 = srcx / cast(float)tdx; diff --git a/src/dlangui/graphics/images.d b/src/dlangui/graphics/images.d index 2080eb5b..7d2164b5 100644 --- a/src/dlangui/graphics/images.d +++ b/src/dlangui/graphics/images.d @@ -69,7 +69,7 @@ ColorDrawBuf loadImage(immutable ubyte[] data, string filename) { import std.algorithm : endsWith; if (filename.endsWith(".xpm")) { - import dlangui.graphics.xpm.reader; + import dlangui.graphics.xpm.reader : parseXPM; try { return parseXPM(data); } @@ -104,7 +104,6 @@ ColorDrawBuf loadImage(immutable ubyte[] data, string filename) { return null; } } else version (USE_DLIBIMAGE) { - import std.algorithm; static import dlib.core.stream; try { version (ENABLE_DLIBIMAGE_JPEG) { @@ -138,7 +137,6 @@ ColorDrawBuf loadImage(immutable ubyte[] data, string filename) { return null; } } else version (USE_DIMAGE) { - import std.algorithm; static import dimage.stream; try { SuperImage image = null; diff --git a/src/dlangui/graphics/resources.d b/src/dlangui/graphics/resources.d index 36b53cdc..7fcbf97e 100644 --- a/src/dlangui/graphics/resources.d +++ b/src/dlangui/graphics/resources.d @@ -458,7 +458,6 @@ class ImageDrawable : Drawable { //Log.d("drawing nine patch image with frame ", p.frame, " padding ", p.padding); int w = width; int h = height; - Rect dstrect = rc; Rect srcrect = Rect(1, 1, w + 1, h + 1); if (true) { //buf.applyClipping(dstrect, srcrect)) { int x0 = srcrect.left; @@ -737,9 +736,6 @@ class StateDrawable : Drawable { /// load from XML file bool load(string filename) { - import std.file; - import std.string; - try { string s = cast(string)loadResourceBytes(filename); if (!s) { diff --git a/src/dlangui/graphics/xpm/colors.d b/src/dlangui/graphics/xpm/colors.d index 09f07346..4470b9e1 100644 --- a/src/dlangui/graphics/xpm/colors.d +++ b/src/dlangui/graphics/xpm/colors.d @@ -19,7 +19,8 @@ struct XPMPredefinedColor return cmp(name, str); } ///ditto - const int opBinaryRight(string op)(in char[] str) if (op == "<") { + int opBinaryRight(string op)(in char[] str) const + if (op == "<") { return cmp(str, name); } } diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d index c89a917f..70958c61 100644 --- a/src/dlangui/platforms/common/platform.d +++ b/src/dlangui/platforms/common/platform.d @@ -129,7 +129,7 @@ class TimerInfo { protected long _nextTimestamp; protected Widget _targetWidget; - override bool opEquals(Object obj) { + override bool opEquals(Object obj) const { TimerInfo b = cast(TimerInfo)obj; if (!b) return false; @@ -653,7 +653,6 @@ class Window { //Log.d("addTracking ", w.id, " items after: ", _mouseTrackingWidgets.length); } private bool checkRemoveTracking(MouseEvent event) { - import std.algorithm; bool res = false; for(int i = cast(int)_mouseTrackingWidgets.length - 1; i >=0; i--) { Widget w = _mouseTrackingWidgets[i]; diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 95b022f9..83839358 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -1548,7 +1548,6 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction Log.d("text entered: ", event.text); if (readOnly) return true; - dchar ch = event.text[0]; if (replaceMode && _selectionRange.empty && _content[_caretPos.line].length >= _caretPos.pos + event.text.length) { // replace next char(s) TextRange range = _selectionRange; diff --git a/src/dlangui/widgets/lists.d b/src/dlangui/widgets/lists.d index 07768329..f6850264 100644 --- a/src/dlangui/widgets/lists.d +++ b/src/dlangui/widgets/lists.d @@ -909,7 +909,7 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler { if (_scrollPosition < 0) _scrollPosition = 0; if (_needScrollbar) { - if (_orientation == Orientation.Vertical) { + if (_orientation == Orientation.Vertical) { // FIXME: _scrollbar.position = _scrollPosition; } else { _scrollbar.position = _scrollPosition; @@ -1105,7 +1105,7 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler { if (itemEnabled(i)) setHoverItem(i); } - if ((event.button == MouseFlag.LButton || event.button == MouseFlag.RButton)) { + if (event.button == MouseFlag.LButton || event.button == MouseFlag.RButton) { if ((_clickOnButtonDown && event.action == MouseAction.ButtonDown) || (!_clickOnButtonDown && event.action == MouseAction.ButtonUp)) { if (itemEnabled(i)) { itemClicked(i); diff --git a/src/dlangui/widgets/metadata.d b/src/dlangui/widgets/metadata.d index 3789310c..694c0031 100644 --- a/src/dlangui/widgets/metadata.d +++ b/src/dlangui/widgets/metadata.d @@ -39,7 +39,7 @@ WidgetSignalMetadata[] getSignalList(alias T)() { // skip non-public members static if (__traits(getProtection, __traits(getMember, T, m)) == "public") { static if (__traits(compiles, __traits(getMember, T, m).params_t ) && __traits(compiles, __traits(getMember, T, m).return_t)) { - alias typeof(__traits(getMember, T, m)) ti; + alias ti = typeof(__traits(getMember, T, m)); res ~= WidgetSignalMetadata(m, __traits(getMember, T, m).return_t.stringof ~ __traits(getMember, T, m).params_t.stringof, typeid(__traits(getMember, T, m).return_t), diff --git a/src/dlangui/widgets/styles.d b/src/dlangui/widgets/styles.d index 04609b39..24f8426f 100644 --- a/src/dlangui/widgets/styles.d +++ b/src/dlangui/widgets/styles.d @@ -1354,9 +1354,6 @@ bool loadTheme(Theme theme, Element doc, int level = 0) { /// load theme from file bool loadTheme(Theme theme, string resourceId, int level = 0) { - import std.file; - import std.string; - string filename; try { filename = drawableCache.findResource(resourceId); diff --git a/src/dlangui/widgets/tabs.d b/src/dlangui/widgets/tabs.d index 70e06715..e768afbd 100644 --- a/src/dlangui/widgets/tabs.d +++ b/src/dlangui/widgets/tabs.d @@ -222,7 +222,6 @@ class TabItemList { } /// find tab index by id int indexById(string id) const { - import std.algorithm; for (int i = 0; i < _len; i++) { if (_list[i].id.equal(id)) return i; diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index a54f3523..a9162f34 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -799,7 +799,7 @@ class Widget { bool nearY(TabOrderInfo v) { return v.rect.top >= rect.top - NEAR_THRESHOLD && v.rect.top <= rect.top + NEAR_THRESHOLD; } - override int opCmp(Object obj) { + override int opCmp(Object obj) const { TabOrderInfo v = cast(TabOrderInfo)obj; if (tabOrder != 0 && v.tabOrder !=0) { if (tabOrder < v.tabOrder) @@ -832,7 +832,7 @@ class Widget { } return obj1.rect.left < obj2.rect.left; } - override string toString() { + override string toString() const { return widget.id; } }