116 abort(); |
116 abort(); |
117 } |
117 } |
118 } |
118 } |
119 |
119 |
120 static void asc_event_window_resized(Uint32 id, Sint32 width, Sint32 height) { |
120 static void asc_event_window_resized(Uint32 id, Sint32 width, Sint32 height) { |
121 for (unsigned int i = 0 ; i < ASC_MAX_WINDOWS ; i++) { |
121 unsigned int i = asc_window_index(id); |
122 if (asc_context.windows[i].id == id) { |
122 if (i < ASC_MAX_WINDOWS) { |
123 asc_vec2i dimensions = (asc_vec2i) {width, height}; |
123 asc_vec2i dimensions = (asc_vec2i) {width, height}; |
124 asc_context.windows[i].resized = true; |
124 asc_context.windows[i].resized = true; |
125 asc_context.windows[i].dimensions = dimensions; |
125 asc_context.windows[i].dimensions = dimensions; |
126 return; |
|
127 } |
|
128 } |
126 } |
129 } |
127 } |
130 |
128 |
131 bool asc_loop_next(void) { |
129 bool asc_loop_next(void) { |
132 // reset mouse motion |
130 // reset mouse motion |
139 switch (event.type) { |
137 switch (event.type) { |
140 case SDL_QUIT: |
138 case SDL_QUIT: |
141 asc_set_flag(asc_context.flags, ASC_FLAG_QUIT); |
139 asc_set_flag(asc_context.flags, ASC_FLAG_QUIT); |
142 break; |
140 break; |
143 case SDL_WINDOWEVENT: { |
141 case SDL_WINDOWEVENT: { |
144 if (event.window.event == SDL_WINDOWEVENT_RESIZED) |
142 if (event.window.event == SDL_WINDOWEVENT_RESIZED) { |
145 asc_event_window_resized( |
143 asc_event_window_resized( |
146 event.window.windowID, |
144 event.window.windowID, |
147 event.window.data1, |
145 event.window.data1, |
148 event.window.data2 |
146 event.window.data2 |
149 ); |
147 ); |
|
148 } else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { |
|
149 unsigned int idx = asc_window_index(event.window.windowID); |
|
150 asc_context.windows[idx].focused = true; |
|
151 } else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { |
|
152 unsigned int idx = asc_window_index(event.window.windowID); |
|
153 asc_context.windows[idx].focused = false; |
|
154 } |
150 break; |
155 break; |
151 } |
156 } |
152 case SDL_MOUSEMOTION: { |
157 case SDL_MOUSEMOTION: { |
153 // accumulate relative motion |
158 // accumulate relative motion |
154 asc_context.input.mouse_xrel += event.motion.xrel; |
159 asc_context.input.mouse_xrel += event.motion.xrel; |
155 asc_context.input.mouse_yrel += event.motion.yrel; |
160 asc_context.input.mouse_yrel += event.motion.yrel; |
156 // update absolute position |
161 // update absolute position |
157 asc_context.input.mouse_x = event.motion.x; |
162 asc_context.input.mouse_x = event.motion.x; |
158 asc_context.input.mouse_y = event.motion.y; |
163 asc_context.input.mouse_y = event.motion.y; |
|
164 // update which window the mouse was seen in |
|
165 asc_context.input.mouse_window = |
|
166 asc_window_index(event.motion.windowID); |
159 break; |
167 break; |
160 } |
168 } |
161 case SDL_KEYDOWN: |
169 case SDL_KEYDOWN: |
162 asc_context.input.keys[event.key.keysym.scancode] = true; |
170 asc_context.input.keys[event.key.keysym.scancode] = true; |
163 break; |
171 break; |