Page 1 of 1
PatternBrush and WS_EX_LAYOUTRTL
Posted: Fri Jan 26, 2018 11:12 am
by chi
Can someone explain to me why a PatternBrush with WS_EX_LAYOUTRTL doesn't work? If you resize the window, the brush smears with RTL, but not with LTR
(BTW, if you draw the background with WM_PAINT or WM_ERASEBKGND, the same thing happens...)
Is there another way to draw an image background that works with both RTL and LTR layouts?
Code: Select all
OpenWindow(0, 0, 0, 320, 200, "title", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\Background.bmp")
brush = CreatePatternBrush_(ImageID(0))
FreeImage(0)
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, brush)
SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE) |#WS_EX_LAYOUTRTL)
HideWindow(0, 0)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
DeleteObject_(brush)
edit: OK, I found a way... Using StretchBlt_() with SetStretchBltMode_(hdc, #STRETCH_HALFTONE), but you have to repeat the brush yourself ;(
Any other suggestions?
Re: PatternBrush and WS_EX_LAYOUTRTL
Posted: Fri Jan 26, 2018 1:46 pm
by RASHAD
I hope it is OK
Code: Select all
Procedure sizeCB()
InvalidateRect_(WindowID(0),0,1)
EndProcedure
SetProcessDefaultLayout_(1)
OpenWindow(0, 0, 0, 320, 200, "title", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\PureBasicLogo.bmp")
brush = CreatePatternBrush_(ImageID(0))
FreeImage(0)
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, brush)
;SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE) |#WS_EX_LAYOUTRTL)
HideWindow(0, 0)
BindEvent(#PB_Event_SizeWindow,@sizeCB())
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
DeleteObject_(brush)
Re: PatternBrush and WS_EX_LAYOUTRTL
Posted: Sat Jan 27, 2018 11:53 am
by chi
Thanks RASHAD, totally OK

. Don't know why I didn't try that, though
Re: PatternBrush and WS_EX_LAYOUTRTL
Posted: Sat Jan 27, 2018 12:53 pm
by chi
hmm, partially OK ^^. The origin of the image swaps back to TopLeft, but it should be TopRight. If you put some controls to the window it kinda feels a little bit like parallax scrolling

. Any ideas?
Code: Select all
Procedure sizeCB()
InvalidateRect_(WindowID(0),0,1)
EndProcedure
SetProcessDefaultLayout_(1)
OpenWindow(0, 0, 0, 320, 200, "title", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
ButtonGadget(0, 10, 10, 100, 30, "button")
CheckBoxGadget(1, 10, 50, 100, 30, "checkbox")
LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\PureBasicLogo.bmp")
brush = CreatePatternBrush_(ImageID(0))
FreeImage(0)
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, brush)
;SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE) |#WS_EX_LAYOUTRTL)
HideWindow(0, 0)
BindEvent(#PB_Event_SizeWindow,@sizeCB())
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
DeleteObject_(brush)
Re: PatternBrush and WS_EX_LAYOUTRTL
Posted: Sat Jan 27, 2018 5:19 pm
by RASHAD
Hi chi
I should tell you that from the first time
You know I have some experience with RTL
Maybe with workaround
Be tuned
Re: PatternBrush and WS_EX_LAYOUTRTL
Posted: Sat Jan 27, 2018 8:05 pm
by chi
RASHAD wrote:You know I have some experience with RTL

Hehe, I figured
May I ask if it would be a big deal if someone's application (a skinning engine, to be precise) does not fully support the RTL layout?
I always thought that Windows, with an installed Arabic language pack, would automatically mirror the window with its controls. But after some testing on a virtual machine I realized that this isn't the case. And the worst part is that some GDI functions are not mirrored in the same way as on an LTR layout.
So far I have 3 major problems: 1) The definition of different left and right margin sizes with WM_NCCALCSIZE does not work as expected. 2) Drawing an image background brush with changed origin within WM_CTLCOLORBTN or WM_CTLCOLORSTATIC seems to work only with some controls and 3) the mentioned problem with image backgrounds (from this thread). With No. 2 + 3 I might be able to get away with a workaround, but for the first problem I have no idea how to even solve that.
And here's the thing... Is it really worth it? I mean, is it absolutely necessary to support the RTL layout (e. g. in Egypt)? Or are most of the applications LTR anyway and nobody actually cares about RTL?

