summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Pinot <ngc891@gmail.com>2013-10-17 13:07:31 +0900
committerJerome Pinot <ngc891@gmail.com>2013-10-17 13:07:31 +0900
commitfbcc470bedde588dd9b3d1e823886c8b76807e0e (patch)
tree24139caf155f351704c6553fc219cb6c6a2faac4
parent56e099aa2b8c4371cc1ba551f3c18eb684c8beec (diff)
Support for quit by pressing 'q' or ESC
-rw-r--r--Makefile2
-rw-r--r--mandelbrot.c25
2 files changed, 26 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 6e7c8b2..fdbc66f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
1LIBS = `pkg-config --cflags --libs evas ecore ecore-evas` -lm 1LIBS = `pkg-config --cflags --libs eina evas ecore ecore-evas` -lm
2 2
3all: mandelbrot.c 3all: mandelbrot.c
4 gcc -O0 -g -ggdb3 -o mandelbrot $< $(LIBS) 4 gcc -O0 -g -ggdb3 -o mandelbrot $< $(LIBS)
diff --git a/mandelbrot.c b/mandelbrot.c
index c3df85e..9c5c4cc 100644
--- a/mandelbrot.c
+++ b/mandelbrot.c
@@ -1,8 +1,10 @@
1#include <Eina.h>
1#include <Ecore.h> 2#include <Ecore.h>
2#include <Ecore_Evas.h> 3#include <Ecore_Evas.h>
3 4
4#include <stdlib.h> 5#include <stdlib.h>
5#include <stdint.h> 6#include <stdint.h>
7#include <string.h>
6#include <unistd.h> 8#include <unistd.h>
7#include <math.h> 9#include <math.h>
8 10
@@ -62,6 +64,26 @@ Ecore_Evas *ee;
62Evas *canvas; 64Evas *canvas;
63Evas_Object *img; 65Evas_Object *img;
64 66
67static void
68_quit(void)
69{
70 ecore_main_loop_quit();
71}
72
73static void
74_key_down(void *data, Evas *e, Evas_Object *o, void *event_info)
75{
76 Evas_Event_Key_Down *ev;
77 char *key;
78
79 ev = (Evas_Event_Key_Down *)event_info;
80 key = ev->keyname;
81
82 if (!strcmp(key, "Escape") || !strcmp(key, "q"))
83 _quit();
84
85}
86
65/* check for divergence */ 87/* check for divergence */
66int 88int
67distance(float x0, float y0) 89distance(float x0, float y0)
@@ -158,6 +180,9 @@ main(void)
158 memset(ptr, WHITE, WIDTH*HEIGHT*4); 180 memset(ptr, WHITE, WIDTH*HEIGHT*4);
159 181
160 draw(ptr,xmin,ymin,xmax,ymax); 182 draw(ptr,xmin,ymin,xmax,ymax);
183 evas_object_focus_set(img, EINA_TRUE);
184
185 evas_object_event_callback_add(img, EVAS_CALLBACK_KEY_DOWN, _key_down, ee);
161 186
162 ecore_main_loop_begin(); 187 ecore_main_loop_begin();
163 188