src/context.c

changeset 63
e3cacdd636e4
parent 58
26ebb2f1e6e6
child 65
9c44c55d327a
equal deleted inserted replaced
62:5a592625e2f9 63:e3cacdd636e4
85 cxBufferDestroy(&asc_context.error_buffer); 85 cxBufferDestroy(&asc_context.error_buffer);
86 asc_context.flags = 0; 86 asc_context.flags = 0;
87 asc_dprintf("Ascension context destroyed."); 87 asc_dprintf("Ascension context destroyed.");
88 } 88 }
89 89
90 void asc_context_quit(void) {
91 asc_set_flag(asc_context.flags, ASC_FLAG_QUIT);
92 }
93
90 static void asc_event_window_resized(Uint32 id, Sint32 width, Sint32 height) { 94 static void asc_event_window_resized(Uint32 id, Sint32 width, Sint32 height) {
91 for (unsigned int i = 0 ; i < ASC_MAX_WINDOWS ; i++) { 95 for (unsigned int i = 0 ; i < ASC_MAX_WINDOWS ; i++) {
92 if (asc_context.windows[i].id == id) { 96 if (asc_context.windows[i].id == id) {
93 asc_vec2i dimensions = (asc_vec2i) {width, height}; 97 asc_vec2i dimensions = (asc_vec2i) {width, height};
94 asc_context.windows[i].resized = true; 98 asc_context.windows[i].resized = true;
97 } 101 }
98 } 102 }
99 } 103 }
100 104
101 bool asc_loop_next(void) { 105 bool asc_loop_next(void) {
106 // reset mouse motion
107 asc_context.input.mouse_xrel = 0;
108 asc_context.input.mouse_yrel = 0;
109
102 // dispatch SDL events 110 // dispatch SDL events
103 SDL_Event event; 111 SDL_Event event;
104 while (SDL_PollEvent(&event)) { 112 while (SDL_PollEvent(&event)) {
105 switch (event.type) { 113 switch (event.type) {
106 case SDL_QUIT: 114 case SDL_QUIT:
113 event.window.data1, 121 event.window.data1,
114 event.window.data2 122 event.window.data2
115 ); 123 );
116 break; 124 break;
117 } 125 }
126 case SDL_MOUSEMOTION: {
127 // accumulate relative motion
128 asc_context.input.mouse_xrel += event.motion.xrel;
129 asc_context.input.mouse_yrel += event.motion.yrel;
130 // update absolute position
131 asc_context.input.mouse_x = event.motion.x;
132 asc_context.input.mouse_y = event.motion.y;
133 break;
134 }
118 case SDL_KEYDOWN: 135 case SDL_KEYDOWN:
119 // TODO: remove this code and implement key press map instead 136 asc_context.input.keys[event.key.keysym.scancode] = true;
120 if (event.key.keysym.sym == SDLK_ESCAPE)
121 return false;
122 break; 137 break;
123 case SDL_KEYUP: 138 case SDL_KEYUP:
124 // TODO: implement key press map 139 asc_context.input.keys[event.key.keysym.scancode] = false;
125 break; 140 break;
126 } 141 }
127 } 142 }
128 143
129 // sync the windows 144 // sync the windows

mercurial