Placing images on GUI window and menu options

BlitzMax Forums/BlitzMax Beginners Area/Placing images on GUI window and menu options

Marco A G Pinto(Posted 2012) [#1]
Hello!

I have been trying to place images on the menus options, for example: "X Load File" where "X" should show an image 16x16.

I have also been trying to display images on the window by using:

which gives me the error: "Unhandled Exception:Attempt to acess field or method of Null object".

I have been searching in the forums without success.

Can someone help?

Thanks!

Kind regards,
>Marco A.G.Pinto
--------------------


Kryzon(Posted 2012) [#2]
You should use SetGadgetPixmap for the menu icons; make sure you use the correct flags.

For drawing images on windows you have to use a Canvas gadget.

Also take a look at this series by Assari: http://www.2dgamecreators.com/maxgui/


Marco A G Pinto(Posted 2012) [#3]
@Kryzon

Sorry for bothering you.

I have been able to make a rectangle to appear in a Canvas.

But the command I used to place an image doesn't do anything.

I now have the following code:
	Global canvas:TGadget=CreateCanvas(0,0,640,480,window)
	SetGraphics CanvasGraphics(canvas)
	DrawRect  20,20,50,80
	Global image_shield=LoadImage:TImage("images/shield.png",flags=-1 )
	DrawImage (image_shield,10,10,frame=0)
	Flip
	RedrawGadget canvas


and in the main loop I have:
		WaitEvent()
		t = EventID()
		If t=EVENT_GADGETPAINT
			Flip
		EndIf


It draws the rectangle but no image.

What am I doing wrong?

Thanks!

Kind regards,
>Marco A.G.Pinto
--------------------


matibee(Posted 2012) [#4]
You just need to add all your drawing code (DrawImage... etc) to your main loop because basically the canvas will be blank each time a gadget-paint event is fired.

WaitEvent()
t = EventID()
If t=EVENT_GADGETPAINT
' do ALL your scene drawing here..
DrawImage (image_shield,10,10,frame=0)
Flip
EndIf



Kryzon(Posted 2012) [#5]
And to fire a gadget-paint regularly you can use a timer:
Local renderTimer:TTimer = CreateTimer(30)

[...]

Select t
	Case EVENT_TIMERTICK
		;Redraw canvas with a 30 FPS frequency.
		If EventData() = renderTimer Then RedrawGadget canvas 
	
	Case EVENT_GADGETPAINT
		UpdateGame()
		DrawImage [...]
		DrawImage [...]
		Flip
	
	Case EVENT_WINDOWCLOSE
		End		
End Select

You could also use the EVENT_MOUSEMOVE event as reference to redraw the canvas, instead of a fixed timer.

In any case, using a timer for controlling the canvas rendering is explained in further detail here:
http://www.2dgamecreators.com/maxgui/T12-Canvas.html


matibee(Posted 2012) [#6]
And to fire a gadget-paint regularly you can use a timer:


I've just stopped doing that in my app as it obliterates the toolbar tooltips (i'm using windows xp). I just rely on gadget-paint messages for any os related things (like window resizing) and posting my own gadget-paint messages when i want to force a readraw.


Marco A G Pinto(Posted 2012) [#7]
Thanks, my dear ones!

I have been able to make it work!

Kind regards from,
>Marco A.G.Pinto
--------------------


Marco A G Pinto(Posted 2012) [#8]
Buaaaaaaaaaaa

I tried to do the same with a panel and it didn't work :(

I tried to place an image on the window area and it worked, but while trying to place another image in a panel it appears inside the panel and outside it.

Here is the code I am using:
	Global canvas:TGadget=CreateCanvas(0,0,640,480,window)
	ActivateGadget canvas
	SetGraphics CanvasGraphics(canvas)
	SetColor  240,240,240
	DrawRect  0,0,640,480
	Global image_shield=LoadImage:TImage("images/shield.png",flags=-1 )
	DrawImage image_shield,529-20-20-8+4,98-10-15+16+16-8-4-2
	Flip
	RedrawGadget canvas



	Global canvas2:TGadget=CreateCanvas(0,0,630+2,15+20+2+3-1,panel_copyright)
	ActivateGadget canvas2
	SetGraphics CanvasGraphics(canvas2)
	SetColor  240,240,240
	DrawRect  0,0,630+2,15+20+2+3-1
	Global image_ribbon=LoadImage:TImage("images/ribbon.png",flags=-1 )
	DrawImage image_ribbon,600-50-10,8
	Flip
	RedrawGadget canvas2


And in the main loop:
		If t=EVENT_GADGETPAINT
			' shield image
			ActivateGadget canvas
			SetGraphics CanvasGraphics(canvas)
			DrawImage image_shield,529-20-20-8+4,98-10-15+16+16-8-4-2
			Flip
		
			' ribbon image
			ActivateGadget canvas2
			SetGraphics CanvasGraphics(canvas2)
			DrawImage image_ribbon,600-50-10,8
			Flip
		EndIf



What am I doing wrong?

Thanks!

Kind regards,
>Marco A.G.Pinto
--------------------


matibee(Posted 2012) [#9]
Perhaps you need:

?Not Win32
GLShareContexts()
?


Which is using a compiler directive (?Not Win32 /?) to call GLShareContexts(). Required for sharing images across canvases.

As for Windows implementations there may be a bug in the directx drivers (I can't remember) but you can use OpenGL anyway.

But, I don't think you need canvases to do what you are doing (if you're just displaying a static bitmap. In your panel try

SetGadgetPixmap( panel_copyright, LoadPixmap( "images/ribbon.png" ) )