Restored from previous forum. Originally posted by Keith.
Hi,
I have a window with lots of 2D drawing going on on it wich is being redrawn every time the window recives a #PB_EventRepaint event but all the gadgets are being drawn over is there any way to redraw all the gadgets at once?
Thanks
Keith
redraw all gadgets on a window
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fweil.
Hello Keith,
I am not sure to understand exactly what you mean ... do you paint gadgets and can't refresh it properly or do you have gadgets over a painted background and can't manage how it appears ?
Gadgets are drawn over the background anyway I believe.
Maybe you will give more information about your issue so that one will help ...
KRgrds
Francois Weil
14, rue Douer
F64100 Bayonne
Hello Keith,
I am not sure to understand exactly what you mean ... do you paint gadgets and can't refresh it properly or do you have gadgets over a painted background and can't manage how it appears ?
Gadgets are drawn over the background anyway I believe.
Maybe you will give more information about your issue so that one will help ...
KRgrds
Francois Weil
14, rue Douer
F64100 Bayonne
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Keith.
Hi,
what I'm doing is using Box() to cover the window but in the main loop so its never erased but if I put controls on the window the box is draw over them.
heres the source
The buttongadget is not visible until its clicked but then as soon as the window repaints its hidden again.
Thanks
Keith
Hi,
what I'm doing is using Box() to cover the window but in the main loop so its never erased but if I put controls on the window the box is draw over them.
heres the source
Code: Select all
#Window_Constants = #PB_Window_BorderLess | #PB_Window_ScreenCentered
Procedure MouseOver(X,Y,W,H)
X=WindowX()+X:Y=WindowY()+y
GetCursorPos_(mouse.POINT) : MX=mouse\x : MY=mouse\y
If MX > X And MX Y And MY < Y + H
Over = 1
Else
Over = 0
EndIf
Else
Over = 0
EndIf
ProcedureReturn Over
EndProcedure
If OpenWindow(1,0,0,250,150,#Window_Constants,"Test Window")
If CreatePopupMenu(1)
MenuItem(1,"Move")
MenuBar()
MenuItem(2,"Close Window"+Chr(9)+"Alt+F4")
DisableMenuItem(1,1)
EndIf
If CreateGadgetList(WindowID())
ButtonGadget(1,229,5,16,14,"X",$8000)
EndIf
AddKeyboardShortcut(1,#PB_Shortcut_Alt | #PB_Shortcut_F4,2)
StartDrawing(WindowOutput())
DrawingMode(1)
FrontColor(255,255,255)
Font1=CreateFont_(13,5,1,100,100,0,0,0,1,1,1,1,1,"Tahoma")
DrawingFont(Font1)
Locate(5,5)
DrawText("Test Window")
Repeat
Select WindowEvent()
Case #WM_LBUTTONDOWN
If MouseOver(3,3,227,18)
SendMessage_(WindowID(), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
Case #WM_RBUTTONDOWN
If MouseOver(3,3,227,18)
DisplayPopupMenu(1,WindowID())
EndIf
Case #PB_EventMenu
Select EventMenuID()
Case 1
SendMessage_(WindowID(), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
Case 2
End
EndSelect
Case #PB_EventRepaint
Box(0,0,250,150,RGB(64,64,64))
Box(0,0,249,149,RGB(212,208,200))
Box(1,1,248,148,RGB(128,128,128))
Box(1,1,247,147,RGB(255,255,255))
Box(2,2,246,146,RGB(212,208,200))
Box(3,3,244,18,RGB(10,36,106))
FrontColor(128,128,128)
Locate(6,6)
DrawText("Test Window")
FrontColor(255,255,255)
Locate(5,5)
DrawText("Test Window")
EndSelect
ForEver
EndIF
Thanks
Keith
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fweil.
Keith,
Your source code requires some updates.
First you should consider using StartDrawing() / StopDrawing() each time you draw something. It means that you should put a StopDrawing() before your event loop and put a leading StartDrawing() and a trailing StopDrawing() in your Case #PB_EventRepaint block.
Then you draw some boxes covering your gadget. If you want to background your window, better is to use a callback to refresh it, or place your drawing stuff in an ImageGadget.
By the way, if I understand, you want to create a window close gadget on the top right of your window ? Why not use the appropriate constants when creating your window with OpenWindow() ?
I am not sure to understand what you would like to do at the end, but maybe you are just trying to make some things easy to write in a different way in PureBasic ?
Let me know for further help.
KRgrds
Francois Weil
14, rue Douer
F64100 Bayonne
Keith,
Your source code requires some updates.
First you should consider using StartDrawing() / StopDrawing() each time you draw something. It means that you should put a StopDrawing() before your event loop and put a leading StartDrawing() and a trailing StopDrawing() in your Case #PB_EventRepaint block.
Then you draw some boxes covering your gadget. If you want to background your window, better is to use a callback to refresh it, or place your drawing stuff in an ImageGadget.
By the way, if I understand, you want to create a window close gadget on the top right of your window ? Why not use the appropriate constants when creating your window with OpenWindow() ?
I am not sure to understand what you would like to do at the end, but maybe you are just trying to make some things easy to write in a different way in PureBasic ?
Let me know for further help.
KRgrds
Francois Weil
14, rue Douer
F64100 Bayonne
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fweil.
Keith,
I propose you a sample code using the same kind of stuff, like image in the background, an active label changing its color when moving the pointer over, and the feature to move the window when clicking this text to drag the window.
You have also the top bar of the window to move / close the window.
Hope this will help you.
Francois Weil
14, rue Douer
F64100 Bayonne
Keith,
I propose you a sample code using the same kind of stuff, like image in the background, an active label changing its color when moving the pointer over, and the feature to move the window when clicking this text to drag the window.
You have also the top bar of the window to move / close the window.
Hope this will help you.
Code: Select all
#background = $602020
Procedure MyWindowCallBack(WindowID.l, Message.l, wParam.l, lParam.l)
Result.l
Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_PAINT
StartDrawing(WindowOutput())
DrawImage(UseImage(0), 0, 0)
StopDrawing()
Case #PB_EventRepaint
StartDrawing(WindowOutput())
DrawImage(UseImage(0), 0, 0)
StopDrawing()
Case #PB_EventMoveWindow
StartDrawing(WindowOutput())
DrawImage(UseImage(0), 0, 0)
StopDrawing()
Default
EndSelect
ProcedureReturn Result
EndProcedure
;
; Main starts here
;
Quit.l = #FALSE
Over.l = #FALSE
WindowXSize.l = 320
WindowYSize.l = 240
hWnd.l = OpenWindow(0, 200, 200, WindowXSize, WindowYSize, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar, "MyWindow")
If hWnd
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 99)
LoadFont(0, "Verdana", 12)
FontID.l = FontID()
If CreateGadgetList(WindowID())
SetGadgetFont(FontID)
EndIf
SetWindowCallback(@MyWindowCallBack())
If CreateImage(0, WindowXSize, WindowYSize)
ImageID.l = ImageID()
StartDrawing(ImageOutput())
Box(0, 0, WindowXSize, WindowYSize, #background)
For i.l = 1 To 1000
Plot(Random(WindowXSize), Random(WindowYSize), RGB(Random(256), Random(256), Random(256)))
Next
DrawingFont(FontID) : FrontColor(255, 255, 0) : DrawingMode(1) : Locate(WindowXSize / 2, WindowYSize / 2) : DrawText("Hello world")
TextLength.l = TextLength("Hello world")
StopDrawing()
EndIf
StartDrawing(WindowOutput())
DrawImage(ImageID, 0, 0)
StopDrawing()
x1.l = WindowXSize / 2
x2.l = WindowXSize / 2 + TextLength
y1.l = WindowYSize / 2
y2.l = WindowYSize / 2 + 20
Repeat
WMX.l = WindowMouseX()
WMY.l = WindowMouseY() - 20
Select WaitWindowEvent()
If WMX > x1 And WMX y1 And WMY x1 And WMX y1 And WMY < y2
ReleaseCapture_()
SendMessage_(hWnd, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
EndSelect
Until Quit
EndIf
End
14, rue Douer
F64100 Bayonne
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Keith.
Thanks for the help.
The reason i dont have a window with a border is because i want this to look the same on any version of windows and it will also allow me to put the titlebar on any side of the window.
The code you posted has helped but the close button dosent show after a repaint
heres the code now
Thanks
Keith
Thanks for the help.
The reason i dont have a window with a border is because i want this to look the same on any version of windows and it will also allow me to put the titlebar on any side of the window.
The code you posted has helped but the close button dosent show after a repaint
heres the code now
Code: Select all
#Window_Constants = #PB_Window_BorderLess | #PB_Window_ScreenCentered
Procedure MouseOver(X,Y,W,H)
X=WindowX()+X:Y=WindowY()+y
GetCursorPos_(mouse.POINT) : MX=mouse\x : MY=mouse\y
If MX > X And MX Y And MY < Y + H
Over = 1
Else
Over = 0
EndIf
Else
Over = 0
EndIf
ProcedureReturn Over
EndProcedure
Procedure CallBack(WindowID.l,Message.l,wParam.l,lParam.l)
Result.l
Result=#PB_ProcessPureBasicEvents
Select Message
Case #PB_EventRepaint
StartDrawing(WindowOutput())
Box(0,0,250,150,RGB(64,64,64))
Box(0,0,249,149,RGB(212,208,200))
Box(1,1,248,148,RGB(128,128,128))
Box(1,1,247,147,RGB(255,255,255))
Box(2,2,246,146,RGB(212,208,200))
Box(3,3,244,18,RGB(10,36,106))
DrawingMode(1)
FrontColor(255,255,255)
Font1=CreateFont_(13,5,1,100,100,0,0,0,1,1,1,1,1,"Tahoma")
DrawingFont(Font1)
FrontColor(128,128,128)
Locate(6,6)
DrawText("Test Window")
FrontColor(255,255,255)
Locate(5,5)
DrawText("Test Window")
StopDrawing()
EndSelect
ProcedureReturn Result
EndProcedure
If OpenWindow(1,0,0,250,150,#Window_Constants,"Test Window")
SetWindowCallback(@CallBack())
If CreatePopupMenu(1)
MenuItem(1,"Move")
MenuBar()
MenuItem(2,"Close Window"+Chr(9)+"Alt+F4")
DisableMenuItem(1,1)
EndIf
If CreateGadgetList(WindowID())
Btn1=ButtonGadget(1,229,5,16,14,"X")
EndIf
AddKeyboardShortcut(1,#PB_Shortcut_Alt | #PB_Shortcut_F4,2)
Repeat
Select WindowEvent()
Case #WM_LBUTTONDOWN
If MouseOver(3,3,227,18)
SendMessage_(WindowID(), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
Case #WM_RBUTTONDOWN
If MouseOver(3,3,227,18)
DisplayPopupMenu(1,WindowID())
EndIf
Case #PB_EventMenu
Select EventMenuID()
Case 1
SendMessage_(WindowID(), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
Case 2
End
EndSelect
EndSelect
ForEver
EndIf
Keith
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm