Canvas size limited to 1024x768 ?

BlitzMax Forums/BlitzMax Beginners Area/Canvas size limited to 1024x768 ?

Canvas size seems limited to 1024x768 ?
Try this :

Const WWX = 1024
Const WWY = 768

Const W = 2048 ' Canvas Size work only with
Const H = 1024  ' W=1024 and H=768

Local window:TGadget=CreateWindow("",0,0,WWX,WWY, Null, WINDOW_MENU|WINDOW_TITLEBAR)
Local panel:Tgadget = CreatePanel(10,10,WWX-40,WWY-80,window,PANEL_ACTIVE)

Global canvas:TGadget=CreateCanvas(0,0,W,H,panel)


While WaitEvent()
	Select EventID()
		Case EVENT_TIMERTICK
			RedrawGadget canvas

		Case EVENT_GADGETPAINT
			SetGraphics CanvasGraphics(canvas)
			Cls
			SetColor 255,255,255
			'...
			Flip
			
		Case EVENT_WINDOWCLOSE
				FreeGadget canvas
				End

		Case EVENT_APPTERMINATE
			End
	End Select

Wend


I just increased the window size and it worked, I had to set W down because 2048 is too big for my monitor.

In fact i want scroll the canvas inside the windows !

Try this (scrollbars)
Const WWX = 800
Const WWY = 600

Const W = 1024 'not work with 2048x1024 !
Const H = 768

Local window:TGadget=CreateWindow("",0,0,WWX,WWY, Null, WINDOW_MENU|WINDOW_TITLEBAR)

Local panel:Tgadget = CreatePanel(10,10,WWX-40,WWY-80,window,PANEL_ACTIVE)
SetGadgetLayout panel,1,1,1,1
SetPanelColor panel,100,0,200

Local sv:Tgadget = CreateSlider(WWX-30,10,20,WWY-80,window,SLIDER_VERTICAL)
Local sh:Tgadget = CreateSlider(10,WWY-70,WWX-40,20,window,SLIDER_HORIZONTAL)

Global canvas:TGadget=CreateCanvas(0,0,W,H,panel)

SetSliderRange sv,ClientWidth(panel),GadgetWidth(canvas)
SetSliderRange sh,ClientHeight(panel),GadgetHeight(canvas)

While WaitEvent()
	Select EventID()
		Case EVENT_TIMERTICK
			RedrawGadget canvas

		Case EVENT_GADGETPAINT
			SetGraphics CanvasGraphics(canvas)
			Cls
			SetColor 255,255,255
			'...
			Flip
			
			SetGadgetShape canvas,-SliderValue(sh),-SliderValue(sv),GadgetWidth(canvas),GadgetHeight(canvas)
			
			
		Case EVENT_MOUSEMOVE

			SetSliderRange sh,ClientWidth(panel),GadgetWidth(canvas)
			SetSliderRange sv,ClientHeight(panel),GadgetHeight(canvas)
			SetGadgetShape canvas,-SliderValue(sh),-SliderValue(sv),GadgetWidth(canvas),GadgetHeight(canvas)
			
			
		Case EVENT_WINDOWCLOSE
				FreeGadget canvas
				End

		Case EVENT_APPTERMINATE
			End
	End Select

	
Wend


I've adapted the code from a blitzplus program. With blitzplus, you can use large canvas (2048x1024) and more ! bmax limitation ? No info about this into the documentation.

Scrolling a canvas isn't needed, as you can just scroll what's be drawn on the canvas...

@Scienthsine : my prog is a spline editor (path for enemies). For a 1024x768 in-game resolution i need a 1224x1224 working area to position some spline points outside the game area. Perhaps a solution will be to use a large image and scroll it.

uhm... the large image seems not be the solution. if i do this i can't use command like 'drawline' ! With an image you can only use writepixel !

image=CreateImage(256,1)
map=LockImage(image)
For i=0 To 255
	WritePixel(map,i,0,ALPHABITS|i)
Next
UnlockImage(image)

DrawImageRect image,0,0,640,480


You only need a canvas as big as what you can display at any one time. Use Scroll bars, and offset your drawing onto the canvas by the scollbars. Yes, somethings won't be drawn because they will run over the canvas, but they would be seen at that point anyway... *sigh*

It's as smiple as making 2 scrollbars. Make the value range for the scrollbars to their 'working size'-'canvas actual size'. Then, to all of your drawing commands, subtract the scrollbar's current value from it's draw position.

This sounds like there can only be displayed 1024*768 pixels at one time, doesn't it?
But there also screens with 1280*1024 pixels or more.
And some Windows systems allow you to have more than one screen in a system - if you've two screens with each 1280*1024 pixels, one left, one right, you'll have 2560*1024 pixels.

I think you are limited to the current screen res for your canvases. Or possibly the highest res that your gfx card can support?

But think of the RedrawGadget example:
' redrawgadget.bmx

Strict

Type TApplet 

	Method OnEvent(Event:TEvent) Abstract

	Method New()
		AddHook EmitEventHook,eventhook,Self
	End Method

	Function eventhook:Object(id,data:Object,context:Object)
		Local	event:TEvent
		Local	app:TApplet
		event=TEvent(data)
		app=TApplet(context)
		app.OnEvent event	
	End Function

End Type

Type TSpinningApplet Extends TApplet

	Field	window:TGadget
	Field	canvas:TGadget
	Field	timer:TTimer
	Field	image:TImage
	
	Method Draw()
		SetGraphics CanvasGraphics(canvas)
		SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
		SetBlend ALPHABLEND
		SetRotation MilliSecs()*.1
		SetClsColor 255,0,0
		Cls
		DrawImage image,GraphicsWidth()/2,GraphicsHeight()/2
		Flip
	End Method
	
	Method OnEvent(Event:TEvent)
		Select event.id
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_TIMERTICK
			RedrawGadget canvas
		Case EVENT_GADGETPAINT
			draw
		End Select
	End Method
	
	Method Create:TSpinningApplet(name$)
		Local	a:TApplet
		Local	w,h
		image=LoadImage("fltkwindow.png")
		window=CreateWindow(name,20,20,512,512)
		w=ClientWidth(window)
		h=ClientHeight(window)
		canvas=CreateCanvas(0,0,w,h,window)
		canvas.SetLayout 1,1,1,1
		timer=CreateTimer(100)
		Return Self		
	End Method
	
End Type

AutoMidHandle True

Local	spinner:TSpinningApplet

spinner=New TSpinningApplet.Create("Spinning Applet")

While True
	WaitEvent
Wend

If the user resizes the window the canvas will be resized too because of its layout. So the user could resize the canvas to sizes bigger than screen resultion and the canvas would "freeze".

That is normal behavior at least for OpenGL which does not support to have higher "canvas" than the actual screensize.