From fcdd3123c019b4eddfa7d8e2bba240fcccbaa1e3 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Fri, 23 Oct 2015 11:00:26 -0400 Subject: [PATCH] stuff --- color.d | 7 ++++++ dom.d | 2 -- minigui.d | 47 +++++++++++++++++++++++++++++++++---- simpledisplay.d | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 6 deletions(-) diff --git a/color.d b/color.d index 173b0f6..6de6a47 100644 --- a/color.d +++ b/color.d @@ -1127,3 +1127,10 @@ struct Size { int width; int height; } + +struct Rectangle { + int left; + int top; + int right; + int bottom; +} diff --git a/dom.d b/dom.d index 10f527a..1a08af9 100644 --- a/dom.d +++ b/dom.d @@ -75,8 +75,6 @@ import std.string; // the reason this is separated is so I can plug it into D->JS as well, which uses a different base Element class -import arsd.dom; - mixin template DomConvenienceFunctions() { /// Calls getElementById, but throws instead of returning null if the element is not found. You can also ask for a specific subclass of Element to dynamically cast to, which also throws if it cannot be done. diff --git a/minigui.d b/minigui.d index 9388315..6c63521 100644 --- a/minigui.d +++ b/minigui.d @@ -147,6 +147,9 @@ class DataView : Widget { public import simpledisplay; +version(Windows) + import core.sys.windows.windows; + // this is a hack to call the original window procedure on native win32 widgets if our event listener thing prevents default. private bool lastDefaultPrevented; @@ -188,8 +191,10 @@ version(Windows) { Single select, multi select, organization, drag+drop */ -static if(UsingSimpledisplayX11) -enum windowBackgroundColor = Color(220, 220, 220); +//static if(UsingSimpledisplayX11) +version(win32_widgets) {} +else + enum windowBackgroundColor = Color(220, 220, 220); private const(char)* toStringzInternal(string s) { return (s ~ '\0').ptr; } private const(wchar)* toWstringzInternal(in char[] s) { @@ -483,6 +488,17 @@ version(win32_widgets) { (*te).parentWindow.focusedWidget = lol; } + + + if(iMessage == WM_CTLCOLORBTN || iMessage == WM_CTLCOLORSTATIC) { + SetBkMode(cast(HDC) wParam, TRANSPARENT); + return cast(typeof(return)) + //GetStockObject(NULL_BRUSH); + // this is the window background color... + GetSysColorBrush(COLOR_3DFACE); + } + + auto pos = getChildPositionRelativeToParentOrigin(*te); lastDefaultPrevented = false; // try {import std.stdio; writeln(typeid(*te)); } catch(Exception e) {} @@ -525,7 +541,7 @@ version(win32_widgets) { } } -version(Windows) +version(win32_widgets) extern(Windows) BOOL childHandler(HWND hwnd, LPARAM lparam) { if(hwnd is null || hwnd in Widget.nativeMapping) return true; @@ -702,6 +718,14 @@ class Widget { void delegate(ScreenPainter painter) paint; ScreenPainter draw() { + int x = this.x, y = this.y; + auto parent = this.parent; + while(parent) { + x += parent.x; + y += parent.y; + parent = parent.parent; + } + auto painter = parentWindow.win.draw(); painter.originX = x; painter.originY = y; @@ -914,7 +938,7 @@ class Window : Widget { if(recipient !is null) { // import std.stdio; writeln(typeid(recipient)); - version(Windows) { + version(win32_widgets) { if(recipient.hwnd !is null) SetFocus(recipient.hwnd); } else { @@ -1530,6 +1554,8 @@ class ProgressBar : Widget { } class Fieldset : Widget { + // FIXME: on Windows,it doesn't draw the background on the label + // on X, it doesn't fix the clipping rectangle for it version(win32_widgets) override int paddingTop() { return Window.lineHeight; } else @@ -2089,6 +2115,13 @@ class TextEdit : Widget { painter.drawText(Point(4, 4), content, Point(width - 4, height - 4)); }; + caratTimer = new Timer(500, { + auto painter = this.draw(); + painter.pen = Pen(Color.white, 1); + painter.rasterOp = RasterOp.xor; + painter.drawLine(Point(16, 0), Point(16, 16)); + }); + defaultEventHandlers["click"] = delegate (Widget _this, Event ev) { this.focus(); }; @@ -2127,6 +2160,12 @@ class TextEdit : Widget { assert(parentWindow !is null); parentWindow.focusedWidget = this; } + + version(win32_widgets) { + + } else { + Timer caratTimer; + } } diff --git a/simpledisplay.d b/simpledisplay.d index 0b1cc3a..1860f65 100644 --- a/simpledisplay.d +++ b/simpledisplay.d @@ -3,6 +3,20 @@ // subsystem too, use `-L/subsystem:windows -L/entry:mainCRTStartup` /* FIXME: + + Text layout needs a lot of work. Plain drawText is useful but too + limited. It will need some kind of text context thing which it will + update and you can pass it on and get more details out of it. + + It will need a bounding box, a current cursor location that is updated + as drawing continues, and various changable facts (which can also be + changed on the painter i guess) like font, color, size, background, + etc. + + We can also fetch the carat location from it somehow. + + Should prolly be an overload of drawText + blink taskbar / demand attention cross platform. FlashWindow and demandAttention WS_EX_NOACTIVATE @@ -2224,6 +2238,41 @@ struct ScreenPainter { impl.drawText(upperLeft.x, upperLeft.y, lowerRight.x, lowerRight.y, text, alignment); } + static struct TextDrawingContext { + Point boundingBoxUpperLeft; + Point boundingBoxLowerRight; + + Point currentLocation; + + Point lastDrewUpperLeft; + Point lastDrewLowerRight; + + // how do i do right aligned rich text? + // i kinda want to do a pre-made drawing then right align + // draw the whole block. + // + // That's exactly the diff: inline vs block stuff. + + // I need to get coordinates of an inline section out too, + // not just a bounding box, but a series of bounding boxes + // should be ok. Consider what's needed to detect a click + // on a link in the middle of a paragraph breaking a line. + // + // Generally, we should be able to get the rectangles of + // any portion we draw. + // + // It also needs to tell what text is left if it overflows + // out of the box, so we can do stuff like float images around + // it. It should not attempt to draw a letter that would be + // clipped. + // + // I might also turn off word wrap stuff. + } + + void drawText(TextDrawingContext context, string text, uint alignment = 0) { + // FIXME + } + /// Drawing an individual pixel is slow. Avoid it if possible. void drawPixel(Point where) { transform(where); @@ -3622,6 +3671,12 @@ version(Windows) { //case WM_ERASEBKGND: // no need since we double buffer //break; + case WM_CTLCOLORBTN: + case WM_CTLCOLORSTATIC: + SetBkMode(cast(HDC) wParam, TRANSPARENT); + return cast(typeof(return)) //GetStockObject(NULL_BRUSH); + GetSysColorBrush(COLOR_3DFACE); + break; case WM_PAINT: { BITMAP bm; PAINTSTRUCT ps; @@ -3860,6 +3915,8 @@ version(X11) { void dispose() { auto buffer = this.window.impl.buffer; + this.rasterOp = RasterOp.normal; + // FIXME: this.window.width/height is probably wrong // src x,y then dest x, y @@ -4361,6 +4418,7 @@ version(X11) { // FIXME: windowType and customizationFlags + try final switch(windowType) { case WindowTypes.normal: setNetWMWindowType(GetAtom!"_NET_WM_WINDOW_TYPE_NORMAL"(display)); @@ -4411,6 +4469,10 @@ version(X11) { break; +/ } + catch(Exception e) { + // XInternAtom failed, prolly a WM + // that doesn't support these things + }