Lesson2: Buttons
/*
+--------------------------------------------------------------------------
| 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
|
+---------------------------------------------------------------------------
*/
Lesson2: Buttons
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 second lesson.
We will add to our window a button to exit from application.
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 button creation.
These are the main Api about button creation and managing:
Ok now that we have listed the main API we can write the code.
You can fnd the complete application code in the attach package
(bibledemo.cpp). Here i will comment only the code added in this
lesson.
Let'go.
bibledemo.cpp additions:
First of all we have to add to our include files the Enigma button library:
Ok Now we have to add the button in our main class. This is the new class declaration:
Perfect !! Now we have to add the button in our main function code
This is our new main Function:
As you can see is very simply.
You can now exercise to compile source you find in the attach package and to modify it.
Exercises:
- Change the button text shortcut and position
- Add another button
That's all, and this is the application shot and the complete package.
(to be continued in lesson 3 ... )
+--------------------------------------------------------------------------
| 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
|
+---------------------------------------------------------------------------
*/
Lesson2: Buttons
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 second lesson.
We will add to our window a button to exit from application.
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 button creation.
These are the main Api about button creation and managing:
Code:
// create button eButton(eWidget *parent); // set button text setText(eString string); // positioning move(ePoint(x, y)); // sizing resize(eSize(x, y)); // set shortcut and pixmap setShortcut(int color); setShortcutPixmap(int pixmap); // decore with a frame loadDeco(); // function to call when button is pressed CONNECT(eButton->selected, function);
You can fnd the complete application code in the attach package
(bibledemo.cpp). Here i will comment only the code added in this
lesson.
Let'go.
bibledemo.cpp additions:
First of all we have to add to our include files the Enigma button library:
Code:
#include <lib/gui/ebutton.h>
Code:
// The Class declaration of our Main Window class eBibleMainWindow: public eWindow { // the label to show the text eLabel *label; // the button eButton *ok; public: // the constructor. eBibleMainWindow(); // the destructor. ~eBibleMainWindow(); };
This is our new main Function:
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 2: Button"); // 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("Push button to exit !!"); // create the button ok = new eButton(this); // set the button text ok->setText("Exit"); // set position ok->move(ePoint((clientrect.width() - 90)/2, clientrect.height() - 60)); // set size ok->resize(eSize(90, 40)); // set shortcut and pixmap ok->setShortcut("green"); ok->setShortcutPixmap("green"); // decore with a frame ok->loadDeco(); // function to call when buton is pressed CONNECT(ok->selected, eWidget::accept); // set focus to the button setFocus(ok); }
You can now exercise to compile source you find in the attach package and to modify it.
Exercises:
- Change the button text shortcut and position
- Add another button
That's all, and this is the application shot and the complete package.
(to be continued in lesson 3 ... )