Commit 159ce2ba authored by guillaume's avatar guillaume

initialization ControlPanel

parent 3aac5b13
...@@ -17,7 +17,7 @@ find_package(raylib 3.0 REQUIRED) ...@@ -17,7 +17,7 @@ find_package(raylib 3.0 REQUIRED)
add_executable(nw-hello src/main-hello.c) add_executable(nw-hello src/main-hello.c)
target_link_libraries(nw-hello raylib) target_link_libraries(nw-hello raylib)
add_executable(nw-viewer src/main-viewer.c src/networld.c) add_executable(nw-viewer src/main-viewer.c src/networld.c src/controlpanel.c)
target_link_libraries(nw-viewer raylib) target_link_libraries(nw-viewer raylib)
#without cmake package... #without cmake package...
......
#include "controlpanel.h"
#include <stdio.h>
#include <stdlib.h>
// Constructor / Destructor
Panel * Panel_new()
{
Panel * p = malloc( sizeof(Panel) );
return p;
}
void Panel_delete(Panel * self)
{
free(self);
}
// Initialization
void Panel_initialize(Panel * self, NetWorld * world)
{
self->world= world;
self->camerax= 0;
self->cameray= 0;
self->scale= 1;
}
// To String
void Panel_print(Panel * self)
{
printf("Panel camera(x-%f, y-%f, scale-%f)\n", self->camerax, self->cameray, self->scale);
}
#ifndef CONTROLPANEL_H
#define CONTROLPANEL_H
#include "networld.h"
struct Str_Panel {
double camerax, cameray;
double scale;
NetWorld * world;
};
typedef struct Str_Panel Panel;
// Constructor / Destructor
Panel * Panel_new();
void Panel_delete(Panel * self);
// Initialization
void Panel_initialize(Panel * self, NetWorld * world);
// To String
void Panel_print(Panel * self);
#endif //CONTROLPANEL_H
\ No newline at end of file
...@@ -5,11 +5,14 @@ ...@@ -5,11 +5,14 @@
* *
********************************************************************************************/ ********************************************************************************************/
#include "networld.h"
#include "raylib.h" #include "raylib.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "networld.h"
#include "controlpanel.h"
// Program attributes // Program attributes
//------------------- //-------------------
const int screenWidth = 800; const int screenWidth = 800;
...@@ -33,6 +36,9 @@ int main(int nbArg, char ** arg) ...@@ -33,6 +36,9 @@ int main(int nbArg, char ** arg)
NetWorld_initNodePosition( world, 1, 110.4, 52.8 ); NetWorld_initNodePosition( world, 1, 110.4, 52.8 );
NetWorld_initNodePosition( world, 2, 384.5, 422.2 ); NetWorld_initNodePosition( world, 2, 384.5, 422.2 );
Panel * panel= Panel_new();
Panel_initialize(panel, world);
// Raylib Initialization // Raylib Initialization
//---------------------- //----------------------
InitWindow(screenWidth, screenHeight, "NetWorld basic viewer"); InitWindow(screenWidth, screenHeight, "NetWorld basic viewer");
...@@ -43,7 +49,8 @@ int main(int nbArg, char ** arg) ...@@ -43,7 +49,8 @@ int main(int nbArg, char ** arg)
puts("world variable:"); puts("world variable:");
NetWorld_print(world); NetWorld_print(world);
puts("world expected:\n[10.4, 12.8]\n[110.4, 52.8]\n[384.5, 422.2]"); puts("world expected:\n[10.4, 12.8]\n[110.4, 52.8]\n[384.5, 422.2]");
Panel_print(panel);
// Main game loop // Main game loop
while (!game_end && !WindowShouldClose()) // Detect window close button or ESC key while (!game_end && !WindowShouldClose()) // Detect window close button or ESC key
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment