From 93a7aa324ae9670eed46044431be0b62961889f0 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Sat, 10 Nov 2018 14:44:28 -0500 Subject: [PATCH 1/3] hide bouncing cursor (affects Windows) --- terminal.d | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/terminal.d b/terminal.d index d4d31a8..0612d68 100644 --- a/terminal.d +++ b/terminal.d @@ -3132,6 +3132,11 @@ class LineGetter { private int lastDrawLength = 0; void redraw() { + terminal.hideCursor(); + scope(exit) { + terminal.flush(); + terminal.showCursor(); + } terminal.moveTo(startOfLineX, startOfLineY); auto lineLength = availableLineLength(); From 58545995519cc52706fcedbc1874bbb38a4f1e3a Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Sat, 10 Nov 2018 15:02:20 -0500 Subject: [PATCH 2/3] detect default fg/bg colors on Windows --- terminal.d | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/terminal.d b/terminal.d index 0612d68..fb8390e 100644 --- a/terminal.d +++ b/terminal.d @@ -794,6 +794,14 @@ http://msdn.microsoft.com/en-us/library/windows/desktop/ms683193%28v=vs.85%29.as if(GetConsoleScreenBufferInfo(hConsole, &originalSbi) == 0) throw new Exception("not a user-interactive terminal"); + + defaultForegroundColor = cast(Color) (originalSbi.wAttributes & 0x0f); + defaultBackgroundColor = cast(Color) ((originalSbi.wAttributes >> 4) & 0x0f); + } + + version(Windows) { + private Color defaultBackgroundColor = Color.black; + private Color defaultForegroundColor = Color.white; } // only use this if you are sure you know what you want, since the terminal is a shared resource you generally really want to reset it to normal when you leave... @@ -930,20 +938,20 @@ http://msdn.microsoft.com/en-us/library/windows/desktop/ms683193%28v=vs.85%29.as // this isn't necessarily right but meh if(background == Color.DEFAULT) - setTob = Color.black; + setTob = defaultBackgroundColor; if(foreground == Color.DEFAULT) - setTof = Color.white; + setTof = defaultForegroundColor; if(force == ForceOption.alwaysSend || reverseVideo != this.reverseVideo || foreground != _currentForeground || background != _currentBackground) { flush(); // if we don't do this now, the buffering can screw up the colors... if(reverseVideo) { if(background == Color.DEFAULT) - setTof = Color.black; + setTof = defaultBackgroundColor; else setTof = cast(ushort) background | (foreground & Bright); if(background == Color.DEFAULT) - setTob = Color.white; + setTob = defaultForegroundColor; else setTob = cast(ushort) (foreground & ~Bright); } @@ -2704,6 +2712,8 @@ void main() { terminal.write("test some long string to see if it wraps or what because i dont really know what it is going to do so i just want to test i think it will wrap but gotta be sure lolololololololol"); terminal.writefln("%d %d", terminal.cursorX, terminal.cursorY); + terminal.color(Color.DEFAULT, Color.DEFAULT); + int centerX = terminal.width / 2; int centerY = terminal.height / 2; From 2a99aaf7ec114d3d2e3f7cbc20047a3b1a3d3378 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Sat, 10 Nov 2018 19:04:17 -0500 Subject: [PATCH 3/3] style improvements --- minigui.d | 96 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/minigui.d b/minigui.d index 4df4d0e..d8edd52 100644 --- a/minigui.d +++ b/minigui.d @@ -529,8 +529,18 @@ class DataView : Widget { //static if(UsingSimpledisplayX11) version(win32_widgets) {} -else version(custom_widgets) - enum windowBackgroundColor = Color(192, 192, 192); +else version(custom_widgets) { + enum windowBackgroundColor = Color(212, 212, 212); // used to be 192 + enum darkAccentColor = Color(172, 172, 172); + enum lightAccentColor = Color(223, 223, 223); // used to be 223 + enum activeTabColor = lightAccentColor; + enum activeListXorColor = Color(255, 255, 0); + enum hoveringColor = Color(215, 215, 215); + enum buttonColor = windowBackgroundColor; + enum depressedButtonColor = darkAccentColor; + enum progressBarColor = Color.blue; + enum activeMenuItemColor = Color.blue; +} else static assert(false); private const(char)* toStringzInternal(string s) { return (s ~ '\0').ptr; } @@ -560,13 +570,13 @@ void draw3dFrame(int x, int y, int width, int height, ScreenPainter painter, Fra painter.fillColor = background; painter.drawRectangle(Point(x + 0, y + 0), width, height); - painter.outlineColor = (style == FrameStyle.sunk) ? Color(128, 128, 128) : Color(223, 223, 223); + painter.outlineColor = (style == FrameStyle.sunk) ? darkAccentColor : lightAccentColor; painter.drawLine(Point(x + 0, y + 0), Point(x + width, y + 0)); painter.drawLine(Point(x + 0, y + 0), Point(x + 0, y + height - 1)); // inner layer //right, bottom - painter.outlineColor = (style == FrameStyle.sunk) ? Color(223, 223, 223) : Color(128, 128, 128); + painter.outlineColor = (style == FrameStyle.sunk) ? lightAccentColor : darkAccentColor; painter.drawLine(Point(x + width - 2, y + 2), Point(x + width - 2, y + height - 2)); painter.drawLine(Point(x + 2, y + height - 2), Point(x + width - 2, y + height - 2)); // left, top @@ -1672,7 +1682,7 @@ class ListWidget : ScrollableWidget { if(option.selected) { painter.rasterOp = RasterOp.xor; painter.outlineColor = Color.white; - painter.fillColor = Color(255, 255, 0); + painter.fillColor = activeListXorColor; painter.drawRectangle(pos, width - 8, Window.lineHeight); painter.rasterOp = RasterOp.normal; } @@ -2388,7 +2398,7 @@ class MouseTrackingWidget : Widget { painter.fillColor = c; painter.drawRectangle(Point(0, 0), this.width, this.height); - auto color = hovering ? Color(215, 215, 215) : windowBackgroundColor; + auto color = hovering ? hoveringColor : windowBackgroundColor; draw3dFrame(positionX, positionY, thumbWidth, thumbHeight, painter, FrameStyle.risen, color); } } @@ -2824,8 +2834,7 @@ class TabWidget : Widget { painter.outlineColor = Color.white; painter.drawPixel(Point(posX + 1, tabBarHeight - 1)); painter.drawPixel(Point(posX + 1, tabBarHeight - 2)); - painter.outlineColor = Color(233, 233, 233); - //painter.outlineColor = (style == FrameStyle.sunk) ? Color(128, 128, 128) : Color(223, 223, 223); + painter.outlineColor = activeTabColor; painter.drawPixel(Point(posX, tabBarHeight - 1)); } @@ -4015,29 +4024,31 @@ class ToolButton : Button { ); break; case GenericIcons.Save: - painter.fillColor = Color.black; + painter.fillColor = Color.white; + painter.outlineColor = Color.black; painter.drawRectangle(Point(2, 2) * multiplier / divisor, Point(13, 13) * multiplier / divisor); + // the label + painter.drawRectangle(Point(4, 8) * multiplier / divisor, Point(11, 13) * multiplier / divisor); + + // the slider + painter.fillColor = Color.black; + painter.outlineColor = Color.black; + painter.drawRectangle(Point(4, 3) * multiplier / divisor, Point(10, 6) * multiplier / divisor); + painter.fillColor = Color.white; painter.outlineColor = Color.white; - // the slider - painter.drawRectangle(Point(5, 2) * multiplier / divisor, Point(10, 5) * multiplier / divisor); - // the label - painter.drawRectangle(Point(4, 8) * multiplier / divisor, Point(11, 12) * multiplier / divisor); - - painter.fillColor = Color.black; - painter.outlineColor = Color.black; // the disc window - painter.drawRectangle(Point(8, 3) * multiplier / divisor, Point(9, 4) * multiplier / divisor); + painter.drawRectangle(Point(5, 3) * multiplier / divisor, Point(6, 5) * multiplier / divisor); break; case GenericIcons.Open: painter.fillColor = Color.white; painter.drawPolygon( - Point(3, 4) * multiplier / divisor, Point(3, 12) * multiplier / divisor, Point(14, 12) * multiplier / divisor, Point(14, 3) * multiplier / divisor, - Point(10, 3) * multiplier / divisor, Point(10, 4) * multiplier / divisor, Point(3, 4) * multiplier / divisor); + Point(3, 4) * multiplier / divisor, Point(3, 12) * multiplier / divisor, Point(13, 12) * multiplier / divisor, Point(13, 3) * multiplier / divisor, + Point(9, 3) * multiplier / divisor, Point(9, 4) * multiplier / divisor, Point(3, 4) * multiplier / divisor); painter.drawPolygon( - Point(1, 6) * multiplier / divisor, Point(12, 6) * multiplier / divisor, - Point(14, 12) * multiplier / divisor, Point(3, 12) * multiplier / divisor); + Point(1, 6) * multiplier / divisor, Point(11, 6) * multiplier / divisor, + Point(13, 12) * multiplier / divisor, Point(3, 12) * multiplier / divisor); //painter.drawLine(Point(9, 6) * multiplier / divisor, Point(13, 7) * multiplier / divisor); break; case GenericIcons.Copy: @@ -4307,7 +4318,7 @@ class ProgressBar : Widget { version(custom_widgets) override void paint(ScreenPainter painter) { this.draw3dFrame(painter, FrameStyle.sunk); - painter.fillColor = Color.blue; + painter.fillColor = progressBarColor; painter.drawRectangle(Point(0, 0), width * current / max, height); } @@ -4460,9 +4471,9 @@ class HorizontalRule : Widget { } override void paint(ScreenPainter painter) { - painter.outlineColor = Color(128, 128, 128); + painter.outlineColor = darkAccentColor; painter.drawLine(Point(0, 0), Point(width, 0)); - painter.outlineColor = Color(223, 223, 223); + painter.outlineColor = lightAccentColor; painter.drawLine(Point(0, 1), Point(width, 1)); } } @@ -4479,9 +4490,9 @@ class VerticalRule : Widget { } override void paint(ScreenPainter painter) { - painter.outlineColor = Color(128, 128, 128); + painter.outlineColor = darkAccentColor; painter.drawLine(Point(0, 0), Point(0, height)); - painter.outlineColor = Color(223, 223, 223); + painter.outlineColor = lightAccentColor; painter.drawLine(Point(1, 0), Point(1, height)); } } @@ -4667,7 +4678,7 @@ class MenuItem : MouseActivatedWidget { if(isDepressed) this.draw3dFrame(painter, FrameStyle.sunk); if(isHovering) - painter.outlineColor = Color.blue; + painter.outlineColor = activeMenuItemColor; else painter.outlineColor = Color.black; painter.fillColor = Color.transparent; @@ -5018,9 +5029,9 @@ class Button : MouseActivatedWidget { width = 50; height = 30; super(parent); - normalBgColor = Color(192, 192, 192); - hoverBgColor = Color(215, 215, 215); - depressedBgColor = Color(160, 160, 160); + normalBgColor = buttonColor; + hoverBgColor = hoveringColor; + depressedBgColor = depressedButtonColor; this.label = label; } @@ -5786,7 +5797,7 @@ enum EventType : string { /// class Event { - /// + /// Creates an event without populating any members and without sending it. See [dispatch] this(string eventName, Widget target) { this.eventName = eventName; this.srcElement = target; @@ -5808,19 +5819,19 @@ class Event { private string eventName; Widget srcElement; /// - alias srcElement target; + alias srcElement target; /// Widget relatedTarget; /// // for mouse events - int clientX; /// - int clientY; /// + int clientX; /// The mouse event location relative to the target widget + int clientY; /// ditto - int viewportX; /// - int viewportY; /// + int viewportX; /// The mouse event location relative to the window origin + int viewportY; /// ditto - int button; /// - int buttonLinear; /// + int button; /// [MouseEvent.button] + int buttonLinear; /// [MouseEvent.buttonLinear] // for key events Key key; /// @@ -6387,17 +6398,23 @@ http://msdn.microsoft.com/en-us/library/windows/desktop/bb760476%28v=vs.85%29.as // These are all for setMenuAndToolbarFromAnnotatedCode /// This item in the menu will be preceded by a separator line +/// Group: generating_from_code struct separator {} deprecated("It was misspelled, use separator instead") alias seperator = separator; /// Program-wide keyboard shortcut to trigger the action +/// Group: generating_from_code struct accelerator { string keyString; } /// tells which menu the action will be on +/// Group: generating_from_code struct menu { string name; } /// Describes which toolbar section the action appears on +/// Group: generating_from_code struct toolbar { string groupName; } /// +/// Group: generating_from_code struct icon { ushort id; } /// +/// Group: generating_from_code struct label { string label; } @@ -6405,11 +6422,14 @@ struct label { string label; } /++ Creates a dialog based on a data structure. + --- dialog((YourStructure value) { // the user filled in the struct and clicked OK, // you can check the members now }); + --- +/ +/// Group: generating_from_code void dialog(T)(void delegate(T) onOK, void delegate() onCancel = null) { auto dg = new AutomaticDialog!T(onOK, onCancel); dg.show();