Ticket #9223: scripts.txt

File scripts.txt, 3.8 KB (added by TriEdgeAI, 8 years ago)
1Welcome to this C++ Haiku video guide. I will be teaching you how to create your first Hellow World application with the Haiku operating system.
3Let's begin by creating a folder.
5Now let's create a source file - Hello-World.cpp.
7The first and most important thing that a regular C++ application should have, is a main function. However, we will not include ay-oh stream, but instead we are going to use another set of headers that are specific to Haiku.
9application.h and window.h.
11Haiku applications have a very object-oriented design. The core component of every program is a class that inherits Be-Application.
13The first thing to do would be to override the constructor. The superconstructor takes a string as an only argument. This string represents the signature of the application. In our case - application, slash, hallow haiku.
15The signature is a MIME-type unique identifier.
17Now, let's inherit the Be-Window class. This time, the constructor will be a bit more complicated. The first argument requires a data-structure called BeRect. A BeRect represents a 2D rectangle.
19The first two values are the x and y coordinates of the upper left corner. The other two values are for the bottom right one.
21This determines where the window will appear on the screen. The second argument is the title of the window. The third one is supposed to tell the type of the window.
23For this tutorial we are going to use Be Titled Window, but there are other types too. You can see a full list with explanations at the link provided below.
25The fourth and last required argument is used to specify certain flags, but we will leave it as zero.
27Now let's create an instance of our window inside the application class. You don't have to take care about deleting it. It will happen automatically when the application closes.
29When a window is first created, it is hidden from the user. In order to make it show up, we have to call the show method like so.
31The last thing to do is create an instance of our application in the main function and call the run method. The application class must be instantiated only and exactly once.
34Let's open a terminal window and try to compile it. We mustn't forget to link our application against the Be library.
38Here is our window. Everything seems fine. However, when we close it, the application does not terminate. We have to do it manually by pressing Control C in the terminal window.
40Let's correct this issue. We'll need to override the method Quit Requested of our Window class. This method is triggered when the window is ordered to close by the user or the operating system.
42Whenever that happens, we will also instruct the application to close. This is done by posting it the quit message like so. Be underscore app is a global variable which points to the instance of the application class.
44Then we return true. That means that we allow the window to close. Returning false would mean that we tell the window to ignore the quit message.
46Now let's try to write some text on it. For this we are going to need another header - StringView.h.
48The StringView is an object that displays a desired text. Let's create one. Again, the API will take care of the cleanup, so we don't have to delete it afterwards.
50The first argument for our StringView is again a BeRect. The coordinates it specifies are relative to the upper-left corner of the parenting container.
52We will supply it with values such, that it would fill the whole window. The second argument is a name. The third one is the text that should be display in the StringView.
54Now we must use the method AddChild to tell the window that this StringView belongs to it.
56Let's compile to see our results.
60This concludes the tutorial. For more information you can visit the links displayed here.