Jelajahi Sumber

Almost ready for merge. Need to fix bug with mouse movement. Need to implement clipboard support. Lastly need to write ReadMe on instructions for building.

Ricardo Antonio Tejada 8 tahun lalu
induk
melakukan
63e98d90bd

+ 26 - 5
demo/sfml_opengl2/Makefile

@@ -1,8 +1,29 @@
-SFML_INC = -I C:/Users/Ricky/MinGW-Libs/SFML/include
-SFML_LIB = -L C:/Users/Ricky/MinGW-Libs/SFML/lib
+# Install
+CC = g++
+BIN = demo
 
-LIBS = -DSFML_STATIC -lmingw32 -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32
+# Flags
+CFLAGS = -s -O2
 
+SRC = main.cpp
+OBJ = $(SRC:.cpp=.o)
 
-build:
-	g++ main.cpp $(SFML_INC) $(SFML_LIB) $(LIBS) -o demo.exe
+# TODO: Mac Build
+ifeq ($(OS),Windows_NT)
+	# Edit the line below to point to your SFML folder on Windows
+	SFML_DIR = C:/Users/Ricky/MinGW-Libs/SFML
+
+	BIN := $(BIN).exe
+	LIBS = -lmingw32 -DSFML_STATIC -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32
+else
+	# Edit the line below to point to your SFML folder on Linux
+	SFML_DIR = /home/ricky/Libraries/SFML
+
+	LIBS = -DSFML_STATIC -lsfml-window-s -lsfml-system-s -pthread -ludev -lGL -lX11 -lXrandr
+endif
+
+SFML_INC = -I $(SFML_DIR)/include
+SFML_LIB = -L $(SFML_DIR)/lib
+
+$(BIN):
+	$(CC) $(SRC) $(CFLAGS) -o $(BIN) $(SFML_INC) $(SFML_LIB) $(LIBS)

+ 0 - 2
demo/sfml_opengl2/build.bat

@@ -1,2 +0,0 @@
-mingw32-make -f Makefile
-pause

+ 1 - 0
demo/sfml_opengl2/main.cpp

@@ -10,6 +10,7 @@
 #include <limits.h>
 #include <time.h>
 
+#include <SFML/OpenGL.hpp>
 #include <SFML/Window.hpp>
 
 #define NK_INCLUDE_FIXED_TYPES

+ 6 - 12
demo/sfml_opengl2/nuklear_sfml_gl2.h

@@ -195,6 +195,7 @@ nk_sfml_clipboard_paste(nk_handle usr, struct nk_text_edit* edit)
 static void
 nk_sfml_clipboard_copy(nk_handle usr, const char* text, int len)
 {
+    /*
     char* str = 0;
     (void)usr;
     if(!len)
@@ -205,12 +206,12 @@ nk_sfml_clipboard_copy(nk_handle usr, const char* text, int len)
     memcpy(str, text, (size_t)len);
     str[len] = '\0';
 
-    /* Not Implemented in SFML
+     Not Implemented in SFML
     sf::Clipboard clipboard(sfml.window);
     clipboard.setText(str);
-    */
-
+    
     free(str);
+    */
 }
 
 NK_API struct nk_context*
@@ -260,6 +261,7 @@ nk_sfml_handle_event(sf::Event* event)
     {
         int x = (int)ctx->input.mouse.prev.x;
         int y = (int)ctx->input.mouse.prev.y;
+        
         sfml.window->setMouseCursorGrabbed(false);
         sf::Mouse::setPosition(sf::Vector2i(x, y));
         ctx->input.mouse.ungrab = 0;
@@ -349,15 +351,7 @@ nk_sfml_handle_event(sf::Event* event)
     }
     else if(event->type == sf::Event::MouseMoved)
     {
-        if(ctx->input.mouse.grabbed)
-        {
-            int x = (int)ctx->input.mouse.prev.x + event->mouseMove.x;
-            int y = (int)ctx->input.mouse.prev.y + event->mouseMove.y;
-
-            nk_input_motion(ctx, x, y);
-        }
-        else
-            nk_input_motion(ctx, event->mouseMove.x, event->mouseMove.y);
+        nk_input_motion(ctx, event->mouseMove.x, event->mouseMove.y);
 
         return 1;
     }

+ 29 - 6
demo/sfml_opengl3/Makefile

@@ -1,10 +1,33 @@
-GLAD_INC = -I C:/Users/Ricky/MinGW-Libs/GLAD/include
+# Install
+CC = g++
+BIN = demo
 
