From ef837c1ffcffc290617af662cbde024949b305c1 Mon Sep 17 00:00:00 2001 From: gazer Date: Sun, 20 Dec 2015 18:41:52 +0300 Subject: [PATCH] clear some code --- src/dlangui/core/types.d | 12 ++-- src/dlangui/graphics/gldrawbuf.d | 88 +++++++++++++-------------- src/dlangui/package.d | 66 ++++++++++---------- src/dlangui/widgets/styles.d | 101 ++++++++++++++++--------------- src/dlangui/widgets/widget.d | 83 ++++++++++--------------- 5 files changed, 168 insertions(+), 182 deletions(-) diff --git a/src/dlangui/core/types.d b/src/dlangui/core/types.d index 38e8256d..9f12cbb4 100644 --- a/src/dlangui/core/types.d +++ b/src/dlangui/core/types.d @@ -177,16 +177,16 @@ struct Rect { // Layout size constants /// layout option, to occupy all available place -immutable int FILL_PARENT = 0x4000_0000; +enum int FILL_PARENT = 0x4000_0000; /// layout option, for size based on content -immutable int WRAP_CONTENT = 0x2000_0000; +enum int WRAP_CONTENT = 0x2000_0000; /// use as widget.layout() param to avoid applying of parent size -immutable int SIZE_UNSPECIFIED = 0x6000_0000; +enum int SIZE_UNSPECIFIED = 0x6000_0000; /// use in styles to specify size in points (1/72 inch) -immutable int SIZE_IN_POINTS_FLAG = 0x1000_0000; +enum int SIZE_IN_POINTS_FLAG = 0x1000_0000; /// (RESERVED) use in styles to specify size in percents * 100 (e.g. 0 == 0%, 10000 == 100%, 100 = 1%) -immutable int SIZE_IN_PERCENTS_FLAG = 0x0800_0000; +enum int SIZE_IN_PERCENTS_FLAG = 0x0800_0000; /// convert custom size to pixels (sz can be either pixels, or points if SIZE_IN_POINTS_FLAG bit set) @@ -257,7 +257,7 @@ private __gshared int PRIVATE_SCREEN_DPI = 96; } /// one point is 1/72 of inch -immutable int POINTS_PER_INCH = 72; +enum POINTS_PER_INCH = 72; /// convert points (1/72in units) to pixels according to SCREEN_DPI int pointsToPixels(int pt) { diff --git a/src/dlangui/graphics/gldrawbuf.d b/src/dlangui/graphics/gldrawbuf.d index 6b2c008b..9bf3f496 100644 --- a/src/dlangui/graphics/gldrawbuf.d +++ b/src/dlangui/graphics/gldrawbuf.d @@ -244,8 +244,8 @@ bool hasActiveScene() { return activeSceneCount > 0; } -immutable int MIN_TEX_SIZE = 64; -immutable int MAX_TEX_SIZE = 4096; +enum MIN_TEX_SIZE = 64; +enum MAX_TEX_SIZE = 4096; private int nearestPOT(int n) { for (int i = MIN_TEX_SIZE; i <= MAX_TEX_SIZE; i *= 2) { if (n <= i) @@ -265,7 +265,6 @@ void onGlyphDestroyedCallback(uint pobject) { } private __gshared GLImageCache glImageCache; - private __gshared GLGlyphCache glGlyphCache; shared static this() { @@ -569,40 +568,7 @@ private class GLImageCache { onCachedObjectDeleted(list[i]); } } -}; - - - -private class TextureSceneItem : SceneItem { - private uint objectId; - //CacheableObject * img; - private Rect dstrc; - private Rect srcrc; - private uint color; - private uint options; - private Rect * clip; - private int rotationAngle; - - override void draw() { - if (glImageCache) - glImageCache.drawItem(objectId, dstrc, srcrc, color, options, clip, rotationAngle); - } - - this(uint _objectId, Rect _dstrc, Rect _srcrc, uint _color, uint _options, Rect * _clip, int _rotationAngle) - { - objectId = _objectId; - dstrc = _dstrc; - srcrc = _srcrc; - color = _color; - options = _options; - clip = _clip; - rotationAngle = _rotationAngle; - } - - ~this() { - } -}; - +} private class GLGlyphCache { @@ -853,17 +819,19 @@ private class GLGlyphCache { onCachedObjectDeleted(list[i]); } } -}; +} - -class LineSceneItem : SceneItem { +private class LineSceneItem : SceneItem { +private: Point _p1; Point _p2; uint _color; + +public: this(Point p1, Point p2, uint color) { _p1 = p1; _p2 = p2; @@ -874,10 +842,12 @@ class LineSceneItem : SceneItem { } } - -class SolidRectSceneItem : SceneItem { +private class SolidRectSceneItem : SceneItem { +private: Rect _rc; uint _color; + +public: this(Rect rc, uint color) { _rc = rc; _color = color; @@ -887,12 +857,43 @@ class SolidRectSceneItem : SceneItem { } } +private class TextureSceneItem : SceneItem { +private: + uint objectId; + //CacheableObject * img; + Rect dstrc; + Rect srcrc; + uint color; + uint options; + Rect * clip; + int rotationAngle; + +public: + override void draw() { + if (glImageCache) + glImageCache.drawItem(objectId, dstrc, srcrc, color, options, clip, rotationAngle); + } + + this(uint _objectId, Rect _dstrc, Rect _srcrc, uint _color, uint _options, Rect * _clip, int _rotationAngle) + { + objectId = _objectId; + dstrc = _dstrc; + srcrc = _srcrc; + color = _color; + options = _options; + clip = _clip; + rotationAngle = _rotationAngle; + } +} + private class GlyphSceneItem : SceneItem { +private: uint objectId; Rect dstrc; Rect srcrc; uint color; Rect * clip; + public: override void draw() { if (glGlyphCache) @@ -906,8 +907,6 @@ public: color = _color; clip = _clip; } - ~this() { - } } private class CustomDrawnSceneItem : SceneItem { @@ -915,6 +914,7 @@ private: DrawBuf _buf; Rect _rc; OpenGLDrawableDelegate _handler; + public: this(DrawBuf buf, Rect rc, OpenGLDrawableDelegate handler) { _buf = buf; diff --git a/src/dlangui/package.d b/src/dlangui/package.d index a592a24e..8a1dbcb8 100644 --- a/src/dlangui/package.d +++ b/src/dlangui/package.d @@ -46,36 +46,38 @@ Authors: Vadim Lopatin, coolreader.org@gmail.com */ module dlangui; -public import dlangui.core.logger; -public import dlangui.core.types; -public import dlangui.core.i18n; -public import dlangui.core.files; -public import dlangui.core.stdaction; -public import dlangui.graphics.images; -public import dlangui.graphics.colors; -public import dlangui.graphics.fonts; -public import dlangui.graphics.drawbuf; -public import dlangui.widgets.widget; -public import dlangui.widgets.controls; -public import dlangui.widgets.layouts; -public import dlangui.widgets.lists; -public import dlangui.widgets.tabs; -public import dlangui.widgets.menu; -public import dlangui.widgets.scroll; -public import dlangui.widgets.editors; -public import dlangui.widgets.srcedit; -public import dlangui.widgets.grid; -public import dlangui.widgets.tree; -public import dlangui.widgets.combobox; -public import dlangui.widgets.popup; -public import dlangui.widgets.appframe; -public import dlangui.widgets.statusline; -public import dlangui.widgets.docks; -public import dlangui.widgets.toolbars; -public import dlangui.platforms.common.platform; -public import dlangui.dml.parser; +public { + import dlangui.core.logger; + import dlangui.core.types; + import dlangui.core.i18n; + import dlangui.core.files; + import dlangui.core.stdaction; + import dlangui.graphics.images; + import dlangui.graphics.colors; + import dlangui.graphics.fonts; + import dlangui.graphics.drawbuf; + import dlangui.widgets.widget; + import dlangui.widgets.controls; + import dlangui.widgets.layouts; + import dlangui.widgets.lists; + import dlangui.widgets.tabs; + import dlangui.widgets.menu; + import dlangui.widgets.scroll; + import dlangui.widgets.editors; + import dlangui.widgets.srcedit; + import dlangui.widgets.grid; + import dlangui.widgets.tree; + import dlangui.widgets.combobox; + import dlangui.widgets.popup; + import dlangui.widgets.appframe; + import dlangui.widgets.statusline; + import dlangui.widgets.docks; + import dlangui.widgets.toolbars; + import dlangui.platforms.common.platform; + import dlangui.dml.parser; -// some useful imports from Phobos -public import std.algorithm : equal; -public import std.conv : to; -public import std.utf : toUTF32, toUTF8; + // some useful imports from Phobos + import std.algorithm : equal; + import std.conv : to; + import std.utf : toUTF32, toUTF8; +} diff --git a/src/dlangui/widgets/styles.d b/src/dlangui/widgets/styles.d index 24f8426f..9b032797 100644 --- a/src/dlangui/widgets/styles.d +++ b/src/dlangui/widgets/styles.d @@ -189,23 +189,23 @@ immutable string STYLE_COLOR_DIALOG_BACKGROUND = "dialog_background"; // Other style constants /// unspecified align - to take parent's value instead -immutable ubyte ALIGN_UNSPECIFIED = 0; +enum ubyte ALIGN_UNSPECIFIED = 0; /// unspecified font size constant - to take parent style property value -immutable ushort FONT_SIZE_UNSPECIFIED = 0xFFFF; +enum ushort FONT_SIZE_UNSPECIFIED = 0xFFFF; /// unspecified font weight constant - to take parent style property value -immutable ushort FONT_WEIGHT_UNSPECIFIED = 0x0000; +enum ushort FONT_WEIGHT_UNSPECIFIED = 0x0000; /// unspecified font style constant - to take parent style property value -immutable ubyte FONT_STYLE_UNSPECIFIED = 0xFF; +enum ubyte FONT_STYLE_UNSPECIFIED = 0xFF; /// normal font style constant -immutable ubyte FONT_STYLE_NORMAL = 0x00; +enum ubyte FONT_STYLE_NORMAL = 0x00; /// italic font style constant -immutable ubyte FONT_STYLE_ITALIC = 0x01; +enum ubyte FONT_STYLE_ITALIC = 0x01; /// use text flags from parent style -immutable uint TEXT_FLAGS_UNSPECIFIED = uint.max; +enum uint TEXT_FLAGS_UNSPECIFIED = uint.max; /// use text flags from parent widget -immutable uint TEXT_FLAGS_USE_PARENT = uint.max - 1; +enum uint TEXT_FLAGS_USE_PARENT = uint.max - 1; /// to take layout weight from parent -immutable int WEIGHT_UNSPECIFIED = -1; +enum int WEIGHT_UNSPECIFIED = -1; /// Align option bit constants enum Align : ubyte { @@ -245,46 +245,48 @@ enum TextFlag : uint { /// style properties class Style { - protected string _id; - protected Theme _theme; - protected Style _parentStyle; - protected string _parentId; - protected uint _stateMask; - protected uint _stateValue; - protected ubyte _align = Align.TopLeft; - protected ubyte _fontStyle = FONT_STYLE_UNSPECIFIED; - protected FontFamily _fontFamily = FontFamily.Unspecified; - protected ushort _fontWeight = FONT_WEIGHT_UNSPECIFIED; - protected int _fontSize = FONT_SIZE_UNSPECIFIED; - protected uint _backgroundColor = COLOR_UNSPECIFIED; - protected uint _textColor = COLOR_UNSPECIFIED; - protected uint _textFlags = 0; - protected uint _alpha; - protected string _fontFace; - protected string _backgroundImageId; - protected Rect _padding; - protected Rect _margins; - protected int _minWidth = SIZE_UNSPECIFIED; - protected int _maxWidth = SIZE_UNSPECIFIED; - protected int _minHeight = SIZE_UNSPECIFIED; - protected int _maxHeight = SIZE_UNSPECIFIED; - protected int _layoutWidth = SIZE_UNSPECIFIED; - protected int _layoutHeight = SIZE_UNSPECIFIED; - protected int _layoutWeight = WEIGHT_UNSPECIFIED; - protected int _maxLines = SIZE_UNSPECIFIED; +protected: + string _id; + Theme _theme; + Style _parentStyle; + string _parentId; + uint _stateMask; + uint _stateValue; + ubyte _align = Align.TopLeft; + ubyte _fontStyle = FONT_STYLE_UNSPECIFIED; + FontFamily _fontFamily = FontFamily.Unspecified; + ushort _fontWeight = FONT_WEIGHT_UNSPECIFIED; + int _fontSize = FONT_SIZE_UNSPECIFIED; + uint _backgroundColor = COLOR_UNSPECIFIED; + uint _textColor = COLOR_UNSPECIFIED; + uint _textFlags = 0; + uint _alpha; + string _fontFace; + string _backgroundImageId; + Rect _padding; + Rect _margins; + int _minWidth = SIZE_UNSPECIFIED; + int _maxWidth = SIZE_UNSPECIFIED; + int _minHeight = SIZE_UNSPECIFIED; + int _maxHeight = SIZE_UNSPECIFIED; + int _layoutWidth = SIZE_UNSPECIFIED; + int _layoutHeight = SIZE_UNSPECIFIED; + int _layoutWeight = WEIGHT_UNSPECIFIED; + int _maxLines = SIZE_UNSPECIFIED; - protected uint[] _focusRectColors; + uint[] _focusRectColors; - protected Style[] _substates; - protected Style[] _children; + Style[] _substates; + Style[] _children; - protected DrawableAttribute[string] _customDrawables; - protected uint[string] _customColors; - protected uint[string] _customLength; + DrawableAttribute[string] _customDrawables; + uint[string] _customColors; + uint[string] _customLength; - protected FontRef _font; - protected DrawableRef _backgroundDrawable; + FontRef _font; + DrawableRef _backgroundDrawable; +public: void onThemeChanged() { _backgroundDrawable.clear(); foreach(s; _substates) @@ -1391,10 +1393,13 @@ Theme loadTheme(string resourceId) { /// custom drawable attribute container for styles class DrawableAttribute { - protected string _id; - protected string _drawableId; - protected DrawableRef _drawable; - protected bool _initialized; +protected: + string _id; + string _drawableId; + DrawableRef _drawable; + bool _initialized; + +public: this(string id, string drawableId) { _id = id; _drawableId = drawableId; diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index 64800651..f74cd221 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -35,21 +35,23 @@ Authors: Vadim Lopatin, coolreader.org@gmail.com */ module dlangui.widgets.widget; -public import dlangui.core.types; -public import dlangui.core.events; -public import dlangui.core.i18n; -public import dlangui.core.collections; -public import dlangui.widgets.styles; +public { + import dlangui.core.types; + import dlangui.core.events; + import dlangui.core.i18n; + import dlangui.core.collections; + import dlangui.widgets.styles; -public import dlangui.graphics.drawbuf; -public import dlangui.graphics.resources; -public import dlangui.graphics.fonts; -public import dlangui.graphics.colors; + import dlangui.graphics.drawbuf; + import dlangui.graphics.resources; + import dlangui.graphics.fonts; + import dlangui.graphics.colors; -public import dlangui.core.signals; + import dlangui.core.signals; -public import dlangui.platforms.common.platform; -public import dlangui.dml.annotations; + import dlangui.platforms.common.platform; + import dlangui.dml.annotations; +} import std.algorithm; @@ -137,36 +139,38 @@ enum CursorType { */ @dmlwidget class Widget { +protected: /// widget id - protected string _id; + string _id; /// current widget position, set by layout() - protected Rect _pos; + Rect _pos; /// widget visibility: either Visible, Invisible, Gone - protected Visibility _visibility = Visibility.Visible; // visible by default + Visibility _visibility = Visibility.Visible; // visible by default /// style id to lookup style in theme - protected string _styleId; + string _styleId; /// own copy of style - to override some of style properties, null of no properties overriden - protected Style _ownStyle; + Style _ownStyle; /// widget state (set of flags from State enum) - protected uint _state; + uint _state; /// width measured by measure() - protected int _measuredWidth; + int _measuredWidth; /// height measured by measure() - protected int _measuredHeight; + int _measuredHeight; /// true to force layout - protected bool _needLayout = true; + bool _needLayout = true; /// true to force redraw - protected bool _needDraw = true; + bool _needDraw = true; /// parent widget - protected Widget _parent; + Widget _parent; /// window (to be used for top level widgets only!) - protected Window _window; + Window _window; /// does widget need to track mouse Hover - protected bool _trackHover; + bool _trackHover; +public: /// mouse movement processing flag (when true, widget will change Hover state while mouse is moving) @property bool trackHover() const { return _trackHover; } /// set new trackHover flag value (when true, widget will change Hover state while mouse is moving) @@ -1457,31 +1461,8 @@ class Widget { return false; } - /// find child by id, returns null if not found - Widget childById(string id, bool deepSearch = true) { - if (deepSearch) { - // search everywhere inside child tree - if (compareId(id)) - return this; - // lookup children - for (int i = childCount - 1; i >= 0; i--) { - Widget res = child(i).childById(id); - if (res !is null) - return res; - } - } else { - // search only across children of this widget - for (int i = childCount - 1; i >= 0; i--) { - if (id.equal(child(i).id)) - return child(i); - } - } - // not found - return null; - } - /// find child of specified type T by id, returns null if not found or cannot be converted to type T - T childById(T)(string id, bool deepSearch = true) { + T childById(T = typeof(this))(string id, bool deepSearch = true) { if (deepSearch) { // search everywhere inside child tree if (compareId(id)) { @@ -1690,14 +1671,12 @@ class WidgetGroupDefaultDrawing : WidgetGroup { auto saver = ClipRectSaver(buf, rc); for (int i = 0; i < _children.count; i++) { Widget item = _children.get(i); - if (item.visibility != Visibility.Visible) - continue; item.onDraw(buf); } } } -immutable long ONE_SECOND = 10_000_000L; +enum ONE_SECOND = 10_000_000L; /// Helper to handle animation progress struct AnimationHelper {