Page 1 of 1

CanvasGadget change background color

Posted: Sun Jun 01, 2014 9:04 pm
by walbus
CanvasGadget - change background color !
For fixing many flickering problems

Re: CanvasGadget change background color

Posted: Sun Jun 01, 2014 9:07 pm
by STARGÅTE
walbus wrote:many flickering problems
I use different background colors, but I have no flickering problems.

Have you an example?

Re: CanvasGadget change background color

Posted: Mon Jun 02, 2014 11:18 am
by walbus
Hi,
on me NV simulator, unfortunately, i have changed the code now to PB 5.30B2
The old version without flickering is to time still for download (2014.5)
On resizing i become with 5.3 (to time- i looking further to fix it) flickerung, i can´t fix it.
On 5.22 resizing it´s absolutely smooth with graphic and text.
Now i must remove this feature, with a only black screen it´s now OK.
I think, it´s simple the canvas enhance for a changed background.
On creating the canvas new it blinking shortly white, this is my problem.

A way is, i make the canvas ever maximum available wide and height from the window
Then, i must not create the canvas by resizing new

Now it´s on this score ok, but the new code looking not good for me

Unfortunately, the code is big and with many includes
Here is the download path, if you want looking.
I change the download in the next day´s to the new version, but it´s to time not necessary.
This simulator is one of the best available, he have many tousends downloads worldwide.
http://www.nachtoptik.de/NV-and-sight-simulator.html

regards werner

Re: CanvasGadget change background color

Posted: Mon Jun 02, 2014 6:50 pm
by IdeasVacuum

Re: CanvasGadget change background color

Posted: Mon Jun 02, 2014 8:24 pm
by walbus
Yep, many thanks,
i am not lucky with the white canvas background.

I have fixed the problem in the NV simulator so :

This code working ONLY with PB5.30 >

But, i am not lucky with this code , but it works :?

Code: Select all

OpenWindow(0,300,300,600,600,"",#PB_Window_SystemMenu | #PB_Window_SizeGadget)

CanvasGadget(0,0,0,600,600)

StartDrawing(CanvasOutput(0))
Box(0,0,WindowWidth(0),WindowHeight(0),RGB(0,0,255))
StopDrawing()

min_win_x=300 : min_win_y=300 : max_win_x=1200 : max_win_y=1200
WindowBounds(0,min_win_x,min_win_y-MenuHeight(),max_win_x,max_win_y-MenuHeight()) ; Min and max window

Global win_resized
Procedure SizeWindowHandler()
  Shared max_win_x,max_win_y
  If EventWindow()=0 ; Window 0
    If Not win_resized
      CanvasGadget(0,0,0,max_win_x,max_win_y) ; Flicker fix
      StartDrawing(CanvasOutput(0))
      Box(0,0,max_win_x,max_win_y,RGB(0,0,255))
      StopDrawing()
    EndIf
    win_resized=1
  EndIf
EndProcedure
BindEvent (#PB_Event_SizeWindow,@SizeWindowHandler())

Repeat
  If win_resized
    win_resized=0
    CanvasGadget(0,0,0,WindowWidth(0),WindowHeight(0))
    StartDrawing(CanvasOutput(0))
    Box(0,0,WindowWidth(0),WindowHeight(0),RGB(0,0,255))
    StopDrawing()
  EndIf
Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: CanvasGadget change background color

Posted: Mon Jun 02, 2014 8:46 pm
by STARGÅTE
WaitWindowEvent ? in a callback of window events ? :oops:

Here is my code for Canvas-Resize without "flicker" (Windows 7, PB 5.30)

Code: Select all

Enumeration
	#Window
	#Gadget
EndEnumeration

Procedure SizeWindowHandler()
	
	ResizeGadget(#Gadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window))
	If StartDrawing(CanvasOutput(#Gadget))
		Box(0, 0, OutputWidth(), OutputHeight(), RGB(0,0,255))
		StopDrawing()
	EndIf
	
EndProcedure


OpenWindow(#Window, 300, 300, 600, 600, "Canvas Example", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
WindowBounds(#Window, 300, 300, 1200, 1200)
CanvasGadget(#Gadget,0,0,600,600)
SizeWindowHandler()

BindEvent(#PB_Event_SizeWindow, @SizeWindowHandler(), #Window)

Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: CanvasGadget change background color

Posted: Mon Jun 02, 2014 8:49 pm
by walbus
Ah, yep, i have oversight it .. thanks, i am looking now for your code...

resizegadget, yes , simple :wink: Many thanks !!!

But, i have a menu, and the flickering is back now with your code ( I think, i must drinking a beer ) , strange :D