Page 1 of 3

[Implemented] Canvas background color

Posted: Sun Aug 13, 2017 6:55 pm
by Justin
It would be handy if we could choose the initial background color, possibly avoiding to draw it twice.

Re: Canvas background color

Posted: Sun Aug 13, 2017 7:21 pm
by IdeasVacuum

Re: Canvas background color

Posted: Sun Aug 13, 2017 7:23 pm
by davido
+1

Re: Canvas background color

Posted: Sun Aug 13, 2017 7:34 pm
by mestnyi
+1

Re: Canvas background color

Posted: Sun Aug 13, 2017 8:45 pm
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..

Re: Canvas background color

Posted: Sun Aug 13, 2017 10:43 pm
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?

Re: Canvas background color

Posted: Sun Aug 13, 2017 11:21 pm
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.

Re: Canvas background color

Posted: Sun Aug 13, 2017 11:54 pm
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?

Re: Canvas background color

Posted: Mon Aug 14, 2017 1:03 am
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.

Re: Canvas background color

Posted: Mon Aug 14, 2017 9:29 pm
by walbus
The pre defined white color for the canvas !
I self can absolutely not understand the reason, its simple for nothing good

Re: Canvas background color

Posted: Tue Aug 15, 2017 8:14 am
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.

Re: Canvas background color

Posted: Tue Aug 15, 2017 1:54 pm
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.

Re: Canvas background color

Posted: Mon Oct 30, 2017 12:11 am
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

Re: Canvas background color

Posted: Mon Oct 30, 2017 12:11 am
by Josh
Deleted, was a double posting

Re: Canvas background color

Posted: Mon Oct 30, 2017 8:25 am
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