Enigma1 THE BIBLE - Lesson1: Hello World Window

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:
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));
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) :
Code:
#include <plugin.h>
#include <stdio.h>
#include <lib/gui/ewindow.h>
#include <lib/gui/elabel.h>
Ok Now we have to declare the class we will use in our application:
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();
};
Perfect !! Now we have to add the function that Enigma will call to execute our application. The "Entry point".
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;
}
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
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 !!");
}
Finally we have to add only an automatic function to windows destroing. We have to do nothing. Only add this standard and automatic function:
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.
}
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 ... )
Attached Images
File Type: pngosdshot.png (9.7 KB, 92 views)
Attached Files
File Type: ziplesson1.zip (7.3 KB, 102 views)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值