Lesson1: Hello World Window
/*
+--------------------------------------------------------------------------
| The Bible Enigma1 Tutorial
| ========================================
| By: Bacicciosat aka Meo aka Luponero
|
| Enigma 1 API GUI tutorial with Sources Code and Comments
| (c) august 2006 by Meo
|
+---------------------------------------------------------------------------
*/
Lesson1: Hello World Window
You can find in attach:
- the cfg file (Bibledemo.cfg)
- the compiled and working plugin (Bibledemo.so)
- the source file (bibledemo.cpp)
- the makefile (nedeed to compile code if you want to modify source)
Ok this is the first lesson.
We will create an Enigma application (a plugin) that will show in your dremabox a simple window displayng the message "Hello World".
You can see the example in the screenshot.
You can test this application simply uploading in your dreambox (/var/tuxbox/plugins) the files that you can find in attach: Bibledemo.cfg and Bibledemo.so
You can modify this application editing the source file bibledemo.cpp and recompiling it to have a new Bibledemo.so file.
The Enigma API we will explain in this lesson is the Window creation.
This are the main Api about window creation:
Ok now that we have listed the main API we can write the code.
In this first lesson i will post here all the code commenting it line by line.
Let'go.
bibledemo.cpp:
First of all we have to include all the libraries we need for our application (in this case we need: the Enigma plugin library, the standard C library, the Enigma ewndow library to create the widnows and the Enigma elabel library to insert the text in a label) :
Ok Now we have to declare the class we will use in our application:
Perfect !! Now we have to add the function that Enigma will call to execute our application. The "Entry point".
The code execution is started. now we can add the code to create our window and to show our message "Hello World".
In this code we:
1) Create our Main Window
2) Give to our Window a position in the screen
3) Give to our window X and Y dimensions
4) Set the Window Title
5) Create a label to show the message
6) Give to the label position and dimensions
7) Insert the message in the label
Finally we have to add only an automatic function to windows destroing. We have to do nothing. Only add this standard and automatic function:
As you can see is very simply.
You can now exercize to compile source you find in the attach package and to modify it.
Exercises:
- Change the window title
- Change the window position and dimensions
- Change label position inside the window
That's all, and this is the apllication shot and the complete package.
(to be continued in lesson 2 ... )
+--------------------------------------------------------------------------
| The Bible Enigma1 Tutorial
| ========================================
| By: Bacicciosat aka Meo aka Luponero
|
| Enigma 1 API GUI tutorial with Sources Code and Comments
| (c) august 2006 by Meo
|
+---------------------------------------------------------------------------
*/
Lesson1: Hello World Window
You can find in attach:
- the cfg file (Bibledemo.cfg)
- the compiled and working plugin (Bibledemo.so)
- the source file (bibledemo.cpp)
- the makefile (nedeed to compile code if you want to modify source)
Ok this is the first lesson.
We will create an Enigma application (a plugin) that will show in your dremabox a simple window displayng the message "Hello World".
You can see the example in the screenshot.
You can test this application simply uploading in your dreambox (/var/tuxbox/plugins) the files that you can find in attach: Bibledemo.cfg and Bibledemo.so
You can modify this application editing the source file bibledemo.cpp and recompiling it to have a new Bibledemo.so file.
The Enigma API we will explain in this lesson is the Window creation.
This are the main Api about window creation:
Code:
// create window eWindow(int takefocus=0); // destruct window ~eWindow(); // set window title setText(eString string); // positioning cmove(ePoint(x, y)); // sizing cresize(eSize(x, y));
In this first lesson i will post here all the code commenting it line by line.
Let'go.
bibledemo.cpp:
First of all we have to include all the libraries we need for our application (in this case we need: the Enigma plugin library, the standard C library, the Enigma ewndow library to create the widnows and the Enigma elabel library to insert the text in a label) :
Code:
#include <plugin.h> #include <stdio.h> #include <lib/gui/ewindow.h> #include <lib/gui/elabel.h>
Code:
// The Class declaration of our Main Window class eBibleMainWindow: public eWindow { // the label to show the text eLabel *label; public: // the constructor. eBibleMainWindow(); // the destructor. ~eBibleMainWindow(); };
Code:
// The plugin entry point, Here start the code execution extern "C" int plugin_exec( PluginParam *par ) { // our demo dialog instance. eBibleMainWindow dlg; // show the dialog... dlg.show(); // give control to dialog.. (the dialog is modal!) int result=dlg.exec(); // and after it, hide it again. dlg.hide(); return result; }
In this code we:
1) Create our Main Window
2) Give to our Window a position in the screen
3) Give to our window X and Y dimensions
4) Set the Window Title
5) Create a label to show the message
6) Give to the label position and dimensions
7) Insert the message in the label
Code:
eBibleMainWindow::eBibleMainWindow(): eWindow(1) { // move our dialog to 100.100... cmove(ePoint(100, 100)); // ...and give x and y dimensions. cresize(eSize(520, 376)); // set a title. setText("Enigma Bible Lesson 1: Window"); // create a label to show a text. label=new eLabel(this); // give a position label->move(ePoint(50, 50)); // set the label dimensions label->resize(eSize(200, 100)); // set the label text label->setText("Hello World !!"); }
Code:
eBibleMainWindow::~eBibleMainWindow() { // we have to do almost nothing here. all widgets are automatically removed // since they are child of us. the eWidget-destructor will to this for us. }
You can now exercize to compile source you find in the attach package and to modify it.
Exercises:
- Change the window title
- Change the window position and dimensions
- Change label position inside the window
That's all, and this is the apllication shot and the complete package.
(to be continued in lesson 2 ... )