[Implemented] Canvas background color

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

[Implemented] Canvas background color

Post by Justin »

It would be handy if we could choose the initial background color, possibly avoiding to draw it twice.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Canvas background color

Post by IdeasVacuum »

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Canvas background color

Post by davido »

+1
DE AA EB
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: Canvas background color

Post by mestnyi »

+1
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: Canvas background color

Post by Justin »

IdeasVacuum wrote:+1 It would make a difference
http://www.purebasic.fr/english/viewtop ... =3&t=54195
I also noticed the redrawing when resizing. But four years have passed..
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Re: Canvas background color

Post by PureLust »

I understand why you ask for this feature, and I've tried to write a little Program to see the flicker-effect.
But .. I can not see any flicker in my example.

Is it, because I do something wrong?
Or is it, because I've done the resizing and redrawing right and maybe you've done something wrong?
Or maybe my PC is just to fast to see any flickering?

Here is my test-code:

Code: Select all

Procedure ResizeAll()
	ActWinWidth = WindowWidth(0)
	ActWinHeight	= WindowHeight(0)
	ResizeGadget(0,#PB_Ignore, #PB_Ignore, ActWinWidth - 10, ActWinHeight - 10)
	
	; Redraw Canvas Gadget
	If StartDrawing(CanvasOutput(0))
		Box(0,0,ActWinWidth - 10, ActWinHeight - 10, $080808)
		Ellipse(ActWinWidth / 2 - 5, ActWinHeight / 2 - 5, ActWinWidth / 2 - 20, ActWinHeight / 2 - 20, $ff8888)
		StopDrawing()
	EndIf
EndProcedure

OpenWindow(0,0,0,600,400,"Resize me ...",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget)
SetWindowColor(0, $080808)
CanvasGadget(0,5,5,5,5)
ResizeAll()
BindEvent(#PB_Event_SizeWindow, @ResizeAll())

Repeat
	Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Can you see any flickering?
Last edited by PureLust on Sun Aug 13, 2017 11:50 pm, edited 2 times in total.
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: Canvas background color

Post by Justin »

It is not exactly a flickering, but if i make the window big and resize it quickly i cleary see the white background on the resized edge.
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Re: Canvas background color

Post by PureLust »

Justin wrote:It is not exactly a flickering, but if i make the window big and resize it quickly i cleary see the white background on the resized edge.
Hmmm, I can't see any white BG, even if I resize as quick as I can.
I've made some small changes to the code above, to tint the window-BG dark.
This is to make sure it's not the white Window-Background you see.

Can you pls. test again?
What's your System specs, you are testing on?
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Canvas background color

Post by IdeasVacuum »

It often depends on the complexity of the graphics on the Canvas as to how much flicker there is. However, there are occasions when the Canvas would not require a redraw on resize, if only the background colour was predefined - just like the window client area, a container gadget etc.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Canvas background color

Post by walbus »

The pre defined white color for the canvas !
I self can absolutely not understand the reason, its simple for nothing good
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Re: Canvas background color

Post by PureLust »

Ok, on a large Screen I was now able to see the initial white BG when resizing the CanvasGadget.

Even though it's not the white background fix you've asked for, you can use my DeFlicker-Modul to get rid of this effect (as a bonus you will eliminate 95% of all other resizing-flicker as well):

Code: Select all

XIncludeFile "Module_DeFlicker.pbi"			; Available here:  http://www.purebasic.fr/english/viewtopic.php?f=12&t=65364&hilit=deflicker

Procedure ResizeAll()
   ActWinWidth = WindowWidth(0)
   ActWinHeight   = WindowHeight(0)
   
	DeFlicker::StartResize(0)					; <--------------------------------
	
   ResizeGadget(0,#PB_Ignore, #PB_Ignore, ActWinWidth - 10, ActWinHeight - 10)
   
   ; Redraw Canvas Gadget
   If StartDrawing(CanvasOutput(0))
      Box(0,0,ActWinWidth - 10, ActWinHeight - 10, $080808)
      Ellipse(ActWinWidth / 2 - 5, ActWinHeight / 2 - 5, ActWinWidth / 2 - 20, ActWinHeight / 2 - 20, $ff8888)
      StopDrawing()
   EndIf
   
   DeFlicker::EndResize()						; <--------------------------------
   
EndProcedure

OpenWindow(0,0,0,600,400,"Resize me ...",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget)
SetWindowColor(0, $080808)
CanvasGadget(0,5,5,5,5)
ResizeAll()
BindEvent(#PB_Event_SizeWindow, @ResizeAll())

Repeat
   Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
You can copy/paste the DeFlicker Module from THIS THREAD.
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Canvas background color

Post by IdeasVacuum »

JHP defined a Windows API solution to flicker:
http://www.purebasic.fr/english/viewtop ... 5&start=15

Code: Select all

SetWindowLongPtr_(WindowID(#MyWindow), #GWL_EXSTYLE, #WS_EX_LAYERED)                      
SetLayeredWindowAttributes_(WindowID(#MyWindow), RGB(124, 109, 146), #Null, #LWA_COLORKEY)
RGB(124, 109, 146) .... set unique colour.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Canvas background color

Post by Josh »

With a simple CanvasGadget in the window it seems to work, but already with two simple CanvasGadget in one splitter an unpleasant effect occurs.

Code: Select all

Procedure ResizeAll()

  If StartDrawing (CanvasOutput (1))
    Box(0, 0, GadgetWidth (1), GadgetHeight (1), #Red)
    StopDrawing()
  EndIf

  If StartDrawing (CanvasOutput (2))
    Box(0, 0, GadgetWidth (2), GadgetHeight (2), #Green)
    StopDrawing()
  EndIf

EndProcedure

OpenWindow (0, 0, 0, 300, 600, "SplitterGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

CanvasGadget   (1, 0, 0,   0,   0)
CanvasGadget   (2, 0, 0,   0,   0)
SplitterGadget (0, 1, 1, 298, 598, 1, 2)

ResizeAll()
BindGadgetEvent (1, @ResizeAll())

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
With a SetGadgetColor () this could be avoided. In addition, creating images would be easier in some cases because I don't have to worry about the size of the gadget.

+10
sorry for my bad english
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Canvas background color

Post by Josh »

Deleted, was a double posting
Last edited by Josh on Mon Oct 30, 2017 4:48 pm, edited 1 time in total.
sorry for my bad english
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Canvas background color

Post by walbus »

This flicker problem is real

It's ugly and unnecessary

But, unfortunately, I don't think we're going to get this simple but nice feature, and I don't think there's an answer why not

I've had enough of this soon, it's just not fun anymore
Post Reply