basic start of an exemple of scene

This commit is contained in:
Edouard Dupin 2012-04-04 23:27:36 +02:00
parent 2fd3e01046
commit a88b4ecda2
3 changed files with 8 additions and 381 deletions

View File

@ -239,8 +239,6 @@ class MainWindows :public ewol::Windows
mySizerVert2->SubWidgetAdd(mybtColor);
m_drawer = new widgetDrawer();
m_drawer->SetFontSize(11);
m_drawer->SetFontNameNormal("freefont/FreeSerif.ttf");
m_drawer->SetExpendX(true);
m_drawer->SetExpendY(true);
m_drawer->SetFillX(true);
@ -332,7 +330,7 @@ class MainWindows :public ewol::Windows
if (NULL != tmpColorButton) {
color_ts tmpColor = tmpColorButton->GetCurrentColor();
if (NULL != m_drawer) {
m_drawer->SetColorOnSelected(tmpColor);
//m_drawer->SetColorOnSelected(tmpColor);
}
}
}

View File

@ -41,28 +41,7 @@
widgetDrawer::widgetDrawer(void)
{
m_fontNormal = -1;
m_fontSize = 15;
m_nearestDot = -1;
m_movingPoint = false;
m_textColorFg.red = 0.0;
m_textColorFg.green = 0.0;
m_textColorFg.blue = 0.0;
m_textColorFg.alpha = 1.0;
m_textColorBg.red = 0.0;
m_textColorBg.green = 0.0;
m_textColorBg.blue = 0.0;
m_textColorBg.alpha = 0.25;
m_triangleColor.red = 0.0;
m_triangleColor.green = 1.0;
m_triangleColor.blue = 0.0;
m_triangleColor.alpha = 1.0;
RegisterMultiCast(drawMsgGuiLinkNew);
RegisterMultiCast(drawMsgListElementChange);
SetCanHaveFocus(true);
}
widgetDrawer::~widgetDrawer(void)
@ -88,7 +67,7 @@ bool widgetDrawer::CheckObjectType(const char * const objectType)
if (objectType == TYPE_EOBJECT_WIDGET_DRAW_DRAWER) {
return true;
} else {
if(true == ewol::Widget::CheckObjectType(objectType)) {
if(true == ewol::Scene::CheckObjectType(objectType)) {
return true;
}
EWOL_ERROR("check error : \"" << TYPE_EOBJECT_WIDGET_DRAW_DRAWER << "\" != \"" << objectType << "\"");
@ -108,178 +87,11 @@ const char * const widgetDrawer::GetObjectType(void)
}
bool widgetDrawer::CalculateMinSize(void)
{
m_minSize.x = 50;
m_minSize.y = 50;
return true;
}
void widgetDrawer::OnDraw(void)
{
m_OObjectsColored[ m_currentDrawId].Draw();
m_OObjectsColoredElement[m_currentDrawId].Draw();
m_OObjectTextNormal[ m_currentDrawId].Draw();
}
#define BORDER_SIZE (2)
void widgetDrawer::OnRegenerateDisplay(void)
{
if (true == NeedRedraw()) {
// clean internal elements ...
m_OObjectTextNormal[ m_currentCreateId].SetFontID(m_fontNormal);
m_OObjectTextNormal[ m_currentCreateId].Clear();
m_OObjectsColored[ m_currentCreateId].Clear();
m_OObjectsColoredElement[m_currentCreateId].Clear();
// we set 3 pixels in the border (blue) and draw
color_ts bandColor;
bandColor.red = 0.0;
bandColor.green = 0.0;
bandColor.blue = 0.0;
bandColor.alpha = 0.2;
color_ts bgColor;
bgColor.red = 0.0;
bgColor.green = 0.0;
bgColor.blue = 1.0;
bgColor.alpha = 1.0;
m_OObjectsColored[m_currentCreateId].SetColor(bgColor);
m_OObjectsColored[m_currentCreateId].Rectangle( 0, 0, m_size.x, m_size.y);
// we set a white background... and we draw a square ...
bgColor.red = 0.8;
bgColor.green = 0.8;
bgColor.blue = 0.8;
bgColor.alpha = 1.0;
m_OObjectsColored[m_currentCreateId].SetColor(bgColor);
coord2D_ts drawPosStart;
coord2D_ts drawPosStop;
if (m_size.x < m_size.y) {
drawPosStart.x = BORDER_SIZE;
drawPosStart.y = BORDER_SIZE;
drawPosStop.x = m_size.x-2*BORDER_SIZE;
drawPosStop.y = m_size.x-2*BORDER_SIZE;
} else {
drawPosStart.x = BORDER_SIZE;
drawPosStart.y = BORDER_SIZE;
drawPosStop.x = m_size.y-2*BORDER_SIZE;
drawPosStop.y = m_size.y-2*BORDER_SIZE;
}
m_OObjectsColored[m_currentCreateId].Rectangle(drawPosStart.x, drawPosStart.y, drawPosStop.x, drawPosStop.y);
m_OObjectsColored[m_currentCreateId].SetColor(bandColor);
clipping_ts clip;
clip.x = drawPosStart.x;
clip.y = drawPosStart.y;
clip.w = drawPosStop.x-drawPosStart.x + 2;
clip.h = drawPosStop.y-drawPosStart.y + 2;
m_OObjectsColored[m_currentCreateId].clippingSet(clip);
int32_t nbElement = (drawPosStop.x-drawPosStart.x)/20 +1;
for (int32_t iii=0; iii<nbElement; iii++) {
m_OObjectsColored[m_currentCreateId].Rectangle(drawPosStart.x + iii*20, drawPosStart.y, 10, drawPosStop.y);
}
nbElement = (drawPosStop.y-drawPosStart.y)/20 +1;
for (int32_t iii=0; iii<nbElement; iii++) {
m_OObjectsColored[m_currentCreateId].Rectangle(drawPosStart.x, drawPosStart.y + iii*20, drawPosStop.x, 10);
}
m_OObjectsColored[m_currentCreateId].clippingDisable();
coord2D_ts drawSize;
drawSize.x = drawPosStop.x-drawPosStart.x;
drawSize.y = drawPosStop.y-drawPosStart.y;
m_OObjectsColoredElement[m_currentCreateId].scalingSet(drawSize);
int32_t nbElements = drawElement::Size();
for(int32_t iii=0; iii<nbElements; iii++) {
drawElement::Base* elementLocal = drawElement::Get(iii);
if (NULL != elementLocal) {
elementLocal->Draw(m_OObjectsColoredElement[m_currentCreateId]);
}
}
/*
m_OObjectsColored[m_currentCreateId].clippingDisable();
for (int32_t iii=0; iii<m_linkList.Size(); iii++) {
for (int32_t jjj=0; jjj<3; jjj++) {
// set color
m_OObjectsColored[m_currentCreateId].SetColor(m_linkList[iii].color[jjj]);
// Set the specific dot
int dotId = m_linkList[iii].dot[jjj];
coord2D_ts position;
position.x = BORDER_SIZE + m_dotList[dotId].x * (drawPosStop.x-drawPosStart.x);
position.y = BORDER_SIZE + m_dotList[dotId].y * (drawPosStop.y-drawPosStart.y);
m_OObjectsColored[m_currentCreateId].SetPoint(position);
}
}
// we set a white background... and we draw a square ...
bgColor.red = 1.0;
bgColor.green = 1.0;
bgColor.blue = 1.0;
bgColor.alpha = 1.0;
m_OObjectsColored[m_currentCreateId].SetColor(bgColor);
for (int32_t iii=0; iii<m_dotList.Size(); iii++) {
coord2D_ts position;
position.x = BORDER_SIZE + m_dotList[iii].x * (drawPosStop.x-drawPosStart.x);
position.y = BORDER_SIZE + m_dotList[iii].y * (drawPosStop.y-drawPosStart.y);
if (true == DotIsSelected(iii)) {
color_ts tmpColor;
tmpColor.red = 1.0;
tmpColor.green = 0.0;
tmpColor.blue = 0.0;
tmpColor.alpha = 1.0;
m_OObjectsColored[m_currentCreateId].SetColor(tmpColor);
m_OObjectsColored[m_currentCreateId].Rectangle( position.x-1, position.y-1, 3, 3);
m_OObjectsColored[m_currentCreateId].SetColor(bgColor);
} else {
m_OObjectsColored[m_currentCreateId].Rectangle( position.x-1, position.y-1, 3, 3);
}
if (m_nearestDot == iii) {
color_ts tmpColor;
tmpColor.red = 1.0;
tmpColor.green = 0.0;
tmpColor.blue = 1.0;
tmpColor.alpha = 1.0;
m_OObjectsColored[m_currentCreateId].SetColor(tmpColor);
m_OObjectsColored[m_currentCreateId].Circle( position.x, position.y, 6, 2);
m_OObjectsColored[m_currentCreateId].SetColor(bgColor);
}
}
*/
m_needFlipFlop = true;
}
}
bool widgetDrawer::OnEventKb(ewol::eventKbType_te typeEvent, uniChar_t unicodeData)
{
//DRAW_DEBUG("KB EVENT : \"" << unicodeData << "\"" << "type=" << (int32_t)typeEvent);
if (typeEvent == ewol::EVENT_KB_TYPE_UP) {
if (unicodeData == 0x7F) {
// Remove all selected points ...
for(int32_t iii=m_dotList.Size()-1 ; iii>=0 ; iii--) {
if (true == DotIsSelected(iii)) {
// Remove all link who have a selected point :
for(int32_t jjj=m_linkList.Size()-1; jjj>=0; jjj--) {
if( m_linkList[jjj].dot[0] == iii
|| m_linkList[jjj].dot[1] == iii
|| m_linkList[jjj].dot[2] == iii ) {
m_linkList.Erase(jjj);
}
}
m_dotList.Erase(iii);
for(int32_t jjj=m_linkList.Size()-1; jjj>=0; jjj--) {
if(m_linkList[jjj].dot[0] > iii) {
m_linkList[jjj].dot[0]--;
}
if(m_linkList[jjj].dot[1] > iii) {
m_linkList[jjj].dot[1]--;
}
if(m_linkList[jjj].dot[2] > iii) {
m_linkList[jjj].dot[2]--;
}
}
}
}
// rmemove all the selected list
m_selectedList.Clear();
MarkToReedraw();
}
}
return true;
}
@ -293,7 +105,7 @@ bool widgetDrawer::OnEventKbMove(ewol::eventKbType_te typeEvent, ewol::eventKbMo
return true;
}
/*
etkFloat_t widgetDrawer::QuadDistance(coord2D_ts aaa, coord2D_ts bbb)
{
etkFloat_t xxx = aaa.x - bbb.x;
@ -301,30 +113,7 @@ etkFloat_t widgetDrawer::QuadDistance(coord2D_ts aaa, coord2D_ts bbb)
return xxx*xxx + yyy*yyy;
}
int32_t widgetDrawer::GetNearestPoint(coord2D_ts pos)
{
int32_t idNearest = -1;
etkFloat_t smallestQuadDist = 10000000;
for (int32_t iii=0; iii<m_dotList.Size(); iii++) {
etkFloat_t dist = QuadDistance(pos, m_dotList[iii]);
if (dist < smallestQuadDist) {
smallestQuadDist = dist;
idNearest = iii;
}
}
return idNearest;
}
bool widgetDrawer::DotIsSelected(int32_t dotId)
{
for( int32_t iii=0; iii< m_selectedList.Size(); iii++) {
if (m_selectedList[iii] == dotId) {
return true;
}
}
return false;
}
*/
/**
* @brief Event on an input of this Widget
@ -337,82 +126,7 @@ bool widgetDrawer::DotIsSelected(int32_t dotId)
bool widgetDrawer::OnEventInput(int32_t IdInput, ewol::eventInputType_te typeEvent, coord2D_ts pos)
{
coord2D_ts relativePos = RelativePosition(pos);
coord2D_ts drawPosStart;
coord2D_ts drawPosStop;
if (m_size.x < m_size.y) {
drawPosStart.x = BORDER_SIZE;
drawPosStart.y = BORDER_SIZE;
drawPosStop.x = m_size.x-2*BORDER_SIZE;
drawPosStop.y = m_size.x-2*BORDER_SIZE;
} else {
drawPosStart.x = BORDER_SIZE;
drawPosStart.y = BORDER_SIZE;
drawPosStop.x = m_size.y-2*BORDER_SIZE;
drawPosStop.y = m_size.y-2*BORDER_SIZE;
}
coord2D_ts position;
position.x = (relativePos.x - BORDER_SIZE) / (drawPosStop.x-drawPosStart.x);
position.y = (relativePos.y - BORDER_SIZE) / (drawPosStop.y-drawPosStart.y);
position.x = etk_avg(0, position.x, 1);
position.y = etk_avg(0, position.y, 1);
//DRAW_DEBUG(" event " << IdInput);
if (0 == IdInput) {
m_nearestDot = GetNearestPoint(position);
MarkToReedraw();
} else if (1 == IdInput) {
KeepFocus();
if ( ewol::EVENT_INPUT_TYPE_SINGLE == typeEvent) {
// try to find the point
int select = GetNearestPoint(position);
if (false == ewol::IsSetShift() ) {
m_selectedList.Clear();
m_selectedList.PushBack(select);
MarkToReedraw();
} else {
if (false == DotIsSelected(select)) {
// add element in the list
m_selectedList.PushBack(select);
MarkToReedraw();
} else {
// remove it ...
for (int32_t iii=m_selectedList.Size()-1 ; iii>=0 ; iii--) {
if (m_selectedList[iii] == select) {
m_selectedList.Erase(iii);
}
}
}
}
} if ( ewol::EVENT_INPUT_TYPE_DOWN == typeEvent) {
// try to find the point
int select = GetNearestPoint(position);
if (m_selectedList.Size() == 1) {
if (select == m_selectedList[0]) {
MarkToReedraw();
m_movingPoint = true;
}
}
} else if (ewol::EVENT_INPUT_TYPE_UP == typeEvent) {
m_movingPoint = false;
MarkToReedraw();
} else if (ewol::EVENT_INPUT_TYPE_MOVE == typeEvent && true == m_movingPoint) {
if (m_selectedList.Size() != 1) {
m_movingPoint = false;
return false;
}
// set it in the drawing area
relativePos.x = etk_avg(drawPosStart.x, relativePos.x, drawPosStop.x);
relativePos.y = etk_avg(drawPosStart.y, relativePos.y, drawPosStop.y);
// instanciate the value ...
m_dotList[m_selectedList[0]] = position;
MarkToReedraw();
}
} else if (3 == IdInput && ewol::EVENT_INPUT_TYPE_SINGLE == typeEvent) {
m_dotList.PushBack(position);
MarkToReedraw();
}
return true;
}
@ -428,56 +142,6 @@ bool widgetDrawer::OnEventInput(int32_t IdInput, ewol::eventInputType_te typeEve
void widgetDrawer::OnReceiveMessage(ewol::EObject * CallerObject, const char * eventId, etk::UString data)
{
DRAW_DEBUG("Extern Event : " << CallerObject << " type : " << eventId << " data=\"" << data << "\"");
if (eventId == drawMsgGuiLinkNew) {
if (m_selectedList.Size() == 3) {
link_ts tmpLink;
tmpLink.dot[0] = m_selectedList[0];
tmpLink.dot[1] = m_selectedList[1];
tmpLink.dot[2] = m_selectedList[2];
tmpLink.color[0] = m_triangleColor;
tmpLink.color[1] = m_triangleColor;
tmpLink.color[2] = m_triangleColor;
m_linkList.PushBack(tmpLink);
MarkToReedraw();
}
} else if (eventId == drawMsgListElementChange) {
MarkToReedraw();
}
}
void widgetDrawer::SetFontSize(int32_t size)
{
m_fontSize = size;
}
void widgetDrawer::SetFontNameNormal(etk::UString fontName)
{
int32_t fontID = ewol::LoadFont(fontName, m_fontSize);
if (fontID >= 0) {
m_fontNormal = fontID;
}
}
void widgetDrawer::SetColorOnSelected(color_ts newColor)
{
m_triangleColor = newColor;
// Remove all selected points ...
for(int32_t iii=0; iii<m_dotList.Size() ; iii++) {
if (true == DotIsSelected(iii)) {
// Remove all link who have a selected point :
for(int32_t jjj=0 ; jjj<m_linkList.Size() ; jjj++) {
if(m_linkList[jjj].dot[0] == iii) {
m_linkList[jjj].color[0] = newColor;
}
if(m_linkList[jjj].dot[1] == iii) {
m_linkList[jjj].color[1] = newColor;
}
if(m_linkList[jjj].dot[2] == iii) {
m_linkList[jjj].color[2] = newColor;
}
}
}
}
MarkToReedraw();
}

View File

@ -28,17 +28,14 @@
#include <widgetDrawer.h>
#include <globalMsg.h>
#include <ewol/Widget.h>
#include <ewol/widget/Scene.h>
#include <etk/Types.h>
typedef struct {
int32_t dot[3];
color_ts color[3];
} link_ts;
extern const char * const TYPE_EOBJECT_WIDGET_DRAW_DRAWER;
class widgetDrawer :public ewol::Widget
class widgetDrawer :public ewol::Scene
{
public:
widgetDrawer(void);
@ -58,18 +55,7 @@ class widgetDrawer :public ewol::Widget
* @return true if the object is compatible, otherwise false
*/
virtual const char * const GetObjectType(void);
virtual bool CalculateMinSize(void);
private:
color_ts m_triangleColor; //!< color for the next element of the triangle
color_ts m_textColorFg; //!< Text color
color_ts m_textColorBg; //!< Background color
// drawing elements :
ewol::OObject2DTextColored m_OObjectTextNormal[NB_BOUBLE_BUFFER];
ewol::OObject2DColored m_OObjectsColored[NB_BOUBLE_BUFFER];
ewol::OObject2DColored m_OObjectsColoredElement[NB_BOUBLE_BUFFER];
public:
virtual void OnRegenerateDisplay(void);
/**
* @brief Receive a message from an other EObject with a specific eventId and data
* @param[in] CallerObject Pointer on the EObject that information came from
@ -97,27 +83,6 @@ class widgetDrawer :public ewol::Widget
*/
virtual bool OnEventKb(ewol::eventKbType_te typeEvent, uniChar_t unicodeData);
virtual bool OnEventKbMove(ewol::eventKbType_te typeEvent, ewol::eventKbMoveType_te moveTypeEvent);
private:
int32_t m_fontSize;
int32_t m_fontNormal;
public:
void SetFontSize(int32_t size);
void SetFontNameNormal(etk::UString fontName);
void SetColorOnSelected(color_ts newColor);
protected:
virtual void OnDraw(void);
private:
etk::VectorType<coord2D_ts> m_dotList; //!< list of all point in the buffer
etk::VectorType<link_ts> m_linkList; //!< List of all triangle in the mesh
etk::VectorType<int32_t> m_selectedList; //!< current selected points
int32_t m_nearestDot; //!< nearest dot from the current cursor
bool m_movingPoint;
void removeDotId(int32_t id);
int32_t GetNearestPoint(coord2D_ts pos);
etkFloat_t QuadDistance(coord2D_ts aaa, coord2D_ts bbb);
bool DotIsSelected(int32_t dotId);
public:
};
#define DRAW_CAST_WIDGET_DRAWER(curentPointer) EWOL_CAST(TYPE_EOBJECT_WIDGET_DRAW_DRAWER,ewol::widgetDrawer,curentPointer)