Author Topic: Patches for CB Scripted Wizards  (Read 6290 times)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Patches for CB Scripted Wizards
« on: February 09, 2016, 03:16:36 am »
My first two patches for the GTK+ and GLFW Wizards. I have also added the patches as attachments.

Code
From d275a6271d3cb7e2a54b6bb9734c9d83f4aae84d Mon Sep 17 00:00:00 2001
From: Tim S <stahta01@users.sourceforge.net>
Date: Sat, 9 Jan 2016 15:23:15 -0500
Subject: [PATCH 1/5] * scriptedwizard: Added support for GTK+ v3. (Thanks
 stahta01)

Added GTK2 and GTK3 version selection page to GTK Wizard.
And, added v3files/main.c file.
---
 .../scriptedwizard/resources/gtk/Makefile.am       |  4 ++
 .../scriptedwizard/resources/gtk/v3files/main.c    | 49 ++++++++++++++++++++++
 .../scriptedwizard/resources/gtk/wizard.script     | 42 +++++++++++--------
 3 files changed, 77 insertions(+), 18 deletions(-)
 create mode 100644 src/plugins/scriptedwizard/resources/gtk/v3files/main.c

diff --git a/src/plugins/scriptedwizard/resources/gtk/Makefile.am b/src/plugins/scriptedwizard/resources/gtk/Makefile.am
index 42ca1c1..491399e 100644
--- a/src/plugins/scriptedwizard/resources/gtk/Makefile.am
+++ b/src/plugins/scriptedwizard/resources/gtk/Makefile.am
@@ -7,3 +7,7 @@ dist_pkgdata_DATA = logo.png \
 gtkfilesdir = $(pkgdatadir)/files
 
 dist_gtkfiles_DATA = files/main.c
+
+gtk3filesdir = $(pkgdatadir)/v3files
+
+dist_gtk3files_DATA = v3files/main.c
diff --git a/src/plugins/scriptedwizard/resources/gtk/v3files/main.c b/src/plugins/scriptedwizard/resources/gtk/v3files/main.c
new file mode 100644
index 0000000..7e83614
--- /dev/null
+++ b/src/plugins/scriptedwizard/resources/gtk/v3files/main.c
@@ -0,0 +1,49 @@
+#include <stdlib.h>
+#include <gtk/gtk.h>
+
+static void helloWorld (GtkWidget *wid, GtkWidget *win)
+{
+  GtkWidget *dialog = NULL;
+
+  dialog = gtk_message_dialog_new (GTK_WINDOW (win), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "Hello World!");
+  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
+  gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_destroy (dialog);
+}
+
+int main (int argc, char *argv[])
+{
+  GtkWidget *button = NULL;
+  GtkWidget *win = NULL;
+  GtkWidget *vbox = NULL;
+
+  /* Initialize GTK+ */
+  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
+  gtk_init (&argc, &argv);
+  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);
+
+  /* Create the main window */
+  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_container_set_border_width (GTK_CONTAINER (win), 8);
+  gtk_window_set_title (GTK_WINDOW (win), "Hello World");
+  gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
+  gtk_widget_realize (win);
+  g_signal_connect (win, "destroy", gtk_main_quit, NULL);
+
+  /* Create a vertical box with buttons */
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  gtk_container_add (GTK_CONTAINER (win), vbox);
+
+  button = gtk_button_new_with_label ("Information");
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (helloWorld), (gpointer) win);
+  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
+
+  button = gtk_button_new_with_label ("Close");
+  g_signal_connect (button, "clicked", gtk_main_quit, NULL);
+  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
+
+  /* Enter the main loop */
+  gtk_widget_show_all (win);
+  gtk_main ();
+  return 0;
+}
diff --git a/src/plugins/scriptedwizard/resources/gtk/wizard.script b/src/plugins/scriptedwizard/resources/gtk/wizard.script
index 2843dfd..b275f92 100644
--- a/src/plugins/scriptedwizard/resources/gtk/wizard.script
+++ b/src/plugins/scriptedwizard/resources/gtk/wizard.script
@@ -9,7 +9,9 @@ GtkPathDefault    <- _T("$(#gtk)");
 GtkPathDefaultInc <- _T("$(#gtk.include)");
 GtkPathDefaultLib <- _T("$(#gtk.lib)");
 GtkPath <- _T("");
-// GtkVersion <- 1; // 0 - GTK+, 1 - GTK+-2.0
+GtkVersion <- 0; // 0 - GTK+-2.0, 1 - GTK+-3.0
+GtkHeaderFolder <- _T("gtk-2.0");
+GtkLibName <- _T("gtk-win32-2.0")
 
 function BeginWizard()
 {
@@ -24,15 +26,12 @@ function BeginWizard()
                            "\"include\" and \"lib\".");
 
     Wizard.AddInfoPage(_T("GtkIntro"), intro_msg);
