diff --git a/Makefile b/Makefile index 7ee19d2b..d3a4df58 100644 --- a/Makefile +++ b/Makefile @@ -164,6 +164,7 @@ CXXFILES += etk/etkDebug.cpp \ # Ewol Sources : CXXFILES += ewol.cpp \ ewolDebug.cpp \ + ewolOObject.cpp \ ewolWidget.cpp \ ewolWindows.cpp diff --git a/Sources/base/guiX11.cpp b/Sources/base/guiX11.cpp index 5567f54c..72b182f4 100644 --- a/Sources/base/guiX11.cpp +++ b/Sources/base/guiX11.cpp @@ -39,238 +39,18 @@ //#define TEST_MODE_1 -/* -bool guiAbstraction(Display *d, XEvent *e, char *arg) -{ - return (e->type == MapNotify) && (e->xmap.window == *(Window*)arg); -} -*/ - namespace guiAbstraction { -#ifdef TEST_MODE_1 - - #undef __class__ - #define __class__ "guiAbstraction::X11display" - class X11display - { - public: - X11display( etk::String name ) { - m_display = XOpenDisplay( name.c_str() ); - if(NULL == m_display) { - EWOL_CRITICAL("Could not open display named='" << name << "'."); - } else { - EWOL_INFO("Display opened named='" << name << "'."); - } - } - ~X11display() { - if( NULL != m_display ) { - XCloseDisplay ( m_display ); - m_display = 0; - } - } - Display * GetDisplay(void) - { - return m_display; - } - private: - Display* m_display; - }; - - #undef __class__ - #define __class__ "guiAbstraction::X11eventMng" - class X11eventMng - { - private: - ewol::Windows* m_uniqueWindows; - Display * m_display; - bool m_run; - public: - X11eventMng(X11display& d) : m_run(true), m_display(d.GetDisplay() ) - { - m_uniqueWindows = NULL; - } - - ~X11eventMng() - { - - } - - void Setwindow(ewol::Windows* newWindows) - { - m_uniqueWindows = newWindows; - } - - void Run() - { - m_run = true; - XEvent event; - while (m_run) { - while (XPending(m_display)) { - //... - // draw the current windows in every case ... - m_uniqueWindows->SysDraw(); - // For test, otherwithe the display leach all the CPU - usleep( 100000 ); - }//end if m_uniqueWindows - } - } - - void Stop() - { - m_run = false; - } - - Display * GetDisplay(void) - { - return m_display; - } - - }; - - const int event_mask = ExposureMask - | ButtonPressMask - | ButtonReleaseMask - | EnterWindowMask - | LeaveWindowMask - | PointerMotionMask - | FocusChangeMask - | KeyPressMask - | KeyReleaseMask - | SubstructureNotifyMask - | StructureNotifyMask - | SubstructureRedirectMask; - - - #undef __class__ - #define __class__ "guiAbstraction::X11Windows" - class X11Windows - { - private: - Display * m_display; - Window m_window; - X11eventMng& m_event_dispatcher; - Atom m_atom[1]; - - size_ts m_size; - position_ts m_position; - private: - // Not copyable - X11Windows(const X11Windows&); - void operator=(X11Windows&); - public: - X11Windows(X11eventMng& e) - : m_display(e.GetDisplay()), - m_event_dispatcher(e) - { - m_window = 0; - m_atom[0] = 0; - if(!m_window) { - int Xscreen = DefaultScreen((void*)m_display); - Window Xroot = RootWindow((void*)m_display, Xscreen); - //RootWindow((void*)m_display,0) - - m_window = XCreateSimpleWindow(m_display, - Xroot, - 20, // origin X - 20, // origin Y - 300, // Width - 200, //Height - 0, - WhitePixel((void*)m_display,0), - WhitePixel((void*)m_display,0)); - //set_background ( m_background ); - if(0==m_window) { - EWOL_CRITICAL("Could not create the basic window"); - } - } - //m_event_dispatcher.Setwindow(this); - Show(); - } - - ~X11Windows(void) - { - Hide(); - if(m_window) { - XDestroyWindow(m_display, m_window); - m_window = 0; - } - m_event_dispatcher.Setwindow(NULL); - } - private: - // - // From window_base: - // - virtual void Show(void) - { - XSelectInput(m_display, m_window, guiAbstraction::event_mask); - XMapWindow(m_display, m_window); - XFlush(m_display); - } - - virtual void Hide(void) - { - XUnmapWindow(m_display, m_window); - XFlush(m_display); - } - - /* - - virtual void set_background(color& c) - { - // hold a ref to the alloc'ed color - m_background.set(c); - XSetWindowBackground(m_display, m_window, c.pixel()); - refresh(); - } - - virtual void set_focus(void) - { - XSetInputFocus(m_display, id(), RevertToParent, CurrentTime ); - refresh(); - } - virtual void refresh(void) - { - XClearWindow(m_display, m_window); - XFlush(m_display); - on_expose(); - } - - virtual rectangle get_rect(void) - { - Window root; - int x = 0, y = 0; - unsigned int width = 0, height = 0, border_width = 0, depth = 0; - XGetGeometry(m_display, - m_window, - &root, - &x, - &y, - &width, - &height, - &border_width, - &depth); - return rectangle(point(x,y), width, height ); - } - */ - virtual long Id(void) - { - return m_window; - } - - - Display * GetDisplay(void) - { - return m_display; - } - - virtual X11eventMng& get_event_dispatcher(void) - { - return m_event_dispatcher; - } - - }; -#else + extern "C" { + typedef struct Hints + { + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long inputMode; + unsigned long status; + } Hints; + } class X11systemInterface { private: @@ -285,13 +65,12 @@ namespace guiAbstraction { bool CreateX11Context(void) { - XEvent event; int x,y, attr_mask; XSizeHints hints; XWMHints *StartupState; XTextProperty textprop; XSetWindowAttributes attr; - static char *title = (char*)"FTB's little OpenGL example"; + static char *title = (char*)"APPLICATION Title ... (todo)"; // Connect to the X server m_display = XOpenDisplay(NULL); @@ -316,7 +95,7 @@ namespace guiAbstraction { GLX_DEPTH_SIZE, 1, None }; - XVisualInfo *visual; + XVisualInfo *visual = NULL; GLXFBConfig *fbconfigs = glXChooseFBConfig(m_display, Xscreen, VisualData, &numfbconfigs); for(int i = 0; iSysOnKill(); } @@ -527,13 +327,15 @@ namespace guiAbstraction { switch (event.type) { case ConfigureNotify: - EWOL_DEBUG("Change Windows Size : (" << event.xconfigure.width << "," << event.xconfigure.height << ")"); + EWOL_DEBUG("X11 event : " << event.type << " = \"ConfigureNotify\" Origin(" << event.xconfigure.x << "," << event.xconfigure.y << ") Size(" << event.xconfigure.width << "," << event.xconfigure.height << ")"); m_uniqueWindows->CalculateSize((double)event.xconfigure.width, (double)event.xconfigure.height); break; case Expose: + EWOL_DEBUG("X11 event : " << event.type << " = \"Expose\""); m_uniqueWindows->SysOnExpose(); break; case ButtonPress: + EWOL_DEBUG("X11 event : " << event.type << " = \"ButtonPress\" (" << (double)event.xbutton.x << "," << (double)event.xbutton.y << ")"); if ( event.xbutton.button & Button2 ) { m_uniqueWindows->GenEventInput(2, ewol::EVENT_INPUT_TYPE_DOWN, (double)event.xbutton.x, (double)event.xbutton.y); } else if (event.xbutton.button & Button1) { @@ -541,6 +343,7 @@ namespace guiAbstraction { } break; case ButtonRelease: + EWOL_DEBUG("X11 event : " << event.type << " = \"ButtonRelease\" (" << (double)event.xbutton.x << "," << (double)event.xbutton.y << ")"); if(event.xbutton.button & Button2) { m_uniqueWindows->GenEventInput(2, ewol::EVENT_INPUT_TYPE_UP, (double)event.xbutton.x, (double)event.xbutton.y); } else if (event.xbutton.button & Button1) { @@ -548,22 +351,28 @@ namespace guiAbstraction { } break; case EnterNotify: + EWOL_DEBUG("X11 event : " << event.type << " = \"EnterNotify\" (" << (double)event.xcrossing.x << "," << (double)event.xcrossing.y << ")"); m_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_ENTER, (double)event.xcrossing.x, (double)event.xcrossing.y); break; case MotionNotify: + EWOL_DEBUG("X11 event : " << event.type << " = \"MotionNotify\" (" << (double)event.xmotion.x << "," << (double)event.xmotion.y << ")"); m_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_MOVE, (double)event.xmotion.x, (double)event.xmotion.y); break; case LeaveNotify: + EWOL_DEBUG("X11 event : " << event.type << " = \"LeaveNotify\" (" << (double)event.xcrossing.x << "," << (double)event.xcrossing.y << ")"); m_uniqueWindows->GenEventInput(0, ewol::EVENT_INPUT_TYPE_LEAVE, (double)event.xcrossing.x, (double)event.xcrossing.y); break; case FocusIn: + EWOL_DEBUG("X11 event : " << event.type << " = \"FocusIn\""); m_uniqueWindows->SetFocus(); break; case FocusOut: + EWOL_DEBUG("X11 event : " << event.type << " = \"FocusOut\""); m_uniqueWindows->RmFocus(); break; case KeyPress: case KeyRelease: + EWOL_DEBUG("X11 event : " << event.type << " = \"KeyPress/KeyRelease\" "); { char buf[11]; KeySym keysym; @@ -580,11 +389,15 @@ namespace guiAbstraction { //case DestroyNotify: // break; case MapNotify: + EWOL_DEBUG("X11 event : " << event.type << " = \"MapNotify\""); m_uniqueWindows->SysOnShow(); break; case UnmapNotify: + EWOL_DEBUG("X11 event : " << event.type << " = \"UnmapNotify\""); m_uniqueWindows->SysOnHide(); break; + default: + EWOL_DEBUG("X11 event : " << event.type << " = \"???\""); } } } @@ -598,11 +411,6 @@ namespace guiAbstraction { m_run = false; } }; - -#endif - - - }; diff --git a/Sources/ewolOObject.cpp b/Sources/ewolOObject.cpp new file mode 100644 index 00000000..d81f7327 --- /dev/null +++ b/Sources/ewolOObject.cpp @@ -0,0 +1,117 @@ +/** + ******************************************************************************* + * @file ewolOObject.cpp + * @brief ewol OpenGl Object system (Sources) + * @author Edouard DUPIN + * @date 24/10/2011 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#include +#include +#include +#include + + + + + +void ewol::OObject2DColored::Draw(void) +{ + if (m_coord.Size()<=0) { + return; + } + // Enable Pointers + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_COLOR_ARRAY ); + + + // Set the vertex pointer to our vertex data + glVertexPointer(2, GL_FLOAT, 0, &m_coord[0] ); + glColorPointer(4, GL_FLOAT, 0, &m_coordColor[0] ); + // Render : draw all of the triangles at once + glDrawArrays( GL_TRIANGLES, 0, m_coord.Size()); + //EWOL_DEBUG("Draw ..." << m_coord.Size()/3 << " triangle(s)"); + + // Disable Pointers + glDisableClientState( GL_VERTEX_ARRAY ); + glDisableClientState( GL_COLOR_ARRAY ); + +} + + +void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h, float red, float green, float blue, float alpha) +{ + //EWOL_DEBUG("Add rectangle : ..."); + coord2D_ts point; + color_ts color; + + color.red = red; + color.green = green; + color.blue = blue; + color.alpha = alpha; + + point.x = x; + point.y = y + h; + m_coord.PushBack(point); + m_coordColor.PushBack(color); + + point.x = x; + point.y = y; + m_coord.PushBack(point); + m_coordColor.PushBack(color); + + point.x = x + w; + point.y = y; + m_coord.PushBack(point); + m_coordColor.PushBack(color); + + m_coord.PushBack(point); + m_coordColor.PushBack(color); + + point.x = x + w; + point.y = y + h; + m_coord.PushBack(point); + m_coordColor.PushBack(color); + + point.x = x; + point.y = y + h; + m_coord.PushBack(point); + m_coordColor.PushBack(color); + +} + + + + + +/* +OObject2DTextured::Draw(void) +{ + if (m_coord.Size()<=0) { + return; + } + glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays + glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays + glVertexPointer( 3, GL_FLOAT, 0, &m_coord[0] ); + glTexCoordPointer( 2, GL_FLOAT, 0, &m_coordTex[0] ); + glDrawArrays( GL_TRIANGLES, 0, m_linkCoord.Size()); + glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays + glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays +} +*/ diff --git a/Sources/ewolOObject.h b/Sources/ewolOObject.h new file mode 100644 index 00000000..13aa2405 --- /dev/null +++ b/Sources/ewolOObject.h @@ -0,0 +1,101 @@ +/** + ******************************************************************************* + * @file ewolOObject.h + * @brief ewol OpenGl Object system (header) + * @author Edouard DUPIN + * @date 24/10/2011 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __EWOL_O_OBJECT_H__ +#define __EWOL_O_OBJECT_H__ + +#include +#include +#include + +namespace ewol { + extern "C" { + typedef struct { + float x; + float y; + float z; + }coord3D_ts; + typedef struct { + float x; + float y; + }coord2D_ts; + typedef struct { + float u; + float v; + }texCoord_ts; + typedef struct { + float red; + float green; + float blue; + float alpha; + }color_ts; + typedef struct { + int32_t f; + int32_t s; + int32_t t; + }linkCoord_ts; + }; + + class OObject + { + public: + OObject(void) {}; + virtual ~OObject(void) {}; + public: + virtual void Draw(void) = 0; + }; + + class OObject2DColored :public ewol::OObject + { + public: + OObject2DColored(void) {}; + virtual ~OObject2DColored(void) {}; + public: + virtual void Draw(void); + protected: + etk::VectorType m_coord; //!< internal coord of the object + etk::VectorType m_coordColor; //!< internal color of the different point + //etk::VectorType m_linkCoord; //!< internal link between point to generate triangle + public: + void Rectangle(float x, float y, float w, float h, float red, float green, float blue, float alpha); + }; + /* + class OObject2DTextured :public ewol::OObject + { + public: + OObject2DTextured(void) {}; + virtual ~OObject2DTextured(void) {}; + public: + virtual void Draw(void); + protected: + uint32_t m_textureId; //!< texture internal ID + etk::VectorType m_coord; //!< internal coord of the object + etk::VectorType m_coordTex; //!< internal texture coordinate for every point + etk::VectorType m_linkCoord; //!< internal link between point to generate triangle + }; + */ +}; + +#endif + diff --git a/Sources/ewolWindows.cpp b/Sources/ewolWindows.cpp index 56f6e99e..452f5247 100644 --- a/Sources/ewolWindows.cpp +++ b/Sources/ewolWindows.cpp @@ -26,11 +26,10 @@ #include #include #include -#include +#include + #include - - bool ewol::Windows::CalculateSize(double availlableX, double availlableY) { m_size.x = availlableX; @@ -38,12 +37,10 @@ bool ewol::Windows::CalculateSize(double availlableX, double availlableY) return true; } - - void ewol::Windows::SysDraw(void) { - static double ploppp = 0.1; - EWOL_DEBUG("Drow on (" << m_size.x << "," << m_size.y << ")"); + + //EWOL_DEBUG("Drow on (" << m_size.x << "," << m_size.y << ")"); // set the size of the open GL system glViewport(0,0,m_size.x,m_size.y); @@ -58,6 +55,34 @@ void ewol::Windows::SysDraw(void) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, -5); + + + static bool initDone = false; + static GLuint indexListe; + if (false == initDone) { + initDone = true; + // create one display list + indexListe = glGenLists(1); + // compile the display list, store a triangle in it + glNewList(indexListe, GL_COMPILE); + glBegin(GL_QUADS); + float plop2 = 0.2; + //glVertex3fv(v0); + glColor3f(1., 0., 0.); glVertex3f( plop2*m_size.x, plop2*m_size.y, 0.); + glColor3f(0., 1., 0.); glVertex3f( (1.0-plop2)*m_size.x, plop2*m_size.y, 0.); + glColor3f(0., 0., 1.); glVertex3f( (1.0-plop2)*m_size.x, (1.0-plop2)*m_size.y, 0.); + glColor3f(1., 1., 0.); glVertex3f( plop2*m_size.x, (1.0-plop2)*m_size.y, 0.); + glEnd(); + glEndList(); + + } + // destroy : glDeleteLists(indexListe, 1); + + + // draw the display list + glCallList(indexListe); + + static double ploppp = 0.1; //EWOL_DEBUG("plop is " << ploppp << " devient " << (1.0-ploppp) ); @@ -71,4 +96,15 @@ void ewol::Windows::SysDraw(void) if (ploppp>0.5) { ploppp = 0; } + + ewol::OObject2DColored myOObject; + + myOObject.Rectangle(20, 30, 100, 50, 1.0, 0.0, 0.0, 1.0); + myOObject.Rectangle(50, 50, 50, 50, 0.0, 1.0, 0.0, 1.0); + myOObject.Rectangle(80, 80, 100, 50, 0.0, 0.0, 1.0, 1.0); + myOObject.Rectangle(50, 00, 300, 300, 0.2, 0.2, 0.2, 0.5); + + myOObject.Draw(); + + } \ No newline at end of file