Print
Parent Category: Development
Category: yab
Hits: 543


System: BeOS, Haiku, Zeta

Index

1. What is yab? 7. Show graphic
2. Creating a Program window 8. Create Button
3. Inloop - Durable inquiry of functions 9. Testing program in Terminal
4. MenuBar in window 10. Bind program code (Zeta only)
5. Create additional View 11. Help while programming
6. Show text  

 




Was is yab?

The yab Interpreter is a BASIC Dialect, witch is a further development of the Windows, Linux and Playstation 2 available YABASIC. yab was optimized for BeOS, ZETA and Haiku and included many commands for it.

With the help of this programming language it is very easy to create simply small and even complex programs. A good example of it is the burner program JABA contained in ZETA.

You will find out in the process of this tutorial how easy it is to create an application with yab, . This tutorial will not provide a complete application, but simple basic knowledge to learn you to get started in yab.



back to index




Creating a Program window

Creating a Program window is simple, you only need to provide the instruction window open and add a few data concerning size, name and internal designation.

window open 50,50 to 600,500, "View", "WindowName"


A window is opened, which begins 50 pixels of the left edge of screen and 50 pixels of the upper edge of screen. After that to the right and lower edge of window are indicated. Thus we have a window size of 550 pixels in the width and 450 pixels in the height. Like you see the window size is not given, but only the coordinates on the screen.

After the data for the window size the name of the window follows (here: "View") for internal use. Over this name you can address the window for example to close or to insert an entry .

For WindowName you indicate the name, which stands then as window designation in the TAB of the window. Thus the name, which is seen by the user.

back to index


Inloop - Durable inquiry of functions

Next we provide a Inloop, which is helpful  to us in the execution of always recurring requirements in the program. Everything located in this loop in the program runs so long again and again as is required. Everything which is outside of the loop stands either only once or only when it is called for. Here it is to be noted that everything which is before the loop will be executed before the loop is started and everything which stands behind the loop only when called for.

Cinloop = true
while(inloop)
     msg$ = message$
     switch msg$

          Here the entries are inserted into the loop.

     end switch
wend

Closing the window over the TAB is a good example, because this function should be selectable in the program sequence at any time. Insert the following code into the range, that in the loop with " Here the entries are inserted into the loop." is indicated. For this we use the instruction case, which begins with indication of its name and is terminated with break.

case "View:_QuitRequested|"

          window close "View"

     break

When the close range of the TAB is clicked, this with name of the window (View) and the pertinent inquiryis spent (here _ QuitRequested).

All that stands between case "View:_QuitRequested|" and break, will be executed upon calling the sequence. Since we would like to close the window, with window close "View" the window View is closed.

back to index


Window menu bar

In the most cases a menu bar belongs also to a window. In order to add these menu bars,add the following code above inloop and underneath the opening of the program window, in order to have this visible at all times.

menu "Program", "Quit", "Q", "View"


Also with this example we take care of terminating the program. With this code we provides the menu range,Programand under this point lies the sub point Quit (terminate). The indication of the Q is the indication of the keyboard shortcut (Alt + Q) with which one can terminate the program apart from the menu. The last instruction View is the window into which the menu is indicated. In order to bring in further menu ranges, further lines must be inserted, which are build the same way. Changing the first names automatically adds a second menu range. Same applies to the subregions.

For this menu option a further entry must take place in the Inloop. This looks as follows:

case "View:Program:Quit|"

          window close "View"

     break


Since we call a closing of the window over the menu bar, the expenditure of the instruction sits down as together as the order of the selected menu selection. The program window (View) on which the menu lies, the menu range Program and the sub menu range Quit.

back to index

Create additional View

In order not to close the program window always to load a new view, it's recommend to set a further View to the main view yourself. This should begin approx.. 10 pixels below (in case off) a menu bar in the program window the top margin.

view 0,10 to 550,450, "View1", "View"


To set a View is similar to open a window. We provide a View with the name View1 on the program window View. The View begins on the basis of the program window size at the left hand side from 0 pixels and from top margin with 10 pixels (because of the menu bar). The right and lower edge are the data after that to.

The View1 is inserted where it should be indicated, in this case it is directly underneath the program window.

back to index
Show text

On this View1 we will now show some text.

draw text 20, 20, "this is a text edition", "View1"

With draw text we indicate that we would like to add some text. Over the specifications 20.20 we indicate the coordinates of the text on the View. Thus 20 pixels of the left hand side and 20 pixels of the top margin. The text following on it is the text, which is indicated on the View. Here no automatic line-makeup is made, so that this must be provided, by adapting the text to indicate the window (View). At the end the indication of the Views follows, on which the text is to be indicated.

back to index

Show graphic

To show graphics we have to add the next code underneath the Views, on which we would like these announcements (View1).

err = draw image 150,30, "/Path/to/Graphic/graphic.jpg", "View1"

With err = draw image we indicate that we would like to insert a graphic. As is the case for the text, the coordinates follow, at which the diagram is to be indicated. According to the indication of the picture location, the file path and the file are indicated (Path/to/Graphic/graphic.jpg), which you would like to represent. Also at the end of this instruction the indication of the Views follows, on which the diagram is to be indicated.

back to index

Create Button.

What is a program without switching surface for the program-specific functions. Whether forwarding to a further program window or for implementing tasks, a Button is very often used.

button 400, 400 to 450, 420, "internal_Button name", "shown_Button name", "View1"

We provide a Button with 400 pixels of the left Viewborder and 400 pixels of the upper Viewborder. The size of the Buttons results from the data of the following data for the right (450 pixels) and lower (420 pixels) edge of the Buttons. As the example shows the name of the Buttons for the internal use follows and then the name which is to be seen on the Button.

The function of the Buttons is indicated as for terminating the program, in the Inloop as a case instruction.

case "Internal_Button name|"

          window close "View"

     break

Here like before with the other cases the internal name of the Button is indicated. Also in this case we use the window close instruction to terminate the program. The Button could also show for example additional text, button, graphic or open and/or close a further window or View.

back to index

Testing program in Terminal.

If you'd like to test your program in between you can run the source code directly in a Terminal window.

yab /Path/to/source code.yab

Just enter yab in a Terminal window followed by space. Then drag and drop the source file to the Terminal so the path will be shown there, press Enter to execute your program.

In case you are using the yab IDE, you can execute the program over the MenuBar in Program and there with Run in Terminal run the Program.

back to index

Bind program code. (Zeta only)

Is your program ready, then the next step is to bind it. By binding a program you prevent other people from looking into the program code so only you can change and look at the source code.

Open a Terminal window and enter the following:

yab -bind "Name of the program" /Path/to/source code.yab

With yab -bind you declare that you would like to bind the source code. The name of the program is the name of the file that you can find in your home folder. The source code can be added like before with drag and drop.

back to index

Help while programming

- Due to the similarities to YABASIC, it is always recommended to search for solutions in their Documentation.

- yab itself comes with some example codes, which demonstrate different functions, these can be found in your yab folder.

- Here on BeSly there is a  yab ProgramHelp (German), where a lot of functions are described.

back to index

Special thanks to JohnM for sending a PDF file of this Tutorial.
Translation by Luc Schrijvers (Begasus) of the Belgium BeOS Usergroup.
Tutorial written by Christian Albrecht (Lelldorin) March 2006
Made available by BeSly, the BeOS & Zeta knowledge.