It would be very nice if you could shed some light on the matter, THX
BTW, I found a workaround for the 3rd problem, but this "fix" is introducing some new minor problems ofc
(toolbar, statusbar)
Code: Select all
Case #WM_ERASEBKGND
GetClientRect_(hWnd, cRect.RECT)
If GetLayout_(wParam)
SetBrushOrgEx_(wParam, cRect\right, 0, 0)
EndIf
FillRect_(wParam, cRect, brush)
ProcedureReturn 1
[/size]
Re: PatternBrush and WS_EX_LAYOUTRTL
Posted: Mon Jan 29, 2018 11:42 pm
by RASHAD
Hi chi
Workaround as promised
Code: Select all
SetProcessDefaultLayout_(1)
OpenWindow(0, 0, 0, 320, 200, "title", #PB_Window_SystemMenu|#PB_Window_SizeGadget| #PB_Window_ScreenCentered|#PB_Window_Invisible)
ContainerGadget(10,0,0,GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN))
ButtonGadget(0, 10, 10, 100, 30, "button")
CheckBoxGadget(1, 10, 50, 100, 30, "checkbox")
CloseGadgetList()
LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\PureBasicLogo.bmp")
brush = CreatePatternBrush_(ImageID(0))
FreeImage(0)
SetClassLongPtr_(GadgetID(10), #GCL_HBRBACKGROUND, brush)
HideWindow(0, 0)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
DeleteObject_(brush)
Re: PatternBrush and WS_EX_LAYOUTRTL
Posted: Tue Jan 30, 2018 9:09 am
by chi
Hello RASHAD,
thanks for the workaround, but unfortunately I can't use this technique in my application.
Forcing all controls of a window (not necessarily built with PB) onto another "window", I'd have to redirect all messages from/to the controls. And that's a no go.
I guess, for now I'll stick to the WM_ERASEBKGND solution...
Re: PatternBrush and WS_EX_LAYOUTRTL
Posted: Tue Jan 30, 2018 9:26 am
by RASHAD
Make it just a background not another window
Code: Select all
SetProcessDefaultLayout_(1)
OpenWindow(0, 0, 0, 320, 200, "title", #PB_Window_SystemMenu|#PB_Window_SizeGadget| #PB_Window_ScreenCentered|#PB_Window_Invisible)
ContainerGadget(10,0,0,GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN))
CloseGadgetList()
DisableGadget(10,1)
LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\Background.bmp")
brush = CreatePatternBrush_(ImageID(0))
FreeImage(0)
SetClassLongPtr_(GadgetID(10), #GCL_HBRBACKGROUND, brush)
ButtonGadget(0, 10, 10, 100, 30, "button")
CheckBoxGadget(1, 10, 50, 100, 30, "checkbox")
ListIconGadget(2,10,90,600,400,"Column #0",120,#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
AddGadgetColumn(2, 1, "Column 1",250)
AddGadgetColumn(2, 2, "Column 2",255)
AddGadgetColumn(2, 3, "Column 3",255)
For i = 0 To 150
AddGadgetItem(2, -1, " "+Str(i)+Chr(10)+ " 111"+Chr(10)+" 222"+Chr(10)+ " 333")
Next
HideWindow(0, 0)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
DeleteObject_(brush)
Re: PatternBrush and WS_EX_LAYOUTRTL
Posted: Wed Jan 31, 2018 9:45 am
by chi
nice, thanks RASHAD!