-SFML_INC = -I C:/Users/Ricky/MinGW-Libs/SFML/include
-SFML_LIB = -L C:/Users/Ricky/MinGW-Libs/SFML/lib
+# Flags
+CFLAGS = -s -O2
 
-LIBS = -DGLAD_HEADER_ONLY -DSFML_STATIC -lmingw32 -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32
+SRC = main.cpp
+OBJ = $(SRC:.cpp=.o)
 
+# TODO: Mac Build
+ifeq ($(OS),Windows_NT)
+	# Edit the line below to point to your SFML/GLAD folder on Windows
+	SFML_DIR = C:/Users/Ricky/MinGW-Libs/SFML
+	GLAD_DIR = C:/Users/Ricky/MinGW-Libs/GLAD
 
-build:
-	g++ main.cpp $(GLAD_INC) $(SFML_INC) $(SFML_LIB) $(LIBS) -o demo.exe
+	BIN := $(BIN).exe
+	LIBS = -lmingw32 -DSFML_STATIC -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32
+else
+	# Edit the line below to point to your SFML/GLAD folder on Linux
+	SFML_DIR = /home/ricky/Libraries/SFML
+	GLAD_DIR = /home/ricky/Libraries/GLAD
+
+	LIBS = -DSFML_STATIC -lsfml-window-s -lsfml-system-s -pthread -ludev -lGL -lX11 -lXrandr
+endif
+
+SFML_INC = -I $(SFML_DIR)/include
+SFML_LIB = -L $(SFML_DIR)/lib
+GLAD_INC = -I $(GLAD_DIR)/include
+GLAD_SRC = $(GLAD_DIR)/src/glad.c
+
+$(BIN):
+	$(CC) $(GLAD_SRC) $(SRC) $(CFLAGS) $(GLAD_INC) $(SFML_INC) $(SFML_LIB) $(SFML_EXT) -o $(BIN) $(LIBS)

+ 0 - 2
demo/sfml_opengl3/build.bat

@@ -1,2 +0,0 @@
-mingw32-make -f Makefile
-pause

+ 6 - 13
demo/sfml_opengl3/nuklear_sfml_gl3.h

@@ -323,6 +323,7 @@ nk_sfml_clipboard_paste(nk_handle usr, struct nk_text_edit* edit)
 static void
 nk_sfml_clipboard_copy(nk_handle usr, const char* text, int len)
 {
+    /*
     char* str = 0;
     (void)usr;
     if(!len)
@@ -333,12 +334,12 @@ nk_sfml_clipboard_copy(nk_handle usr, const char* text, int len)
     memcpy(str, text, (size_t)len);
     str[len] = '\0';
 
-    /* Not Implemented in SFML
+     Not Implemented in SFML
     sf::Clipboard clipboard(sfml.window);
     clipboard.setText(str);
-    */
-
+    
     free(str);
+    */
 }
 
 NK_API struct nk_context*
@@ -349,7 +350,6 @@ nk_sfml_init(sf::Window* window)
     sfml.ctx.clip.copy = nk_sfml_clipboard_copy;
     sfml.ctx.clip.paste = nk_sfml_clipboard_paste;
     sfml.ctx.clip.userdata = nk_handle_ptr(0);
-    //nk_buffer_init_default(&sfml.ogl.cmds);
     nk_sfml_device_create();
     return &sfml.ctx;
 }
@@ -389,6 +389,7 @@ nk_sfml_handle_event(sf::Event* event)
     {
         int x = (int)ctx->input.mouse.prev.x;
         int y = (int)ctx->input.mouse.prev.y;
+        
         sfml.window->setMouseCursorGrabbed(false);
         sf::Mouse::setPosition(sf::Vector2i(x, y));
         ctx->input.mouse.ungrab = 0;
@@ -478,15 +479,7 @@ nk_sfml_handle_event(sf::Event* event)
     }
     else if(event->type == sf::Event::MouseMoved)
     {
-        if(ctx->input.mouse.grabbed)
-        {
-            int x = (int)ctx->input.mouse.prev.x + event->mouseMove.x;
-            int y = (int)ctx->input.mouse.prev.y + event->mouseMove.y;
-
-            nk_input_motion(ctx, x, y);
-        }
-        else
-            nk_input_motion(ctx, event->mouseMove.x, event->mouseMove.y);
+        nk_input_motion(ctx, event->mouseMove.x, event->mouseMove.y);
 
         return 1;
     }