+    Wizard.AddGenericSingleChoiceListPage(_T("GtkVersionPage"), _T("Please select the GTK+ version you want to use."), _T("GTK+ 2.x;GTK+ 3.x"), GtkVersion); // select GTK+ version
     Wizard.AddProjectPathPage();
     if (PLATFORM == PLATFORM_MSW)
     {
         Wizard.AddGenericSelectPathPage(_T("GtkPath"), gtkpath_msg, _T("GTK's location:"), GtkPathDefault);
     }
-    /*else
-    {
-        Wizard.AddGenericSingleChoiceListPage(_T("GtkVersionPage"), _T("Please select the GTK+ version you want to use."), _T("GTK+ 1.x;GTK+ 2.x"), GtkVersion); // select GTK+ version
-    }*/
     Wizard.AddCompilerPage(_T(""), _T("gcc*"), true, true);
 }
 
@@ -54,14 +53,14 @@ function OnLeave_GtkPath(fwd)
         local dir_nomacro_inc = GetCompilerIncludeDir(dir, GtkPathDefault, GtkPathDefaultInc);
         if (dir_nomacro_inc.IsEmpty())
             return false;
-        if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("gtk-2.0") + wxFILE_SEP_PATH +_T("gtk"), _T("gtk.h"), _T("GTK's include")))
+        if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + GtkHeaderFolder + wxFILE_SEP_PATH +_T("gtk"), _T("gtk.h"), _T("GTK's include")))
             return false;
 
         // verify library dependencies
         local dir_nomacro_lib = GetCompilerLibDir(dir, GtkPathDefault, GtkPathDefaultLib);
         if (dir_nomacro_lib.IsEmpty())
             return false;
-        if (!VerifyLibFile(dir_nomacro_lib, _T("gtk-win32-2.0"), _T("GTK's")))
+        if (!VerifyLibFile(dir_nomacro_lib, GtkLibName, _T("GTK's")))
             return false;
 
 
@@ -97,6 +96,11 @@ function OnLeave_GtkVersionPage(fwd)
     if (fwd)
     {
         GtkVersion = Wizard.GetListboxSelection(_T("GenericChoiceList"));
+        if (GtkVersion == 1)
+        {
+            GtkHeaderFolder <- _T("gtk-3.0");
+            GtkLibName <- _T("gtk-3")
+        }
     }
     return true;
 }
@@ -104,6 +108,8 @@ function OnLeave_GtkVersionPage(fwd)
 // return the files this project contains
 function GetFilesDir()
 {
+    if (GtkVersion == 1)
+        return _T("gtk/v3files");
     return _T("gtk/files");
 }
 
@@ -113,14 +119,14 @@ function SetupProject(project)
     if (PLATFORM == PLATFORM_MSW)
     {
         project.AddIncludeDir(GtkPathDefaultInc);
-        project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gtk-2.0"));
+        project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + GtkHeaderFolder);
         project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("cairo"));
         project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gdk"));
         project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("glib-2.0"));
         // Notice GtkPathDefault*Lib* at some positions. This is correct as of 2.8.20
         project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("glib-2.0") + wxFILE_SEP_PATH + _T("include"));
         project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("pango-1.0"));
-        project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("gtk-2.0")  + wxFILE_SEP_PATH + _T("include"));
+        project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + GtkHeaderFolder  + wxFILE_SEP_PATH + _T("include"));
         project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("atk-1.0"));
         if ( IO.DirectoryExists(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gdk-pixbuf-2.0")) )
             project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gdk-pixbuf-2.0"));
@@ -128,7 +134,7 @@ function SetupProject(project)
         project.AddLibDir(GtkPathDefaultLib);
 
         // add link libraries
-        project.AddLinkLib(_T("gtk-win32-2.0"));
+        project.AddLinkLib(GtkLibName);
         project.AddLinkLib(_T("gobject-2.0"));
         project.AddLinkLib(_T("glib-2.0"));
 
@@ -142,16 +148,16 @@ function SetupProject(project)
     }
     else
     {
-        /*if (GtkVersion == 1)
-        {*/
-        project.AddCompilerOption(_T("`pkg-config gtk+-2.0 --cflags`"));
-        project.AddLinkerOption(_T("`pkg-config gtk+-2.0 --libs`"));
-        /*}
+        if (GtkVersion == 1)
+        {
+            project.AddCompilerOption(_T("`pkg-config gtk+-3.0 --cflags`"));
+            project.AddLinkerOption(_T("`pkg-config gtk+-3.0 --libs`"));
+        }
         else
         {
-            project.AddCompilerOption(_T("`pkg-config gtk+ --cflags`"));
-            project.AddLinkerOption(_T("`pkg-config gtk+ --libs`"));
-        }*/
+            project.AddCompilerOption(_T("`pkg-config gtk+-2.0 --cflags`"));
+            project.AddLinkerOption(_T("`pkg-config gtk+-2.0 --libs`"));
+        }
     }
 
     // enable compiler warnings (project-wide)
