Merge pull request #129 from g4z3r/codestyle

clear some code
This commit is contained in:
Vadim Lopatin 2015-12-21 07:03:49 +03:00
commit 3027f6a588
5 changed files with 168 additions and 182 deletions

View File

@ -177,16 +177,16 @@ struct Rect {
// Layout size constants // Layout size constants
/// layout option, to occupy all available place /// 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 /// 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 /// 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) /// 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%) /// (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) /// 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 /// 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 /// convert points (1/72in units) to pixels according to SCREEN_DPI
int pointsToPixels(int pt) { int pointsToPixels(int pt) {

View File

@ -244,8 +244,8 @@ bool hasActiveScene() {
return activeSceneCount > 0; return activeSceneCount > 0;
} }
immutable int MIN_TEX_SIZE = 64; enum MIN_TEX_SIZE = 64;
immutable int MAX_TEX_SIZE = 4096; enum MAX_TEX_SIZE = 4096;
private int nearestPOT(int n) { private int nearestPOT(int n) {
for (int i = MIN_TEX_SIZE; i <= MAX_TEX_SIZE; i *= 2) { for (int i = MIN_TEX_SIZE; i <= MAX_TEX_SIZE; i *= 2) {
if (n <= i) if (n <= i)
@ -265,7 +265,6 @@ void onGlyphDestroyedCallback(uint pobject) {
} }
private __gshared GLImageCache glImageCache; private __gshared GLImageCache glImageCache;
private __gshared GLGlyphCache glGlyphCache; private __gshared GLGlyphCache glGlyphCache;
shared static this() { shared static this() {
@ -569,41 +568,8 @@ private class GLImageCache {
onCachedObjectDeleted(list[i]); 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 { private class GLGlyphCache {
static class GLGlyphCacheItem { static class GLGlyphCacheItem {
@ -853,17 +819,19 @@ private class GLGlyphCache {
onCachedObjectDeleted(list[i]); onCachedObjectDeleted(list[i]);
} }
} }
}; }
private class LineSceneItem : SceneItem {
class LineSceneItem : SceneItem { private:
Point _p1; Point _p1;
Point _p2; Point _p2;
uint _color; uint _color;
public:
this(Point p1, Point p2, uint color) { this(Point p1, Point p2, uint color) {
_p1 = p1; _p1 = p1;
_p2 = p2; _p2 = p2;
@ -874,10 +842,12 @@ class LineSceneItem : SceneItem {
} }
} }
private class SolidRectSceneItem : SceneItem {
class SolidRectSceneItem : SceneItem { private:
Rect _rc; Rect _rc;
uint _color; uint _color;
public:
this(Rect rc, uint color) { this(Rect rc, uint color) {
_rc = rc; _rc = rc;
_color = color; _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 class GlyphSceneItem : SceneItem {
private:
uint objectId; uint objectId;
Rect dstrc; Rect dstrc;
Rect srcrc; Rect srcrc;
uint color; uint color;
Rect * clip; Rect * clip;
public: public:
override void draw() { override void draw() {
if (glGlyphCache) if (glGlyphCache)
@ -906,8 +907,6 @@ public:
color = _color; color = _color;
clip = _clip; clip = _clip;
} }
~this() {
}
} }
private class CustomDrawnSceneItem : SceneItem { private class CustomDrawnSceneItem : SceneItem {
@ -915,6 +914,7 @@ private:
DrawBuf _buf; DrawBuf _buf;
Rect _rc; Rect _rc;
OpenGLDrawableDelegate _handler; OpenGLDrawableDelegate _handler;
public: public:
this(DrawBuf buf, Rect rc, OpenGLDrawableDelegate handler) { this(DrawBuf buf, Rect rc, OpenGLDrawableDelegate handler) {
_buf = buf; _buf = buf;

View File

@ -46,36 +46,38 @@ Authors: Vadim Lopatin, coolreader.org@gmail.com
*/ */
module dlangui; module dlangui;
public import dlangui.core.logger; public {
public import dlangui.core.types; import dlangui.core.logger;
public import dlangui.core.i18n; import dlangui.core.types;
public import dlangui.core.files; import dlangui.core.i18n;
public import dlangui.core.stdaction; import dlangui.core.files;
public import dlangui.graphics.images; import dlangui.core.stdaction;
public import dlangui.graphics.colors; import dlangui.graphics.images;
public import dlangui.graphics.fonts; import dlangui.graphics.colors;
public import dlangui.graphics.drawbuf; import dlangui.graphics.fonts;
public import dlangui.widgets.widget; import dlangui.graphics.drawbuf;
public import dlangui.widgets.controls; import dlangui.widgets.widget;
public import dlangui.widgets.layouts; import dlangui.widgets.controls;
public import dlangui.widgets.lists; import dlangui.widgets.layouts;
public import dlangui.widgets.tabs; import dlangui.widgets.lists;
public import dlangui.widgets.menu; import dlangui.widgets.tabs;
public import dlangui.widgets.scroll; import dlangui.widgets.menu;
public import dlangui.widgets.editors; import dlangui.widgets.scroll;
public import dlangui.widgets.srcedit; import dlangui.widgets.editors;
public import dlangui.widgets.grid; import dlangui.widgets.srcedit;
public import dlangui.widgets.tree; import dlangui.widgets.grid;
public import dlangui.widgets.combobox; import dlangui.widgets.tree;
public import dlangui.widgets.popup; import dlangui.widgets.combobox;
public import dlangui.widgets.appframe; import dlangui.widgets.popup;
public import dlangui.widgets.statusline; import dlangui.widgets.appframe;
public import dlangui.widgets.docks; import dlangui.widgets.statusline;
public import dlangui.widgets.toolbars; import dlangui.widgets.docks;
public import dlangui.platforms.common.platform; import dlangui.widgets.toolbars;
public import dlangui.dml.parser; import dlangui.platforms.common.platform;
import dlangui.dml.parser;
// some useful imports from Phobos // some useful imports from Phobos
public import std.algorithm : equal; import std.algorithm : equal;
public import std.conv : to; import std.conv : to;
public import std.utf : toUTF32, toUTF8; import std.utf : toUTF32, toUTF8;
}

View File

@ -189,23 +189,23 @@ immutable string STYLE_COLOR_DIALOG_BACKGROUND = "dialog_background";
// Other style constants // Other style constants
/// unspecified align - to take parent's value instead /// 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 /// 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 /// 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 /// 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 /// normal font style constant
immutable ubyte FONT_STYLE_NORMAL = 0x00; enum ubyte FONT_STYLE_NORMAL = 0x00;
/// italic font style constant /// italic font style constant
immutable ubyte FONT_STYLE_ITALIC = 0x01; enum ubyte FONT_STYLE_ITALIC = 0x01;
/// use text flags from parent style /// 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 /// 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 /// to take layout weight from parent
immutable int WEIGHT_UNSPECIFIED = -1; enum int WEIGHT_UNSPECIFIED = -1;
/// Align option bit constants /// Align option bit constants
enum Align : ubyte { enum Align : ubyte {
@ -245,46 +245,48 @@ enum TextFlag : uint {
/// style properties /// style properties
class Style { class Style {
protected string _id; protected:
protected Theme _theme; string _id;
protected Style _parentStyle; Theme _theme;
protected string _parentId; Style _parentStyle;
protected uint _stateMask; string _parentId;
protected uint _stateValue; uint _stateMask;
protected ubyte _align = Align.TopLeft; uint _stateValue;
protected ubyte _fontStyle = FONT_STYLE_UNSPECIFIED; ubyte _align = Align.TopLeft;
protected FontFamily _fontFamily = FontFamily.Unspecified; ubyte _fontStyle = FONT_STYLE_UNSPECIFIED;
protected ushort _fontWeight = FONT_WEIGHT_UNSPECIFIED; FontFamily _fontFamily = FontFamily.Unspecified;
protected int _fontSize = FONT_SIZE_UNSPECIFIED; ushort _fontWeight = FONT_WEIGHT_UNSPECIFIED;
protected uint _backgroundColor = COLOR_UNSPECIFIED; int _fontSize = FONT_SIZE_UNSPECIFIED;
protected uint _textColor = COLOR_UNSPECIFIED; uint _backgroundColor = COLOR_UNSPECIFIED;
protected uint _textFlags = 0; uint _textColor = COLOR_UNSPECIFIED;
protected uint _alpha; uint _textFlags = 0;
protected string _fontFace; uint _alpha;
protected string _backgroundImageId; string _fontFace;
protected Rect _padding; string _backgroundImageId;
protected Rect _margins; Rect _padding;
protected int _minWidth = SIZE_UNSPECIFIED; Rect _margins;
protected int _maxWidth = SIZE_UNSPECIFIED; int _minWidth = SIZE_UNSPECIFIED;
protected int _minHeight = SIZE_UNSPECIFIED; int _maxWidth = SIZE_UNSPECIFIED;
protected int _maxHeight = SIZE_UNSPECIFIED; int _minHeight = SIZE_UNSPECIFIED;
protected int _layoutWidth = SIZE_UNSPECIFIED; int _maxHeight = SIZE_UNSPECIFIED;
protected int _layoutHeight = SIZE_UNSPECIFIED; int _layoutWidth = SIZE_UNSPECIFIED;
protected int _layoutWeight = WEIGHT_UNSPECIFIED; int _layoutHeight = SIZE_UNSPECIFIED;
protected int _maxLines = SIZE_UNSPECIFIED; int _layoutWeight = WEIGHT_UNSPECIFIED;
int _maxLines = SIZE_UNSPECIFIED;
protected uint[] _focusRectColors; uint[] _focusRectColors;
protected Style[] _substates; Style[] _substates;
protected Style[] _children; Style[] _children;
protected DrawableAttribute[string] _customDrawables; DrawableAttribute[string] _customDrawables;
protected uint[string] _customColors; uint[string] _customColors;
protected uint[string] _customLength; uint[string] _customLength;
protected FontRef _font; FontRef _font;
protected DrawableRef _backgroundDrawable; DrawableRef _backgroundDrawable;
public:
void onThemeChanged() { void onThemeChanged() {
_backgroundDrawable.clear(); _backgroundDrawable.clear();
foreach(s; _substates) foreach(s; _substates)
@ -1391,10 +1393,13 @@ Theme loadTheme(string resourceId) {
/// custom drawable attribute container for styles /// custom drawable attribute container for styles
class DrawableAttribute { class DrawableAttribute {
protected string _id; protected:
protected string _drawableId; string _id;
protected DrawableRef _drawable; string _drawableId;
protected bool _initialized; DrawableRef _drawable;
bool _initialized;
public:
this(string id, string drawableId) { this(string id, string drawableId) {
_id = id; _id = id;
_drawableId = drawableId; _drawableId = drawableId;

View File

@ -35,21 +35,23 @@ Authors: Vadim Lopatin, coolreader.org@gmail.com
*/ */
module dlangui.widgets.widget; module dlangui.widgets.widget;
public import dlangui.core.types; public {
public import dlangui.core.events; import dlangui.core.types;
public import dlangui.core.i18n; import dlangui.core.events;
public import dlangui.core.collections; import dlangui.core.i18n;
public import dlangui.widgets.styles; import dlangui.core.collections;
import dlangui.widgets.styles;
public import dlangui.graphics.drawbuf; import dlangui.graphics.drawbuf;
public import dlangui.graphics.resources; import dlangui.graphics.resources;
public import dlangui.graphics.fonts; import dlangui.graphics.fonts;
public import dlangui.graphics.colors; import dlangui.graphics.colors;
public import dlangui.core.signals; import dlangui.core.signals;
public import dlangui.platforms.common.platform; import dlangui.platforms.common.platform;
public import dlangui.dml.annotations; import dlangui.dml.annotations;
}
import std.algorithm; import std.algorithm;
@ -137,36 +139,38 @@ enum CursorType {
*/ */
@dmlwidget @dmlwidget
class Widget { class Widget {
protected:
/// widget id /// widget id
protected string _id; string _id;
/// current widget position, set by layout() /// current widget position, set by layout()
protected Rect _pos; Rect _pos;
/// widget visibility: either Visible, Invisible, Gone /// 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 /// 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 /// 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) /// widget state (set of flags from State enum)
protected uint _state; uint _state;
/// width measured by measure() /// width measured by measure()
protected int _measuredWidth; int _measuredWidth;
/// height measured by measure() /// height measured by measure()
protected int _measuredHeight; int _measuredHeight;
/// true to force layout /// true to force layout
protected bool _needLayout = true; bool _needLayout = true;
/// true to force redraw /// true to force redraw
protected bool _needDraw = true; bool _needDraw = true;
/// parent widget /// parent widget
protected Widget _parent; Widget _parent;
/// window (to be used for top level widgets only!) /// window (to be used for top level widgets only!)
protected Window _window; Window _window;
/// does widget need to track mouse Hover /// 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) /// mouse movement processing flag (when true, widget will change Hover state while mouse is moving)
@property bool trackHover() const { return _trackHover; } @property bool trackHover() const { return _trackHover; }
/// set new trackHover flag value (when true, widget will change Hover state while mouse is moving) /// set new trackHover flag value (when true, widget will change Hover state while mouse is moving)
@ -1457,31 +1461,8 @@ class Widget {
return false; 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 /// 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) { if (deepSearch) {
// search everywhere inside child tree // search everywhere inside child tree
if (compareId(id)) { if (compareId(id)) {
@ -1690,14 +1671,12 @@ class WidgetGroupDefaultDrawing : WidgetGroup {
auto saver = ClipRectSaver(buf, rc); auto saver = ClipRectSaver(buf, rc);
for (int i = 0; i < _children.count; i++) { for (int i = 0; i < _children.count; i++) {
Widget item = _children.get(i); Widget item = _children.get(i);
if (item.visibility != Visibility.Visible)
continue;
item.onDraw(buf); item.onDraw(buf);
} }
} }
} }
immutable long ONE_SECOND = 10_000_000L; enum ONE_SECOND = 10_000_000L;
/// Helper to handle animation progress /// Helper to handle animation progress
struct AnimationHelper { struct AnimationHelper {