Merge pull request #497 from denizzzka/again_adding_WIDGET_STYLE_CONSOLE

Separates BACKEND_CONSOLE flag and console-style widgets flag, second attempt
This commit is contained in:
Vadim Lopatin 2017-10-24 19:56:07 +03:00 committed by GitHub
commit fcb5565f4c
14 changed files with 91 additions and 76 deletions

View File

@ -70,7 +70,7 @@
{
"name": "external",
"versions": ["USE_EXTERNAL"],
"excludedSourceFiles": ["3rdparty/*"]
"excludedSourceFiles": ["3rdparty/fontconfig/*"]
},
{
"name": "minimal",

View File

@ -10,6 +10,8 @@ version(USE_CONSOLE) {
enum ENABLE_OPENGL = false;
enum ENABLE_FREETYPE = false;
enum BACKEND_CONSOLE = true;
/// Tweaking widgets to console style drawing
enum WIDGET_STYLE_CONSOLE = true;
enum BACKEND_GUI = false;
enum BACKEND_SDL = false;
enum BACKEND_X11 = false;
@ -17,9 +19,15 @@ version(USE_CONSOLE) {
enum BACKEND_WIN32 = false;
enum BACKEND_ANDROID = false;
} else {
version(USE_EXTERNAL) {}
version(USE_EXTERNAL) {
// Use this file to define any enums that is need for the external backend
mixin(import("external_cfg.d"));
}
else
{
enum BACKEND_GUI = true;
enum WIDGET_STYLE_CONSOLE = false;
}
version (NO_FREETYPE) {
enum ENABLE_FREETYPE = false;

View File

@ -315,7 +315,7 @@ private __gshared int PRIVATE_SCREEN_DPI_OVERRIDE = 0;
/// call to disable automatic screen DPI detection, use provided one instead (pass 0 to disable override and use value detected by platform)
@property void overrideScreenDPI(int dpi = 96) {
static if (BACKEND_CONSOLE) {
static if (WIDGET_STYLE_CONSOLE) {
} else {
if ((dpi >= 72 && dpi <= 500) || dpi == 0)
PRIVATE_SCREEN_DPI_OVERRIDE = dpi;
@ -324,7 +324,7 @@ private __gshared int PRIVATE_SCREEN_DPI_OVERRIDE = 0;
/// set screen DPI detected by platform
@property void SCREEN_DPI(int dpi) {
static if (BACKEND_CONSOLE) {
static if (WIDGET_STYLE_CONSOLE) {
PRIVATE_SCREEN_DPI = dpi;
} else {
if (dpi >= 72 && dpi <= 500) {

View File

@ -503,7 +503,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
sz.y = fnt.height;
return sz;
}
if (BACKEND_CONSOLE)
if (WIDGET_STYLE_CONSOLE)
return Point(0, 0);
else {
DrawableRef icon = rowIcon(row);
@ -526,7 +526,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
Align ha = Align.Left;
//if (sz.y < rc.height)
// applyAlign(rc, sz, ha, Align.VCenter);
int offset = BACKEND_CONSOLE ? 0 : 1;
int offset = WIDGET_STYLE_CONSOLE ? 0 : 1;
uint cl = _fileList.textColor;
if (_entries[row].isDir)
cl = style.customColor("file_dialog_dir_name_color", cl);
@ -550,7 +550,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
WidgetListAdapter adapter = new WidgetListAdapter();
foreach(ref RootEntry root; _roots) {
ImageTextButton btn = new ImageTextButton(null, root.icon, root.label);
static if (BACKEND_CONSOLE) btn.margins = Rect(1, 1, 0, 0);
static if (WIDGET_STYLE_CONSOLE) btn.margins = Rect(1, 1, 0, 0);
btn.orientation = Orientation.Vertical;
btn.styleId = STYLE_TRANSPARENT_BUTTON_BACKGROUND;
btn.focusable = false;
@ -715,7 +715,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
override void initialize() {
_roots = getRootPaths() ~ getBookmarkPaths();
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).minWidth(BACKEND_CONSOLE ? 50 : 600);
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).minWidth(WIDGET_STYLE_CONSOLE ? 50 : 600);
//minHeight = 400;
LinearLayout content = new HorizontalLayout("dlgcontent");
@ -725,10 +725,10 @@ class FileDialog : Dialog, CustomGridCellAdapter {
//leftPanel = new VerticalLayout("places");
//leftPanel.addChild(createRootsList());
//leftPanel.layoutHeight(FILL_PARENT).minWidth(BACKEND_CONSOLE ? 7 : 40);
//leftPanel.layoutHeight(FILL_PARENT).minWidth(WIDGET_STYLE_CONSOLE ? 7 : 40);
leftPanel = createRootsList();
leftPanel.minWidth(BACKEND_CONSOLE ? 7 : 40.pointsToPixels);
leftPanel.minWidth(WIDGET_STYLE_CONSOLE ? 7 : 40.pointsToPixels);
rightPanel = new VerticalLayout("main");
rightPanel.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
@ -1161,7 +1161,7 @@ class FileNameEditLine : HorizontalLayout {
super(ID);
_caption = UIString.fromId("TITLE_OPEN_FILE"c).value;
_edFileName = new EditLine("FileNameEditLine_edFileName");
_edFileName.minWidth(BACKEND_CONSOLE ? 16 : 200);
_edFileName.minWidth(WIDGET_STYLE_CONSOLE ? 16 : 200);
_edFileName.layoutWidth = FILL_PARENT;
_btn = new Button("FileNameEditLine_btnFile", "..."d);
_btn.styleId = STYLE_BUTTON_NOMARGINS;

View File

@ -139,7 +139,7 @@ class DummyIconProvider : IconProviderBase
}
}
static if (!BACKEND_CONSOLE) {
static if (!WIDGET_STYLE_CONSOLE) {
version(Windows)
{
import core.sys.windows.windows;
@ -484,28 +484,30 @@ static if (!BACKEND_CONSOLE) {
DrawBufRef getIconFromTheme(string name, string context = null)
{
auto found = name in _cache;
if (found) {
return *found;
}
string iconPath;
try {
if (context.length) {
iconPath = findClosestIcon!(subdir => subdir.context == context)(name, 32, _iconThemes, _baseIconDirs);
} else {
iconPath = findClosestIcon(name, 32, _iconThemes, _baseIconDirs);
static if (!WIDGET_STYLE_CONSOLE) {
auto found = name in _cache;
if (found) {
return *found;
}
string iconPath;
try {
if (context.length) {
iconPath = findClosestIcon!(subdir => subdir.context == context)(name, 32, _iconThemes, _baseIconDirs);
} else {
iconPath = findClosestIcon(name, 32, _iconThemes, _baseIconDirs);
}
} catch(Exception e) {
Log.e("Error while searching for icon", name);
Log.e(e);
}
} catch(Exception e) {
Log.e("Error while searching for icon", name);
Log.e(e);
}
if (iconPath.length) {
auto image = DrawBufRef(loadImage(iconPath));
_cache[name] = image;
return image;
} else {
_cache[name] = DrawBufRef(null);
if (iconPath.length) {
auto image = DrawBufRef(loadImage(iconPath));
_cache[name] = image;
return image;
} else {
_cache[name] = DrawBufRef(null);
}
}
return DrawBufRef(null);
}

View File

@ -216,7 +216,7 @@ EmbeddedResource[] embedResources(string[] resourceNames)() {
/// embed all resources from list
EmbeddedResource[] embedResourcesFromList(string resourceList)() {
static if (BACKEND_CONSOLE) {
static if (WIDGET_STYLE_CONSOLE) {
return embedResources!(splitLines(import("console_" ~ resourceList)))();
} else {
return embedResources!(splitLines(import(resourceList)))();
@ -523,7 +523,7 @@ static uint decodeAngle(string s) {
return ((angle % 360) + 360) % 360;
}
static if (BACKEND_CONSOLE) {
static if (WIDGET_STYLE_CONSOLE) {
/**
Sample format:
{
@ -610,7 +610,7 @@ static Drawable createColorDrawable(string s) {
return new EmptyDrawable(); // invalid format - just return empty drawable
}
static if (BACKEND_CONSOLE) {
static if (WIDGET_STYLE_CONSOLE) {
/**
Text image drawable.
Resource file extension: .tim
@ -630,8 +630,13 @@ static if (BACKEND_CONSOLE) {
{'' ' ' '' bc 0x000080 tc 0xFF0000 ninepatch 1 1 1 1}
*/
abstract class ConsoleDrawBuf : DrawBuf
{
abstract void drawChar(int x, int y, dchar ch, uint color, uint bgcolor);
}
class TextDrawable : Drawable {
import dlangui.platforms.console.consoleapp : ConsoleDrawBuf;
private int _width;
private int _height;
private dchar[] _text;
@ -1541,7 +1546,7 @@ class DrawableCache {
foreach(string path; _resourcePaths) {
string fn;
fn = checkFileName(path, id, ".xml");
if (fn is null && BACKEND_CONSOLE)
if (fn is null && WIDGET_STYLE_CONSOLE)
fn = checkFileName(path, id, ".tim");
if (fn is null)
fn = checkFileName(path, id, ".png");
@ -1601,7 +1606,7 @@ private Drawable makeDrawableFromId(in string id, in bool tiled, ColorTransform
return d;
}
} else if (id.endsWith(".tim") || id.endsWith(".TIM")) {
static if (BACKEND_CONSOLE) {
static if (WIDGET_STYLE_CONSOLE) {
try {
// .tim (text image) drawables support
string s = cast(string)loadResourceBytes(id);
@ -1620,7 +1625,7 @@ private Drawable makeDrawableFromId(in string id, in bool tiled, ColorTransform
return createColorDrawable(id);
} else if (id.startsWith("{")) {
// json in {} with text drawable description
static if (BACKEND_CONSOLE) {
static if (WIDGET_STYLE_CONSOLE) {
return createTextDrawable(id);
}
} else {

View File

@ -1,4 +1,4 @@
module dlangui.platforms.console.consoleapp;
module dlangui.platforms.ansi_console.consoleapp;
public import dlangui.core.config;
static if (BACKEND_CONSOLE):
@ -9,8 +9,8 @@ import dlangui.graphics.drawbuf;
import dlangui.graphics.fonts;
import dlangui.widgets.styles;
import dlangui.widgets.widget;
import dlangui.platforms.console.consolefont;
private import dlangui.platforms.console.dconsole;
import dlangui.platforms.ansi_console.consolefont;
private import dlangui.platforms.ansi_console.dconsole;
class ConsoleWindow : Window {
ConsolePlatform _platform;
@ -84,7 +84,7 @@ class ConsolePlatform : Platform {
@property Console console() { return _console; }
protected ConsoleDrawBuf _drawBuf;
protected ANSIConsoleDrawBuf _drawBuf;
this() {
_console = new Console();
_console.batchMode = true;
@ -95,7 +95,7 @@ class ConsolePlatform : Platform {
_console.init();
_console.setCursorType(ConsoleCursorType.Invisible);
_uiDialogDisplayMode = DialogDisplayMode.allTypesOfDialogsInPopup;
_drawBuf = new ConsoleDrawBuf(_console);
_drawBuf = new ANSIConsoleDrawBuf(_console);
}
~this() {
//Log.d("Destroying console");
@ -279,7 +279,7 @@ class ConsolePlatform : Platform {
}
/// drawing buffer - image container which allows to perform some drawing operations
class ConsoleDrawBuf : DrawBuf {
class ANSIConsoleDrawBuf : ConsoleDrawBuf {
protected Console _console;
@property Console console() { return _console; }
@ -439,7 +439,7 @@ class ConsoleDrawBuf : DrawBuf {
// TODO
}
void drawChar(int x, int y, dchar ch, uint color, uint bgcolor) {
override void drawChar(int x, int y, dchar ch, uint color, uint bgcolor) {
if (x < _clipRect.left || x >= _clipRect.right || y < _clipRect.top || y >= _clipRect.bottom)
return;
ubyte tc = toConsoleColor(color, false);

View File

@ -1,4 +1,4 @@
module dlangui.platforms.console.consolefont;
module dlangui.platforms.ansi_console.consolefont;
public import dlangui.core.config;
@ -129,9 +129,9 @@ class ConsoleFont : Font {
override void drawText(DrawBuf drawBuf, int x, int y, const dchar[] text, uint color, int tabSize = 4, int tabOffset = 0, uint textFlags = 0) {
if (text.length == 0)
return; // nothing to draw - empty text
import dlangui.platforms.console.consoleapp;
import dlangui.platforms.console.dconsole;
ConsoleDrawBuf buf = cast(ConsoleDrawBuf)drawBuf;
import dlangui.platforms.ansi_console.consoleapp;
import dlangui.platforms.ansi_console.dconsole;
ANSIConsoleDrawBuf buf = cast(ANSIConsoleDrawBuf)drawBuf;
if (!buf)
return;
if (_textSizeBuffer.length < text.length)
@ -146,7 +146,7 @@ class ConsoleFont : Font {
bool underline = (textFlags & TextFlag.Underline) != 0;
int underlineHeight = 1;
int underlineY = y + _baseline + underlineHeight * 2;
buf.console.textColor = ConsoleDrawBuf.toConsoleColor(color);
buf.console.textColor = ANSIConsoleDrawBuf.toConsoleColor(color);
buf.console.backgroundColor = CONSOLE_TRANSPARENT_BACKGROUND;
//Log.d("drawText: (", x, ',', y, ") '", text, "', color=", buf.console.textColor);
foreach(int i; 0 .. charsMeasured) {
@ -200,9 +200,9 @@ class ConsoleFont : Font {
if (text.length == 0)
return; // nothing to draw - empty text
import dlangui.platforms.console.consoleapp;
import dlangui.platforms.console.dconsole;
ConsoleDrawBuf buf = cast(ConsoleDrawBuf)drawBuf;
import dlangui.platforms.ansi_console.consoleapp;
import dlangui.platforms.ansi_console.dconsole;
ANSIConsoleDrawBuf buf = cast(ANSIConsoleDrawBuf)drawBuf;
if (_textSizeBuffer.length < text.length)
_textSizeBuffer.length = text.length;
@ -221,7 +221,7 @@ class ConsoleFont : Font {
foreach(int i; 0 .. charsMeasured) {
dchar ch = text[i];
uint color = i < charProps.length ? charProps[i].color : charProps[$ - 1].color;
buf.console.textColor = ConsoleDrawBuf.toConsoleColor(color);
buf.console.textColor = ANSIConsoleDrawBuf.toConsoleColor(color);
customizedTextFlags = (i < charProps.length ? charProps[i].textFlags : charProps[$ - 1].textFlags) | textFlags;
underline = (customizedTextFlags & TextFlag.Underline) != 0;
// turn off underline after hot key

View File

@ -1,4 +1,4 @@
module dlangui.platforms.console.dconsole;
module dlangui.platforms.ansi_console.dconsole;
public import dlangui.core.config;

View File

@ -1947,7 +1947,7 @@ class Platform {
void onThemeChanged() {
// override and call dispatchThemeChange for all windows
drawableCache.clear();
static if (!BACKEND_CONSOLE) {
static if (!WIDGET_STYLE_CONSOLE) {
imageCache.checkpoint();
imageCache.cleanup();
}

View File

@ -309,9 +309,9 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
protected uint _caretColorReplace = 0x808080FF;
protected uint _matchingBracketHightlightColor = 0x60FFE0B0;
protected uint _iconsPaneWidth = BACKEND_CONSOLE ? 1 : 16;
protected uint _foldingPaneWidth = BACKEND_CONSOLE ? 1 : 12;
protected uint _modificationMarksPaneWidth = BACKEND_CONSOLE ? 1 : 4;
protected uint _iconsPaneWidth = WIDGET_STYLE_CONSOLE ? 1 : 16;
protected uint _foldingPaneWidth = WIDGET_STYLE_CONSOLE ? 1 : 12;
protected uint _modificationMarksPaneWidth = WIDGET_STYLE_CONSOLE ? 1 : 4;
/// when true, call measureVisibileText on next layout
protected bool _contentChanged = true;
@ -415,7 +415,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
}
_leftPaneWidth = _lineNumbersWidth + _modificationMarksWidth + _foldingWidth + _iconsWidth;
if (_leftPaneWidth)
_leftPaneWidth += BACKEND_CONSOLE ? 1 : 3;
_leftPaneWidth += WIDGET_STYLE_CONSOLE ? 1 : 3;
}
protected void drawLeftPaneFolding(DrawBuf buf, Rect rc, int line) {
@ -573,7 +573,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
buf.fillRect(rc, _leftPaneBackgroundColor);
//buf.fillRect(Rect(rc.right - 2, rc.top, rc.right - 1, rc.bottom), _leftPaneBackgroundColor2);
//buf.fillRect(Rect(rc.right - 1, rc.top, rc.right - 0, rc.bottom), _leftPaneBackgroundColor3);
rc.right -= BACKEND_CONSOLE ? 1 : 3;
rc.right -= WIDGET_STYLE_CONSOLE ? 1 : 3;
if (_foldingWidth) {
Rect rc2 = rc;
rc.right = rc2.left = rc2.right - _foldingWidth;
@ -1039,7 +1039,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
protected void startCaretBlinking() {
if (window) {
static if (BACKEND_CONSOLE) {
static if (WIDGET_STYLE_CONSOLE) {
window.caretRect = caretRect;
window.caretReplace = _replaceMode;
} else {
@ -1059,7 +1059,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
protected void stopCaretBlinking() {
if (window) {
static if (BACKEND_CONSOLE) {
static if (WIDGET_STYLE_CONSOLE) {
window.caretRect = Rect.init;
} else {
if (_caretTimerId) {

View File

@ -1649,7 +1649,7 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler
if (!colVisible(x))
continue;
Rect cellRect = cellRectScroll(x, y);
if (BACKEND_CONSOLE && phase == 1) {
if (WIDGET_STYLE_CONSOLE && phase == 1) {
cellRect.right--;
}
Rect clippedCellRect = cellRect;
@ -1703,7 +1703,7 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler
protected Point measureCell(int x, int y) {
// override it!
return Point(BACKEND_CONSOLE ? 5 : 80, BACKEND_CONSOLE ? 1 : 20);
return Point(WIDGET_STYLE_CONSOLE ? 5 : 80, WIDGET_STYLE_CONSOLE ? 1 : 20);
}
protected int measureColWidth(int x) {
@ -1741,7 +1741,7 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler
}
void autoFitColumnWidth(int i) {
_colWidths[i] = (i < _headerCols && !_showRowHeaders) ? 0 : measureColWidth(i) + (BACKEND_CONSOLE ? 1 : 3.pointsToPixels);
_colWidths[i] = (i < _headerCols && !_showRowHeaders) ? 0 : measureColWidth(i) + (WIDGET_STYLE_CONSOLE ? 1 : 3.pointsToPixels);
_changedSize = true;
}
@ -1765,7 +1765,7 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler
}
void autoFitRowHeight(int i) {
_rowHeights[i] = (i < _headerRows && !_showColHeaders) ? 0 : measureRowHeight(i) + (BACKEND_CONSOLE ? 0 : 2);
_rowHeights[i] = (i < _headerRows && !_showColHeaders) ? 0 : measureRowHeight(i) + (WIDGET_STYLE_CONSOLE ? 0 : 2);
_changedSize = true;
}
@ -1785,8 +1785,8 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler
_headerCols = 1;
_headerRows = 1;
_selection = new RedBlackTree!Point();
_defRowHeight = BACKEND_CONSOLE ? 1 : pointsToPixels(16);
_defColumnWidth = BACKEND_CONSOLE ? 7 : 100;
_defRowHeight = WIDGET_STYLE_CONSOLE ? 1 : pointsToPixels(16);
_defColumnWidth = WIDGET_STYLE_CONSOLE ? 7 : 100;
_showColHeaders = true;
_showRowHeaders = true;
@ -1964,7 +1964,7 @@ class StringGridWidget : StringGridWidgetBase {
Align ha = Align.Left;
//if (sz.y < rc.height)
// applyAlign(rc, sz, ha, Align.VCenter);
int offset = BACKEND_CONSOLE ? 0 : 1;
int offset = WIDGET_STYLE_CONSOLE ? 0 : 1;
fnt.drawText(buf, rc.left + offset, rc.top + offset, txt, textColor);
}
@ -1989,7 +1989,7 @@ class StringGridWidget : StringGridWidgetBase {
//if (row < 0)
// ha = Align.HCenter;
applyAlign(rc, sz, ha, Align.VCenter);
int offset = BACKEND_CONSOLE ? 0 : 1;
int offset = WIDGET_STYLE_CONSOLE ? 0 : 1;
uint cl = textColor;
cl = style.customColor("grid_cell_text_color_header", cl);
fnt.drawText(buf, rc.left + offset, rc.top + offset, txt, cl);

View File

@ -65,8 +65,8 @@ class StatusLineTextAndIconPanel : StatusLineTextPanel {
this(string ID) {
super(ID);
_icon = new ImageWidget(null);
_icon.minWidth = BACKEND_CONSOLE ? 1 : 20;
_icon.minHeight = BACKEND_CONSOLE ? 1 : 20;
_icon.minWidth = WIDGET_STYLE_CONSOLE ? 1 : 20;
_icon.minHeight = WIDGET_STYLE_CONSOLE ? 1 : 20;
_icon.alignment = Align.Center;
addChild(_icon);
}

View File

@ -1187,7 +1187,7 @@ Theme createDefaultTheme() {
res.fontFace = "Verdana";
}
//res.fontFace = "Arial Narrow";
static if (BACKEND_CONSOLE) {
static if (WIDGET_STYLE_CONSOLE) {
res.fontSize = 1;
res.textColor = 0xFFFFFF;
Style button = res.createSubstyle(STYLE_BUTTON).backgroundColor(0x808080).alignment(Align.Center).setMargins(0, 0, 0, 0).textColor(0x000000);
@ -1690,7 +1690,7 @@ bool loadTheme(Theme theme, string resourceId, int level = 0) {
string filename;
try {
filename = drawableCache.findResource(BACKEND_CONSOLE ? "console_" ~ resourceId : resourceId);
filename = drawableCache.findResource(WIDGET_STYLE_CONSOLE ? "console_" ~ resourceId : resourceId);
if (!filename || !filename.endsWith(".xml"))
return false;
string s = cast(string)loadResourceBytes(filename);