Enigma1 THE BIBLE - Lesson2: Buttons

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:
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);
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:
Code:
#include <lib/gui/ebutton.h>
Ok Now we have to add the button in our main class. This is the new class declaration:
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();
};
Perfect !! Now we have to add the button in our main function code
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);

}
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 ... )
Attached Images
File Type: pngosdshot.png (10.1 KB, 60 views)
Attached Files
File Type: ziplesson2.zip (8.5 KB, 55 views)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值