mirror of https://github.com/buggins/dlangui.git
cursor type support in console apps
This commit is contained in:
parent
969148ad26
commit
5fc7825c82
|
@ -1437,6 +1437,8 @@ class DrawableCache {
|
|||
foreach(string path; _resourcePaths) {
|
||||
string fn;
|
||||
fn = checkFileName(path, id, ".xml");
|
||||
if (fn is null && BACKEND_CONSOLE)
|
||||
fn = checkFileName(path, id, ".tim");
|
||||
if (fn is null)
|
||||
fn = checkFileName(path, id, ".png");
|
||||
if (fn is null)
|
||||
|
|
|
@ -214,9 +214,15 @@ class Window : CustomEventTarget {
|
|||
}
|
||||
|
||||
protected Rect _caretRect;
|
||||
/// blinking caret position (empty rect if no blinking caret)
|
||||
@property void caretRect(Rect rc) { _caretRect = rc; }
|
||||
@property Rect caretRect() { return _caretRect; }
|
||||
|
||||
protected bool _caretReplace;
|
||||
/// blinking caret is in Replace mode if true, insert mode if false
|
||||
@property void caretReplace(bool flg) { _caretReplace = flg; }
|
||||
@property bool caretReplace() { return _caretReplace; }
|
||||
|
||||
// Abstract methods : override in platform implementatino
|
||||
|
||||
/// show window
|
||||
|
|
|
@ -142,8 +142,14 @@ class ConsolePlatform : Platform {
|
|||
_drawBuf.fillRect(Rect(0, 0, w.width, w.height), w.backgroundColor);
|
||||
w.onDraw(_drawBuf);
|
||||
auto caretRect = w.caretRect;
|
||||
if ((w is activeWindow) && !caretRect.empty)
|
||||
_drawBuf.console.setCursor(caretRect.left, caretRect.top);
|
||||
if ((w is activeWindow) && !caretRect.empty) {
|
||||
if (!caretRect.empty) {
|
||||
_drawBuf.console.setCursor(caretRect.left, caretRect.top);
|
||||
_drawBuf.console.setCursorType(w.caretReplace ? ConsoleCursorType.Replace : ConsoleCursorType.Insert);
|
||||
} else {
|
||||
_drawBuf.console.setCursorType(ConsoleCursorType.Invisible);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_needRedraw = false;
|
||||
|
|
|
@ -15,6 +15,13 @@ version(Windows) {
|
|||
import dlangui.core.signals;
|
||||
import dlangui.core.events;
|
||||
|
||||
/// console cursor type
|
||||
enum ConsoleCursorType {
|
||||
Invisible, /// hidden
|
||||
Insert, /// insert (usually underscore)
|
||||
Replace, /// replace (usually square)
|
||||
}
|
||||
|
||||
enum TextColor : ubyte {
|
||||
BLACK, // 0
|
||||
BLUE,
|
||||
|
@ -441,6 +448,7 @@ class Console {
|
|||
_cursorX = _batchBuf.cursorX;
|
||||
_cursorY = _batchBuf.cursorY;
|
||||
rawSetCursor(_cursorX, _cursorY);
|
||||
rawSetCursorType(_cursorType);
|
||||
}
|
||||
_batchBuf.clear(ConsoleChar.init);
|
||||
}
|
||||
|
@ -477,6 +485,52 @@ class Console {
|
|||
}
|
||||
}
|
||||
|
||||
private ConsoleCursorType _rawCursorType = ConsoleCursorType.Insert;
|
||||
protected void rawSetCursorType(ConsoleCursorType type) {
|
||||
if (_rawCursorType == type)
|
||||
return;
|
||||
version(Windows) {
|
||||
CONSOLE_CURSOR_INFO ci;
|
||||
switch(type) {
|
||||
default:
|
||||
case ConsoleCursorType.Insert:
|
||||
ci.dwSize = 10;
|
||||
ci.bVisible = TRUE;
|
||||
break;
|
||||
case ConsoleCursorType.Replace:
|
||||
ci.dwSize = 100;
|
||||
ci.bVisible = TRUE;
|
||||
break;
|
||||
case ConsoleCursorType.Invisible:
|
||||
ci.dwSize = 10;
|
||||
ci.bVisible = FALSE;
|
||||
break;
|
||||
}
|
||||
SetConsoleCursorInfo(_hstdout, &ci);
|
||||
} else {
|
||||
switch(type) {
|
||||
default:
|
||||
case ConsoleCursorType.Insert:
|
||||
rawWrite("\x1b[?25h");
|
||||
break;
|
||||
case ConsoleCursorType.Replace:
|
||||
rawWrite("\x1b[?25h");
|
||||
break;
|
||||
case ConsoleCursorType.Invisible:
|
||||
rawWrite("\x1b[?25l");
|
||||
break;
|
||||
}
|
||||
}
|
||||
_rawCursorType = type;
|
||||
}
|
||||
|
||||
private ConsoleCursorType _cursorType = ConsoleCursorType.Insert;
|
||||
void setCursorType(ConsoleCursorType type) {
|
||||
_cursorType = type;
|
||||
if (!_batchMode)
|
||||
rawSetCursorType(_cursorType);
|
||||
}
|
||||
|
||||
protected void rawWriteTextAt(int x, int y, uint attr, dstring str) {
|
||||
if (!str.length)
|
||||
return;
|
||||
|
|
|
@ -944,6 +944,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
|
|||
if (window) {
|
||||
static if (BACKEND_CONSOLE) {
|
||||
window.caretRect = caretRect;
|
||||
window.caretReplace = _replaceMode;
|
||||
} else {
|
||||
long ts = currentTimeMillis;
|
||||
if (_caretTimerId) {
|
||||
|
@ -1058,7 +1059,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
|
|||
Rect caretRc = caretRect();
|
||||
if (caretRc.intersects(_clientRect)) {
|
||||
//caretRc.left++;
|
||||
if (_replaceMode)
|
||||
if (_replaceMode && BACKEND_GUI)
|
||||
buf.fillRect(caretRc, _caretColorReplace);
|
||||
buf.drawLine(Point(caretRc.left, caretRc.bottom), Point(caretRc.left, caretRc.top), _caretColor);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue