2016-09-16 22:35:06 +02:00
|
|
|
EWOL: Create a custom Widget {#ewol_tutorial_create_custom_widget}
|
|
|
|
============================
|
|
|
|
|
|
|
|
@tableofcontents
|
|
|
|
|
|
|
|
Objectifs: {#ewol_tutorial_create_custom_widget_objectif}
|
|
|
|
==========
|
2014-03-04 21:18:41 +01:00
|
|
|
|
|
|
|
To create a custum widget, this is as simple as complex.
|
|
|
|
The first things to do is to choice a methode to display you widget:
|
2016-09-16 22:35:06 +02:00
|
|
|
- [b]Direct mode:[/b] display on openGL engine with your prefered methode (some help for shaders)
|
|
|
|
- [b]Compositing:[/b] display with a toolbox for drawing on openGL
|
|
|
|
- [b]Shaper:[/b] this is a special mode of compositing
|
|
|
|
- [b]Add capacity:[/b] this could be interesting to increase some capacity of a widget...
|
|
|
|
|
|
|
|
Create the widget structure {#ewol_tutorial_create_custom_widget_structure}
|
|
|
|
===========================
|
|
|
|
|
|
|
|
Header
|
|
|
|
------
|
2014-03-04 21:18:41 +01:00
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
```{.cpp}
|
2016-10-02 23:49:03 +02:00
|
|
|
#include <ewol/widget/Widget.hpp>
|
|
|
|
#include <ewol/compisiting/Widget.hpp>
|
2014-03-04 21:18:41 +01:00
|
|
|
namespace appl {
|
|
|
|
class myWidget : public ewol::Widget {
|
2016-03-24 21:54:13 +01:00
|
|
|
private:
|
|
|
|
ewol::compositing::Drawing m_draw; //!< simple openGL drawing tool
|
2014-03-04 21:18:41 +01:00
|
|
|
public:
|
|
|
|
myWidget(void) {};
|
|
|
|
~myWidget(void) {};
|
|
|
|
public: // herited function
|
2016-03-24 21:54:13 +01:00
|
|
|
void onDraw(void);
|
2014-03-04 21:18:41 +01:00
|
|
|
void onRegenerateDisplay(void);
|
|
|
|
}
|
|
|
|
}
|
2016-09-16 22:35:06 +02:00
|
|
|
```
|
2014-03-04 21:18:41 +01:00
|
|
|
|
2016-03-24 21:54:13 +01:00
|
|
|
We can show that we have two function, the first is call every time we render the widget (as the number of fps) "onDraw()".
|
2014-03-04 21:18:41 +01:00
|
|
|
And the second that is call only when we need to redraw the widget (after the user call markToRedraw() ) "onRegenerateDisplay()".
|
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
basic code
|
|
|
|
----------
|
2014-03-04 21:18:41 +01:00
|
|
|
|
2016-03-24 21:54:13 +01:00
|
|
|
we can define some basic functions:
|
|
|
|
|
|
|
|
The constructor:
|
2016-09-16 22:35:06 +02:00
|
|
|
```{.cpp}
|
2016-03-24 21:54:13 +01:00
|
|
|
appl::myWidget::myWidget() {
|
|
|
|
addObjectType("appl::widget::VectorDisplay");
|
|
|
|
}
|
2016-09-16 22:35:06 +02:00
|
|
|
```
|
2016-03-24 21:54:13 +01:00
|
|
|
|
|
|
|
The draw function:
|
2016-09-16 22:35:06 +02:00
|
|
|
```{.cpp}
|
2016-03-24 21:54:13 +01:00
|
|
|
void appl::myWidget::onDraw() {
|
|
|
|
m_draw.draw();
|
|
|
|
}
|
2016-09-16 22:35:06 +02:00
|
|
|
```
|
2016-03-24 21:54:13 +01:00
|
|
|
|
|
|
|
The drawing area function (where we create the patern.).
|
2016-09-16 22:35:06 +02:00
|
|
|
```{.cpp}
|
2016-03-24 21:54:13 +01:00
|
|
|
void appl::myWidget::onRegenerateDisplay() {
|
|
|
|
//!< Check if we really need to redraw the display, if not needed, we redraw the previous data ...
|
|
|
|
if (needRedraw() == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// remove previous data
|
|
|
|
m_draw.clear();
|
|
|
|
// set background
|
|
|
|
m_draw.setColor(etk::color::black);
|
|
|
|
m_draw.setPos(vec2(0,0));
|
|
|
|
m_draw.rectangleWidth(m_size);
|
|
|
|
m_draw.setColor(etk::color::green);
|
|
|
|
m_draw.setPos(m_size*0.2);
|
|
|
|
m_draw.rectangleWidth(m_size*0.5);
|
|
|
|
}
|
2016-09-16 22:35:06 +02:00
|
|
|
```
|
2014-03-04 21:18:41 +01:00
|
|
|
|
|
|
|
|
2016-09-16 22:35:06 +02:00
|
|
|
A more complex sample is availlable in **"ewol-sample-CustomWidget"**
|
2014-03-04 21:18:41 +01:00
|
|
|
|