summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Krauter <trustablecode@gmail.com>2020-03-05 16:40:20 +0100
committerSimon Krauter <trustablecode@gmail.com>2020-03-05 16:40:20 +0100
commita54e55a935cd1f8da050750c1d52e5ed07417f97 (patch)
treef25b13bc92f5ccacaae6bc3ca45f56a8d8ba4d70
parent825382a020aabe890962e122cbd7df7f674af627 (diff)
downloadNiGui-a54e55a935cd1f8da050750c1d52e5ed07417f97.tar.gz
NiGui-a54e55a935cd1f8da050750c1d52e5ed07417f97.zip
Windows: Cache the background brush instead of creating a new one every time
Fixes #91
-rwxr-xr-xsrc/nigui/private/windows/platform_impl.nim17
-rwxr-xr-xsrc/nigui/private/windows/platform_types1.nim1
2 files changed, 14 insertions, 4 deletions
diff --git a/src/nigui/private/windows/platform_impl.nim b/src/nigui/private/windows/platform_impl.nim
index bf31484..d08800d 100755
--- a/src/nigui/private/windows/platform_impl.nim
+++ b/src/nigui/private/windows/platform_impl.nim
@@ -171,10 +171,12 @@ proc pCommonWndProc(hWnd: pointer, uMsg: int32, wParam, lParam: pointer): pointe
evt.control = control
control.handleTextChangeEvent(evt)
of WM_CTLCOLORSTATIC, WM_CTLCOLOREDIT:
- let control = cast[Control](pGetWindowLongPtr(lParam, GWLP_USERDATA))
+ let control = cast[ControlImpl](pGetWindowLongPtr(lParam, GWLP_USERDATA))
discard SetTextColor(wParam, control.textColor.pColorToRGB32())
discard SetBkColor(wParam, control.backgroundColor.pColorToRGB32())
- return CreateSolidBrush(control.backgroundColor.pColorToRGB32)
+ if control.fBackgroundBrush == nil:
+ control.fBackgroundBrush = CreateSolidBrush(control.backgroundColor.pColorToRGB32)
+ return control.fBackgroundBrush
else:
discard
result = DefWindowProcW(hWnd, uMsg, wParam, lParam)
@@ -1089,6 +1091,12 @@ proc pGetTextSize(control: ControlImpl, text: string): Size =
result = pGetTextSize(hdc, control.fFont, text)
discard DeleteDC(hdc)
+method setBackgroundColor(control: ControlImpl, color: Color) =
+ procCall control.Control.setBackgroundColor(color)
+ if control.fBackgroundBrush != nil:
+ discard DeleteObject(control.fBackgroundBrush)
+ control.fBackgroundBrush = nil
+
method focus(control: ControlImpl) =
discard SetFocus(control.fHandle)
@@ -1298,9 +1306,10 @@ proc pContainerWndProc(hWnd: pointer, uMsg: int32, wParam, lParam: pointer): poi
of WM_ERASEBKGND:
let control = cast[ControlImpl](pGetWindowLongPtr(hWnd, GWLP_USERDATA))
if control != nil:
- var brush = CreateSolidBrush(control.backgroundColor.pColorToRGB32)
+ if control.fBackgroundBrush == nil:
+ control.fBackgroundBrush = CreateSolidBrush(control.backgroundColor.pColorToRGB32)
var rect = pGetClientRect(control.fHandle)
- discard FillRect(wParam, rect, brush)
+ discard FillRect(wParam, rect, control.fBackgroundBrush)
return
else:
discard
diff --git a/src/nigui/private/windows/platform_types1.nim b/src/nigui/private/windows/platform_types1.nim
index 9b99df8..c1f9866 100755
--- a/src/nigui/private/windows/platform_types1.nim
+++ b/src/nigui/private/windows/platform_types1.nim
@@ -13,6 +13,7 @@ type
ControlImpl* = ref object of Control
fHandle: pointer
fFont: pointer
+ fBackgroundBrush: pointer
CanvasImpl* = ref object of Canvas
fDC: pointer