--
2.7.0.windows.1

Code
From 13a7295b6f25bb88760325ae0c446df3390f8af3 Mon Sep 17 00:00:00 2001
From: Tim S <stahta01@gmail.com>
Date: Sun, 10 Jan 2016 00:38:53 -0500
Subject: [PATCH 2/5] * scriptedwizard: Added support for GLFW v3. (Thanks
 stahta01)

Added GLFW3 version of main.cpp and GlfwVersionPage.
---
 .../scriptedwizard/resources/glfw/Makefile.am      |  4 ++
 .../scriptedwizard/resources/glfw/v3files/main.cpp | 79 ++++++++++++++++++++++
 .../scriptedwizard/resources/glfw/wizard.script    | 40 ++++++++++-
 3 files changed, 120 insertions(+), 3 deletions(-)
 create mode 100644 src/plugins/scriptedwizard/resources/glfw/v3files/main.cpp

diff --git a/src/plugins/scriptedwizard/resources/glfw/Makefile.am b/src/plugins/scriptedwizard/resources/glfw/Makefile.am
index 863efcf..25998b2 100644
--- a/src/plugins/scriptedwizard/resources/glfw/Makefile.am
+++ b/src/plugins/scriptedwizard/resources/glfw/Makefile.am
@@ -7,3 +7,7 @@ dist_pkgdata_DATA = logo.png \
 glfwfilesdir = $(pkgdatadir)/files
 
 dist_glfwfiles_DATA = files/main.cpp
+
+glfw3filesdir =  $(pkgdatadir)/v3files
+
+dist_glfw3files_DATA = v3files/main.cpp
diff --git a/src/plugins/scriptedwizard/resources/glfw/v3files/main.cpp b/src/plugins/scriptedwizard/resources/glfw/v3files/main.cpp
new file mode 100644
index 0000000..2e88cd7
--- /dev/null
+++ b/src/plugins/scriptedwizard/resources/glfw/v3files/main.cpp
@@ -0,0 +1,79 @@
+#define GLFW_INCLUDE_GLU
+#include <GLFW/glfw3.h>
+
+static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
+{
+    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
+        glfwSetWindowShouldClose(window, GL_TRUE);
+}
+
+int main()
+{
+    int     width, height;
+    int     frame = 0;
+
+    if ( GL_FALSE == glfwInit())
+    {
+        return 1;
+    }
+
+    GLFWwindow* window = glfwCreateWindow(640, 480, "GLFW Application", NULL, NULL);
+    if(!window)
+    {
+        glfwTerminate();
+        return 2;
+    }
+
+    glfwMakeContextCurrent(window);
+    glfwSetKeyCallback(window, key_callback);
+
+    while(!glfwWindowShouldClose(window))
+    {
+        frame++;
+
+        glfwGetWindowSize(window, &width, &height );
+        height = height > 0 ? height : 1;
+
+        glViewport( 0, 0, width, height );
+
+        glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
+        glClear( GL_COLOR_BUFFER_BIT );
+
+        glMatrixMode( GL_PROJECTION );
+        glLoadIdentity();
+        gluPerspective( 65.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f );
+
+        // Draw some rotating garbage
+        glMatrixMode( GL_MODELVIEW );
+        glLoadIdentity();
+        gluLookAt(0.0f, -10.0f, 0.0f,
+                0.0f, 0.0f, 0.0f,
+                0.0f, 0.0f, 1.0f );
+
+        //glTranslatef( 1.0f, 1.0f, 0.0f );
+        glRotatef(frame, 0.25f, 1.0f, 0.75f);
+        glBegin( GL_TRIANGLES );
+          glColor3f(0.1f, 0.0f, 0.0f );
+          glVertex3f(0.0f, 3.0f, -4.0f);
+          glColor3f(0.0f, 1.0f, 0.0f );
+          glVertex3f(3.0f, -2.0f, -4.0f);
+          glColor3f(0.0f, 0.0f, 1.0f );
+          glVertex3f(-3.0f, -2.0f, -4.0f);
+        glEnd();
+        glBegin( GL_TRIANGLES );
+          glColor3f(0.0f, 0.1f, 0.0f );
+          glVertex3f(0.0f, 3.0f, -3.0f);
+          glColor3f(0.0f, 0.0f, 1.0f );
+          glVertex3f(3.0f, -2.0f, -2.0f);
+          glColor3f(1.0f, 0.0f, 0.0f );
+          glVertex3f(-3.0f, -2.0f, 2.0f);
+        glEnd();
+        glfwSwapBuffers(window);
+        glfwPollEvents(); // Check for ESC key pressed.
+    }
+
+    glfwDestroyWindow(window);
+    glfwTerminate();
+
+    return 0;
+}
diff --git a/src/plugins/scriptedwizard/resources/glfw/wizard.script b/src/plugins/scriptedwizard/resources/glfw/wizard.script
index 9701e13..d12cfa2 100644
--- a/src/plugins/scriptedwizard/resources/glfw/wizard.script
+++ b/src/plugins/scriptedwizard/resources/glfw/wizard.script
@@ -9,6 +9,10 @@ GlfwPathDefault    <- _T("$(#glfw)");
 GlfwPathDefaultInc <- _T("$(#glfw.include)");
 GlfwPathDefaultLib <- _T("$(#glfw.lib)");
 GlfwPath <- _T("");
