mirror of https://github.com/buggins/dlangui.git
commit
81f068fc7b
|
@ -1052,8 +1052,9 @@ class EditableContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// inserts count empty lines at specified position
|
/// inserts count empty lines at specified position
|
||||||
protected void insertLines(int start, int count) {
|
protected void insertLines(int start, int count)
|
||||||
assert(count > 0);
|
in { assert(count > 0); }
|
||||||
|
body {
|
||||||
_lines.length += count;
|
_lines.length += count;
|
||||||
_tokenProps.length = _lines.length;
|
_tokenProps.length = _lines.length;
|
||||||
_editMarks.length = _lines.length;
|
_editMarks.length = _lines.length;
|
||||||
|
|
|
@ -29,7 +29,7 @@ module dlangui.core.settings;
|
||||||
import dlangui.core.logger;
|
import dlangui.core.logger;
|
||||||
import dlangui.core.types : parseHexDigit;
|
import dlangui.core.types : parseHexDigit;
|
||||||
import std.range;
|
import std.range;
|
||||||
import std.algorithm : equal;
|
import std.algorithm : clamp, equal;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
import std.utf : encode;
|
import std.utf : encode;
|
||||||
import std.math : pow;
|
import std.math : pow;
|
||||||
|
@ -82,15 +82,12 @@ class SettingsFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int limitInt(long value, int minvalue, int maxvalue) {
|
static int limitInt(long value, int minvalue, int maxvalue) {
|
||||||
if (value < minvalue)
|
return clamp(cast(int)value, minvalue, maxvalue);
|
||||||
return minvalue;
|
|
||||||
else if (value > maxvalue)
|
|
||||||
return maxvalue;
|
|
||||||
return cast(int)value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static string limitString(string value, const string[] values) {
|
static string limitString(string value, const string[] values)
|
||||||
assert(values.length > 0);
|
in { assert(values.length > 0); }
|
||||||
|
body {
|
||||||
foreach(v; values)
|
foreach(v; values)
|
||||||
if (v.equal(value))
|
if (v.equal(value))
|
||||||
return value;
|
return value;
|
||||||
|
|
|
@ -121,12 +121,7 @@ struct Rect {
|
||||||
return right <= left || bottom <= top;
|
return right <= left || bottom <= top;
|
||||||
}
|
}
|
||||||
/// translate rectangle coordinates by (x,y) - add deltax to x coordinates, and deltay to y coordinates
|
/// translate rectangle coordinates by (x,y) - add deltax to x coordinates, and deltay to y coordinates
|
||||||
void moveBy(int deltax, int deltay) {
|
alias moveBy = offset;
|
||||||
left += deltax;
|
|
||||||
right += deltax;
|
|
||||||
top += deltay;
|
|
||||||
bottom += deltay;
|
|
||||||
}
|
|
||||||
/// moves this rect to fit rc bounds, retaining the same size
|
/// moves this rect to fit rc bounds, retaining the same size
|
||||||
void moveToFit(ref Rect rc) {
|
void moveToFit(ref Rect rc) {
|
||||||
if (right > rc.right)
|
if (right > rc.right)
|
||||||
|
@ -175,6 +170,38 @@ struct Rect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// widget state bit flags
|
||||||
|
enum State : uint {
|
||||||
|
/// state not specified / normal
|
||||||
|
Normal = 4 | 256, // Normal is Enabled
|
||||||
|
/// pressed (e.g. clicked by mouse)
|
||||||
|
Pressed = 1,
|
||||||
|
/// widget has focus
|
||||||
|
Focused = 2,
|
||||||
|
/// widget can process mouse and key events
|
||||||
|
Enabled = 4,
|
||||||
|
/// mouse pointer is over this widget
|
||||||
|
Hovered = 8, // mouse pointer is over control, buttons not pressed
|
||||||
|
/// widget is selected
|
||||||
|
Selected = 16,
|
||||||
|
/// widget can be checked
|
||||||
|
Checkable = 32,
|
||||||
|
/// widget is checked
|
||||||
|
Checked = 64,
|
||||||
|
/// widget is activated
|
||||||
|
Activated = 128,
|
||||||
|
/// window is focused
|
||||||
|
WindowFocused = 256,
|
||||||
|
/// widget is default control for form (should be focused when window gains focus first time)
|
||||||
|
Default = 512, // widget is default for form (e.g. default button will be focused on show)
|
||||||
|
/// widget has been focused by keyboard navigation
|
||||||
|
KeyboardFocused = 1024,
|
||||||
|
/// return state of parent instead of widget's state when requested
|
||||||
|
Parent = 0x10000, // use parent's state
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Layout size constants
|
// Layout size constants
|
||||||
/// layout option, to occupy all available place
|
/// layout option, to occupy all available place
|
||||||
enum int FILL_PARENT = 0x4000_0000;
|
enum int FILL_PARENT = 0x4000_0000;
|
||||||
|
@ -418,6 +445,7 @@ struct Ref(T) { // if (T is RefCountedObject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//================================================================================
|
//================================================================================
|
||||||
// some utility functions
|
// some utility functions
|
||||||
|
|
||||||
|
@ -441,38 +469,6 @@ wstring fromWStringz(const(wchar) * s) {
|
||||||
return cast(wstring)(s[0..i].dup);
|
return cast(wstring)(s[0..i].dup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** widget state flags - bits */
|
|
||||||
enum State : uint {
|
|
||||||
/// state not specified / normal
|
|
||||||
Normal = 4 | 256, // Normal is Enabled
|
|
||||||
/// pressed (e.g. clicked by mouse)
|
|
||||||
Pressed = 1,
|
|
||||||
/// widget has focus
|
|
||||||
Focused = 2,
|
|
||||||
/// widget can process mouse and key events
|
|
||||||
Enabled = 4,
|
|
||||||
/// mouse pointer is over this widget
|
|
||||||
Hovered = 8, // mouse pointer is over control, buttons not pressed
|
|
||||||
/// widget is selected
|
|
||||||
Selected = 16,
|
|
||||||
/// widget can be checked
|
|
||||||
Checkable = 32,
|
|
||||||
/// widget is checked
|
|
||||||
Checked = 64,
|
|
||||||
/// widget is activated
|
|
||||||
Activated = 128,
|
|
||||||
/// window is focused
|
|
||||||
WindowFocused = 256,
|
|
||||||
/// widget is default control for form (should be focused when window gains focus first time)
|
|
||||||
Default = 512, // widget is default for form (e.g. default button will be focused on show)
|
|
||||||
/// widget has been focused by keyboard navigation
|
|
||||||
KeyboardFocused = 1024,
|
|
||||||
/// return state of parent instead of widget's state when requested
|
|
||||||
Parent = 0x10000, // use parent's state
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Deprecated: use std.uni.toUpper instead.
|
/** Deprecated: use std.uni.toUpper instead.
|
||||||
Uppercase unicode character.
|
Uppercase unicode character.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -84,12 +84,10 @@ immutable dchar UNICODE_NB_HYPHEN = 0x2011;
|
||||||
struct CustomCharProps {
|
struct CustomCharProps {
|
||||||
uint color;
|
uint color;
|
||||||
uint textFlags;
|
uint textFlags;
|
||||||
this(uint color) {
|
|
||||||
|
this(uint color, bool underline = false, bool strikeThrough = false) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.textFlags = 0;
|
this.textFlags = 0;
|
||||||
}
|
|
||||||
this(uint color, bool underline, bool strikeThrough = false) {
|
|
||||||
this.color = color;
|
|
||||||
if (underline)
|
if (underline)
|
||||||
this.textFlags |= TextFlag.Underline;
|
this.textFlags |= TextFlag.Underline;
|
||||||
if (strikeThrough)
|
if (strikeThrough)
|
||||||
|
@ -726,15 +724,12 @@ class FontManager {
|
||||||
/// get font gamma (1.0 is neutral, < 1.0 makes glyphs lighter, >1.0 makes glyphs bolder)
|
/// get font gamma (1.0 is neutral, < 1.0 makes glyphs lighter, >1.0 makes glyphs bolder)
|
||||||
static @property double fontGamma() { return _fontGamma; }
|
static @property double fontGamma() { return _fontGamma; }
|
||||||
/// set font gamma (1.0 is neutral, < 1.0 makes glyphs lighter, >1.0 makes glyphs bolder)
|
/// set font gamma (1.0 is neutral, < 1.0 makes glyphs lighter, >1.0 makes glyphs bolder)
|
||||||
static @property void fontGamma(double v) {
|
static @property void fontGamma(double v) {
|
||||||
if (v < 0.1)
|
double gamma = clamp(v, 0.1, 4);
|
||||||
v = 0.1;
|
if (_fontGamma != gamma) {
|
||||||
else if (v > 4)
|
_fontGamma = gamma;
|
||||||
v = 4;
|
_gamma65.gamma = gamma;
|
||||||
if (_fontGamma != v) {
|
_gamma256.gamma = gamma;
|
||||||
_fontGamma = v;
|
|
||||||
_gamma65.gamma = v;
|
|
||||||
_gamma256.gamma = v;
|
|
||||||
if (_instance)
|
if (_instance)
|
||||||
_instance.clearGlyphCaches();
|
_instance.clearGlyphCaches();
|
||||||
}
|
}
|
||||||
|
@ -767,7 +762,7 @@ struct GlyphCache
|
||||||
private glyph_ptr[][1024] _glyphs;
|
private glyph_ptr[][1024] _glyphs;
|
||||||
|
|
||||||
/// try to find glyph for character in cache, returns null if not found
|
/// try to find glyph for character in cache, returns null if not found
|
||||||
Glyph * find(dchar ch) {
|
glyph_ptr find(dchar ch) {
|
||||||
ch = ch & 0xF_FFFF;
|
ch = ch & 0xF_FFFF;
|
||||||
//if (_array is null)
|
//if (_array is null)
|
||||||
// _array = new Glyph[0x10000];
|
// _array = new Glyph[0x10000];
|
||||||
|
@ -776,7 +771,7 @@ struct GlyphCache
|
||||||
if (row is null)
|
if (row is null)
|
||||||
return null;
|
return null;
|
||||||
uint i = ch & 0xFF;
|
uint i = ch & 0xFF;
|
||||||
Glyph * res = row[i];
|
glyph_ptr res = row[i];
|
||||||
if (!res)
|
if (!res)
|
||||||
return null;
|
return null;
|
||||||
res.lastUsage = 1;
|
res.lastUsage = 1;
|
||||||
|
@ -784,7 +779,7 @@ struct GlyphCache
|
||||||
}
|
}
|
||||||
|
|
||||||
/// put character glyph to cache
|
/// put character glyph to cache
|
||||||
Glyph * put(dchar ch, Glyph * glyph) {
|
glyph_ptr put(dchar ch, glyph_ptr glyph) {
|
||||||
ch = ch & 0xF_FFFF;
|
ch = ch & 0xF_FFFF;
|
||||||
uint p = ch >> 8;
|
uint p = ch >> 8;
|
||||||
uint i = ch & 0xFF;
|
uint i = ch & 0xFF;
|
||||||
|
@ -868,13 +863,9 @@ class glyph_gamma_table(int maxv = 65)
|
||||||
{
|
{
|
||||||
double v = (maxv - 1.0 - i) / maxv;
|
double v = (maxv - 1.0 - i) / maxv;
|
||||||
v = pow(v, g);
|
v = pow(v, g);
|
||||||
int n = cast(int)round(v * 255);
|
int n = 255 - cast(int)round(v * 255);
|
||||||
n = 255 - n;
|
ubyte n_clamp = cast(ubyte)clamp(n, 0, 255);
|
||||||
if (n < 0)
|
_map[i] = n_clamp;
|
||||||
n = 0;
|
|
||||||
else if (n > 255)
|
|
||||||
n = 255;
|
|
||||||
_map[i] = cast(ubyte)n;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// correct byte value from source range to 0..255 applying gamma
|
/// correct byte value from source range to 0..255 applying gamma
|
||||||
|
|
|
@ -34,29 +34,26 @@ int stdFontFacePriority(string face) {
|
||||||
//debug = FontResources;
|
//debug = FontResources;
|
||||||
|
|
||||||
private struct FontDef {
|
private struct FontDef {
|
||||||
immutable FontFamily _family;
|
immutable FontFamily family;
|
||||||
immutable string _face;
|
immutable string face;
|
||||||
immutable bool _italic;
|
immutable bool italic;
|
||||||
immutable int _weight;
|
immutable int weight;
|
||||||
@property FontFamily family() { return _family; }
|
|
||||||
@property string face() { return _face; }
|
|
||||||
@property bool italic() { return _italic; }
|
|
||||||
@property int weight() { return _weight; }
|
|
||||||
this(FontFamily family, string face, bool italic, int weight) {
|
this(FontFamily family, string face, bool italic, int weight) {
|
||||||
_family = family;
|
this.family = family;
|
||||||
_face = face;
|
this.face = face;
|
||||||
_italic = italic;
|
this.italic = italic;
|
||||||
_weight = weight;
|
this.weight = weight;
|
||||||
}
|
}
|
||||||
bool opEquals(ref const FontDef v) const {
|
bool opEquals(ref const FontDef v) const {
|
||||||
return _family == v._family && _italic == v._italic && _weight == v._weight && _face.equal(v._face);
|
return family == v.family && italic == v.italic && weight == v.weight && face.equal(v.face);
|
||||||
}
|
}
|
||||||
hash_t toHash() const nothrow @safe {
|
hash_t toHash() const nothrow @safe {
|
||||||
hash_t res = 123;
|
hash_t res = 123;
|
||||||
res = res * 31 + cast(hash_t)_italic;
|
res = res * 31 + cast(hash_t)italic;
|
||||||
res = res * 31 + cast(hash_t)_weight;
|
res = res * 31 + cast(hash_t)weight;
|
||||||
res = res * 31 + cast(hash_t)_family;
|
res = res * 31 + cast(hash_t)family;
|
||||||
res = res * 31 + typeid(_face).getHash(&_face);
|
res = res * 31 + typeid(face).getHash(&face);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue