How to place an image (JPG,, GIF, etc.) with YAB?

Hi,

I am trying to learn YAB and to programm a small tool.
But I did not find any information how to place an image in a window.
I just want to place a simple image (JPG, GIF, etc.) within in window.
How can I do this?

I just saw a documentation how to place an image within a button… so it must be possible to place it as an independet element in the window, too.

Thanks for any information!

Miroslav

You can just create a vanilla BView and call DrawBitmap() on that.
I assume you use Translator Kit’s GetBitmap() or GetBitmapFile() to fetch the BBitmap.

@ Miroslav
Hi, you are develop with yab :slight_smile: nice.
I am from www.team-maui.org, we make yab.
Do you need support, please visit the yab forum,
www.yab.beosmax.org.
For info, yab is not 100% run in haiku, in time runs yab 100% in BeOS r5. Haiku is not finish, so can’t yab perfectly works in time.

Quick support:
you can load any image format what the OS you give per Translator, yab used the Translator from the OS
(nice OS Desing). In yab script can you load the image so:
err = DRAW IMAGE x1,y1 TO x2,y2, Image$, View$

see the line 153 and upper = http://yab-interpreter.cvs.sourceforge.net/yab-interpreter/yab-interpreter/documentation/yab-Commands?view=markup

yab have more intresting stuff with Bitmap and Canvas support in yab, thats cool and works good, this is a big think for making small 2D games :wink:

I hope i can help you.

MFG Ralf Schülke aka stargater

Hello,

take a look at my first yab beginners tutorial on BeSly:

http://www.besly.de/menu/search/archiv/dev/yab_tutorial_eng.html

there you can find an example, how to place a picture.

Greetings Lelldorin

Hi,

I have a trouble about picture in Yab I can’t use a relative path for it. I must encode all the path.
How can I put a relative path?

Thanks.

What do you mean with “relative path”?

You can set the path with image name:

/boot/apps/nameofapp/gfx/Image.gif

Or you can use a variable with the program path:

ProgramFolder$=/boot/apps/nameofapp/

ProgramFolder$+"/gfx/Image.gif"

Or if you want to get the current App folder:

if (peek("isbound")) then
   Programfolder$ = peek$("directory")
else
   Programfolder$=system$("pwd")
   Programfolder$ = left$(Programfolder$, len(Programfolder$)-1)
fi
1 Like

This forum discussion is very old, you should Look for newer one.

Best help you get at:

https://www.besly.de

Or

https://www.old.besly.de

Please, Post your line as a example. So we can test it and hopeful find a solution for the problem.

Regards lorglas

Hi,

I think Lelldorin had answered to my question.
I will test it this evening and post my source.

When I talking about a relative path, I want the software recognize the current directory to work with files in it or in subfolders.

Thanks


Reedit

Hi again,

The Lelldorin method work for me.

my code
window open 50,50 to 600,500,“View”,“Kitsune Soft”
view 0,10 to 550,450, “View1”,“View”
menu “Program”,“Quit”,“Q”,“View”
draw text 15,25, “This is a text edition”, “View1”

if (peek("isbound")) then
	Programfolder$ = peek$("directory")
else
	Programfolder$ =system$("pwd")
	Programfolder$=left$(Programfolder$,len(Programfolder$)-1)
fi
Programfolder$=Programfolder$+"/Graphic/lizard.jpg"

err = draw image 30,30, Programfolder$,"View1"
inloop=true
while(inloop)
	msg$=message$
	switch msg$
	
	case "View:Program:Quit|" 
		window close "View" 
	break	
	case "View:_QuitRequested|" 
		window close "View" 
	break
		
	end switch
wend

The only thing that doesn’t work this is it:
ProgramFolder$+“thepathofthefolder”

I have put ProgramFolder$=ProgramFolder+“thepathofthefolder”

Thanks.

1 Like

It make no sence to change the programfolder during the program is running.

If you want to put the Image into a variable, make a new one.

But it runs

Yes, that was just for testing the first tutorial.

But I have a question, Yab can work with music file? Or there are some librairies about audio with it?