+GlfwVersion <- 0; // 0 - GLFW-2.0, 1 - GlFW-3.0
+GlfwHeaderFolder <- _T("GL");
+GlfwHeaderName <- _T("glfw.h");
+GlfwLibName <- _T("glfw");
 
 function BeginWizard()
 {
@@ -23,12 +27,40 @@ function BeginWizard()
                               "\"include\" and \"lib\".");
 
     Wizard.AddInfoPage(_T("GlfwIntro"), intro_msg);
+    Wizard.AddGenericSingleChoiceListPage(_T("GlfwVersionPage"), _T("Please select the GLFW version you want to use."), _T("GLFW 2.x;GLFW 3.x"), GlfwVersion);
     Wizard.AddProjectPathPage();
     Wizard.AddGenericSelectPathPage(_T("GlfwPath"), glfwpath_descr, _T("Please select GLFW's location:"), GlfwPathDefault);
     Wizard.AddCompilerPage(_T(""), _T("*"), true, true);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+// GLFW's version page
+////////////////////////////////////////////////////////////////////////////////
+
+function OnLeave_GlfwVersionPage(fwd)
+{
+    if (fwd)
+    {
+        GlfwVersion = Wizard.GetListboxSelection(_T("GenericChoiceList"));
+        if (GlfwVersion == 1)
+        {
+            GlfwHeaderFolder <- _T("GLFW");
+            GlfwHeaderName <- _T("glfw3.h");
+            if (PLATFORM == PLATFORM_MSW)
+            {
+                GlfwLibName <- _T("glfw3");
+            }
+            else
+            {
+                GlfwLibName <- _T("glfw"); // Debian Linux uses same libname for version 2 and 3.
+            }
+        }
+    }
+    return true;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
 // GLFW's path page
 ////////////////////////////////////////////////////////////////////////////////
 
@@ -46,13 +78,13 @@ function OnLeave_GlfwPath(fwd)
         local dir_nomacro_inc = GetCompilerIncludeDir(dir, GlfwPathDefault, GlfwPathDefaultInc);
         if (dir_nomacro_inc.IsEmpty())
             return false;
-        if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("GL"), _T("glfw.h"), _T("GLFW's include"))) return false;
+        if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + GlfwHeaderFolder, GlfwHeaderName, _T("GLFW's include"))) return false;
 
         // verify library dependencies
         local dir_nomacro_lib = GetCompilerLibDir(dir, GlfwPathDefault, GlfwPathDefaultLib);
         if (dir_nomacro_lib.IsEmpty())
             return false;
-        if (!VerifyLibFile(dir_nomacro_lib, _T("glfw"), _T("GLFW's"))) return false;
+        if (!VerifyLibFile(dir_nomacro_lib, GlfwLibName, _T("GLFW's"))) return false;
 
 
         GlfwPath = dir; // Remember the original selection.
@@ -81,6 +113,8 @@ function OnLeave_GlfwPath(fwd)
 // return the files this project contains
 function GetFilesDir()
 {
+    if (GlfwVersion == 1)
+        return _T("glfw/v3files");
     return _T("glfw/files");
 }
 
@@ -92,7 +126,7 @@ function SetupProject(project)
     project.AddLibDir(GlfwPathDefaultLib);
 
     // add link libraries
-    project.AddLinkLib(_T("glfw"));
+    project.AddLinkLib(GlfwLibName);
     if (PLATFORM == PLATFORM_MSW)
     {
         project.AddLinkLib(_T("opengl32"));
--
2.7.0.windows.1

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org