From 68a5c1a85106bc1cd9123d58f06bd1ec77c7a782 Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Tue, 27 Dec 2011 18:48:15 +0100 Subject: [PATCH] Refactor the datatypes to the GTK ones (for compability) --- editor/src/config.h | 22 ++++++++++------------ editor/src/display.c | 8 ++++---- editor/src/display.h | 2 +- editor/src/event_callbacks.c | 2 +- editor/src/input.c | 14 +++++++------- editor/src/input.h | 6 +++--- editor/src/main.c | 24 +++++++++++------------- 7 files changed, 37 insertions(+), 41 deletions(-) diff --git a/editor/src/config.h b/editor/src/config.h index 54a79f0..44f40b3 100644 --- a/editor/src/config.h +++ b/editor/src/config.h @@ -8,8 +8,6 @@ #define MOVE_SPEED 7 #define ZOOM_LEVEL 25 -#define PI 3.1415926535897932 - // Poor Man's enums #define TOP_ORIENTATION 0x01 #define SIDE_ORIENTATION 0x02 @@ -18,16 +16,16 @@ #define PICKING_MODE 0x02 // Materials -extern float ledOnMaterial[]; -extern float ledOffMaterial[]; -extern float wireMaterial[]; -extern float innerWireMaterial[]; -extern float backgroundColor[]; +extern gfloat ledOnMaterial[]; +extern gfloat ledOffMaterial[]; +extern gfloat wireMaterial[]; +extern gfloat innerWireMaterial[]; +extern gfloat backgroundColor[]; // Movement -extern float lookX, lookZ; -extern float eyePos, eyeAngle; -extern int ledOrientation; +extern gfloat lookX, lookZ; +extern gfloat eyePos, eyeAngle; +extern gint ledOrientation; // Objects extern GLUquadricObj *quadric; @@ -36,10 +34,10 @@ extern GdkGLWindow *glWindow; extern GdkGLContext *glContext; // Dimensions, positions -extern float light0Pos[]; +extern gfloat light0Pos[]; // LED data -extern int currentFrame[27]; +extern gint currentFrame[27]; #endif diff --git a/editor/src/display.c b/editor/src/display.c index a086ac4..3e6b56b 100644 --- a/editor/src/display.c +++ b/editor/src/display.c @@ -8,9 +8,9 @@ #include "display.h" -void drawLEDs(int mode) { - int x, y, z; - int ledIndex = 0; +void drawLEDs(gint mode) { + gint x, y, z; + gint ledIndex = 0; if (ledOrientation == TOP_ORIENTATION) { glRotatef(90, 2, 0, 0); @@ -44,7 +44,7 @@ void drawLEDs(int mode) { } void drawWires() { - int x, y; + gint x, y; for (y=-10; y<=10; y+=10) for (x=-10; x<=10; x+=10) { glMaterialfv(GL_FRONT, GL_AMBIENT, ((x == 0 || y == 0) ? innerWireMaterial : wireMaterial)); diff --git a/editor/src/display.h b/editor/src/display.h index d6236fb..4af3c5d 100644 --- a/editor/src/display.h +++ b/editor/src/display.h @@ -1,7 +1,7 @@ #ifndef _DISPLAY_H #define _DISPLAY_H -void drawLEDs(int mode); +void drawLEDs(gint mode); void drawWires(); void display(gboolean onlyForPicking); diff --git a/editor/src/event_callbacks.c b/editor/src/event_callbacks.c index 2f389a7..cfe49cc 100644 --- a/editor/src/event_callbacks.c +++ b/editor/src/event_callbacks.c @@ -59,7 +59,7 @@ void on_drawing_area_button_press_event(GtkWidget *widget, gpointer data) { if (!gdk_gl_drawable_gl_begin(glDrawable, glContext)) return; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - + display(TRUE); mouse(x, y); diff --git a/editor/src/input.c b/editor/src/input.c index 7a0286c..2b58f91 100644 --- a/editor/src/input.c +++ b/editor/src/input.c @@ -9,27 +9,27 @@ #include "display.h" -void moveCameraPosition(float direction) { +void moveCameraPosition(gfloat direction) { eyePos += direction; if (eyePos > 360.0) eyePos = 0.0; - lookX = sin(eyePos * PI/180.0)*70.0; - lookZ = cos(eyePos * PI/180.0)*70.0; + lookX = sin(eyePos * M_PI/180.0)*70.0; + lookZ = cos(eyePos * M_PI/180.0)*70.0; } -void moveCameraAngle(float angle) { +void moveCameraAngle(gfloat angle) { eyeAngle += angle; if (eyeAngle > 120) eyeAngle = 120; if (eyeAngle < 0) eyeAngle = 0; } -void mouse(int x, int y) { - int position, viewport[4]; +void mouse(gint x, gint y) { + gint position, viewport[4]; GLubyte pixel[3]; glGetIntegerv(GL_VIEWPORT, viewport); glReadPixels(x, viewport[3]-y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, (void*)pixel); - position = ((int)pixel[2]/8)-1; // Selected LED + position = ((gint)pixel[2]/8)-1; // Selected LED printf("%d\n", position); currentFrame[position] = currentFrame[position] == 0 ? 1 : 0; diff --git a/editor/src/input.h b/editor/src/input.h index d010515..b1af947 100644 --- a/editor/src/input.h +++ b/editor/src/input.h @@ -1,10 +1,10 @@ #ifndef _INPUT_H #define _INPUT_H -void moveCameraPosition(float direction); -void moveCameraAngle(float angle); +void moveCameraPosition(gfloat direction); +void moveCameraAngle(gfloat angle); -void mouse(int x, int y); +void mouse(gint x, gint y); #endif diff --git a/editor/src/main.c b/editor/src/main.c index dd9ab68..c610d5f 100644 --- a/editor/src/main.c +++ b/editor/src/main.c @@ -12,22 +12,20 @@ #include "input.h" #include "event_callbacks.c" -// TODO: Refactor to GLib-Datatypes (page 747) - // Materials -float ledOnMaterial[] = {0.0, 0.0, 1.0, 0.4}; -float ledOffMaterial[] = {0.1, 0.1, 0.1, 0.0}; -float wireMaterial[] = {0.7, 0.7, 0.7, 1.0}; -float innerWireMaterial[] = {0.3, 0.3, 0.3, 0.3}; +gfloat ledOnMaterial[] = {0.0, 0.0, 1.0, 0.4}; +gfloat ledOffMaterial[] = {0.1, 0.1, 0.1, 0.0}; +gfloat wireMaterial[] = {0.7, 0.7, 0.7, 1.0}; +gfloat innerWireMaterial[] = {0.3, 0.3, 0.3, 0.3}; // Colors -float backgroundColor[] = {0.3, 0.3, 0.3, 0.4}; +gfloat backgroundColor[] = {0.3, 0.3, 0.3, 0.4}; // Positions -float light0Pos[] = {70, 70, 70, 0.0}; -float lookX = 0.0, lookZ = 0.0; -float eyePos = 0.0, eyeAngle = 45.0; -int ledOrientation = TOP_ORIENTATION; +gfloat light0Pos[] = {70, 70, 70, 0.0}; +gfloat lookX = 0.0, lookZ = 0.0; +gfloat eyePos = 0.0, eyeAngle = 45.0; +gint ledOrientation = TOP_ORIENTATION; // Objects GLUquadricObj *quadric; @@ -36,10 +34,10 @@ GdkGLContext *glContext; GtkWidget *window, *drawingArea; // LED data -int currentFrame[27] = {0}; +gint currentFrame[27] = {0}; -int main(int argc, char *argv[]) { +gint main(gint argc, gchar *argv[]) { GladeXML *xml; gtk_init(&argc, &argv);