Thanks.

You can use in yab following commands.

Sound play
Sound stop
Sound wait

Also for streaming Sound

Mediasound play
Mediasound stop

Regards lorglas

2 Likes

Ok I find it finally in the menu.

Thanks again it work :slight_smile:

OT, but since there are some expert here :wink:
I found that “file panel” stopped working in recent Yab release and I’ve already discovered why, but I found that I can’t bmessage a script when bound, it only works when run as a script, if I try

Hey application/my_yab_script do something

I don’t receive any response when the script is bound, but it works if it’s not bound to the executable

And another thing, how can use numkeys as shortcuts? Alt + 0/9 works only with upper row of the keyboard, not with the numpad

Tnx guys

Hi, the change to the filepanel comes from the reactivating the translation function in yab.

The point of bmessage, i didn’t know why, because i didn’t change it. But i will test it and look why this error.

Please report this error and with an example at
trac.besly.de.

Thank you

Lorglas

1 Like

Hi,

  1. Filepanel:
    Since localize is reactive with yab 1.8, it is needed that you define a empty filename also for load modes. See the example below.
    filename$ = filepanel “load-file”, “Open File”, “”,""

  2. Shortcuts
    I think, it isn’t possible. I look in the keymap preferences. if i press ctrl or alt the numpad is switching. I think that is the problem, but i not 100% sure.

Regards lorglas

1 Like

hi,

  1. The message function is working, if you build the program with the buildfactory. With the bind function there is an error. I must be look, why?
    I tested it with ping / pong in the example on Haiku Hrev 55507 and fresh installed yab and yab buildfactory.

regards lorglas

1 Like

I have made my first Yab app :slight_smile: based on Tedit it also count the lines

window open 50, 50 to 710,530, "View", "TextEditor"
layout "all","View"
window set "View", "minimumto",200,100
menu "File","Open","O","View"
menu "File","Save As...","S","View"
menu "File","Quit","Q","View"
menu"Help","About","A","View"
textedit 0,25 to 660,463, TextEd$, 3, "View"

//Text 10,468 to 100,481, "Text", "Line: ", "View"
inloop = true
while(inloop)

	h = window get "View", "height"
	Option$="countlines"
	LineCount=TEXTEDIT GET TextE$,Option$
	Option$ = "currentline"
	LineNumber = TEXTEDIT GET TextEd$, Option$
	Update()
	
	msg$=message$
	switch msg$
	case "View:_QuitRequested|"
		inloop = false
	break
	
	case "View:File:Quit|"
		inloop = false
	break
	
	case "View:File:Open|"
		filename$ = ""
		filename$ = filepanel "load-file", "Open File", "",""
		
		if(filename$="")then
			TEXTEDIT CLEAR TextEd$
		else
			//Clear the text Edit box
			TEXTEDIT CLEAR TextEd$
			//Open the file
			open filename$ for reading as #1
			while(!eof(1))
				//Read a line and stock it in newline
				line input #1 newline$
				//Add the new line + \n in Text box
				textedit add TextEd$, newline$ + "\n"
			wend
			//close file
			close #1
			//Place the cursor to line 1 when finished loading the file
			textedit set TextEd$, "gotoline", 1
		endif
			
		break
	
	case "View:File:Save As...|"
	file2save$=""
	filename$=""
	file2save$ = textedit get$ TextEd$
	if file2save$ <> "" then
		filename$ = filepanel "save-file", "Save File As ...", "/boot/home",""
		if filename$= "" return
		open filename$ for writing as #1
		print #1 file2save$
		close #1
	endif
	break
	
	case "View:Help:About|"
		alert "Developed by Kitsune.", "Ok", "About"
	break
	
	end switch
wend
window close "View"

Exit

sub Update()
	draw flush "View"
	draw text 10,h-2,"Line: "+str$(LineNumber)+"/"+str$(LineCount), "View"
	return
end sub

I have a question. Is it possible to run a Terminal from a Yab application? The launch function don’t do it.

2 Likes

The system command can launch a Terminal.
system(“Terminal”)

1 Like

That work Thanks!