CanvasGadget change background color

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

CanvasGadget change background color

Post by walbus »

CanvasGadget - change background color !
For fixing many flickering problems
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: CanvasGadget change background color

Post by STARGÅTE »

walbus wrote:many flickering problems
I use different background colors, but I have no flickering problems.

Have you an example?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: CanvasGadget change background color

Post 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
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: CanvasGadget change background color

Post by IdeasVacuum »

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: CanvasGadget change background color

Post 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
Last edited by walbus on Mon Jun 02, 2014 8:50 pm, edited 1 time in total.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: CanvasGadget change background color

Post 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
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: CanvasGadget change background color

Post 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
Post Reply