Commits

Anonymous committed 3c1379f

Added Win and Widgets classes, everything crash

  • Participants
  • Parent commits e4a40a3

Comments (0)

Files changed (12)

File essential/examples/01-hello/build_debug/hello

Binary file modified.

File essential/examples/01-hello/hello.cpp

     Reactor reactor;
 
     //Register any gadget you want to
-    Evas_Object *main_win;
-    registerObject("main_window", main_win);
+    reactor.registerObject(new Win("main_window", "Hello, World!"));
 
     //Run the reactor
     reactor.run();

File essential/include/Essential.hpp

 #ifndef Essential_hpp
 #define Essential_hpp
 
+#include "EvasObject.hpp"
+#include "Widget.hpp"
+#include "Win.hpp"
 #include "Reactor.hpp"
 
 #endif

File essential/include/EvasObject.hpp

     class EvasObject
     {
         public:
-            EvasObject(Evas_Object *ob);
+            EvasObject(Evas_Object *obj);
             virtual ~EvasObject();
+
+            /**
+             * The underlying Elementary obj
+             */
+            inline Evas_Object* obj(void) const { return raw_obj_; }
             void show();
-            void hide();
 
         private:
-            Evas_Object* obj_;
+            Evas_Object* raw_obj_;
     };
 }
 

File essential/include/Reactor.hpp

 #ifndef Reactor_hpp
 #define Reactor_hpp
 
-#include <Elementary.h>
+#include "EvasObject.hpp"
 #include <vector>
 #include <map>
 #include <string>
              * main loop
              */
             void run();
-            void registerObject(Evas_Object*);
+            void registerObject(EvasObject*);
 
         private:
-            std::vector<Evas_Object*> widgets_;
-            std::map<std::string, Evas_Object*> widget2obj_;
+            std::map<const std::string, EvasObject*> widget2obj_;
     };
 }
 #endif

File essential/include/Widget.hpp

+
+/*
+ * Copyright (c) 2012, Alfredo Di Napoli
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the authors nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ALFREDO DI NAPOLI ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL ALFREDO DI NAPOLI BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef Widget_hpp
+#define Widget_hpp
+
+#include "EvasObject.hpp"
+
+namespace Essential
+{
+    class Widget: public EvasObject
+    {
+        public:
+            Widget(Evas_Object *obj);
+            virtual ~Widget();
+            //Probably a lot of methods here...
+    };
+}
+
+#endif

File essential/include/Win.hpp

+/*
+ * Copyright (c) 2012, Alfredo Di Napoli
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the authors nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ALFREDO DI NAPOLI ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL ALFREDO DI NAPOLI BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef Win_hpp
+#define Win_hpp
+
+#include "Widget.hpp"
+#include <string>
+
+namespace Essential
+{
+    class Win: public Widget
+    {
+        public:
+            Win(const std::string& name, const std::string& title);
+            ~Win();
+    };
+}
+
+#endif

File essential/main.scons

 env = Environment()
 
+#Use clang as default compiler
+env.Replace(CXX = "clang++")
+
 lib_target  = "essential"
 lib_sources = Glob("src/*.cpp")
 
-env.ParseConfig('pkg-config elementary --cflags --libs')
-env.SharedLibrary(target = lib_target, source = lib_sources)
-
 env.Append(CPPPATH = [
     './include',
     '/usr/local/include',
     '/usr/include/efreet-1',
     '/usr/include/ethumb-1'
 ])
+
+env.Append(CCFLAGS = [
+  '-std=c++11',
+  '-stdlib=libstdc++'
+])
+env.ParseConfig('pkg-config elementary --cflags --libs')
+env.SharedLibrary(target = lib_target, source = lib_sources)
+

File essential/src/EvasObject.cpp

 
 namespace Essential
 {
-    EvasObject::EvasObject(EvasObject *obj):
-        obj_(obj)
+    EvasObject::EvasObject(Evas_Object *obj):
+        raw_obj_(obj)
     {
         //NO-OP
     }
 
     void EvasObject::show()
     {
-        if(obj_ != nullptr)
-            evas_object_show(obj_);
+        if(raw_obj_ != nullptr)
+            evas_object_show(raw_obj_);
         //TODO
     }
-
-    void EvasObject::hide()
-    {
-        //TODO, how to hide?
-    }
 }

File essential/src/Reactor.cpp

 
     Reactor::~Reactor()
     {
+        //Delete every attached object
+        for(auto pair : widget2obj_)
+          delete pair.second;
+
         //Invoke Elementary Shutdown
         elm_shutdown();
     }
 
-    void registerObject(const std::string& name, Evas_Object* obj)
+    void Reactor::registerObject(EvasObject* obj)
     {
+        Evas_Object *raw_obj = obj->obj();
+        const std::string name(evas_object_name_get(raw_obj));
+        widget2obj_[name] = obj;
 
         //By default, set the obj visible
+        obj->show();
     }
 
     void Reactor::run()

File essential/src/Widget.cpp

+/*
+ * Copyright (c) 2012, Alfredo Di Napoli
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the authors nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ALFREDO DI NAPOLI ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL ALFREDO DI NAPOLI BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "Widget.hpp"
+
+namespace Essential
+{
+    Widget::Widget(Evas_Object *obj):
+        EvasObject(obj)
+    {
+        //NO-OP
+    }
+
+    Widget::~Widget()
+    {
+        //NO-OP
+    }
+}

File essential/src/Win.cpp

+/*
+ * Copyright (c) 2012, Alfredo Di Napoli
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the authors nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ALFREDO DI NAPOLI ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL ALFREDO DI NAPOLI BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "Win.hpp"
+
+namespace Essential
+{
+    Win::Win(const std::string& name, const std::string& title):
+        Widget(elm_win_util_standard_add(name.c_str(), title.c_str()))
+    {
+      //TODO
+    }
+
+    Win::~Win()
+    {
+      //NO-OP
+    }
+}