137 {
138
140
141 const Array *options = (Array *) this->options;
142
143 if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
146 return true;
147 }
148 }
149
150 if (event->type == SDL_EVENT_MOUSE_BUTTON_UP) {
152 self->
state &= ~ControlStateHighlighted;
153
154 for (size_t i = 0; i < options->count; i++) {
155
156 Option *option = $(options, objectAtIndex, i);
159 if (this->delegate.didSelectOption) {
160 this->delegate.didSelectOption(this, option);
161 }
162 return true;
163 }
164 }
165 } else {
167 return true;
168 }
169 }
170
171 if (event->type == SDL_EVENT_KEY_DOWN) {
172
173 switch (event->key.key) {
174
175 case SDLK_ESCAPE:
176 self->
state &= ~ControlStateHighlighted;
177 return true;
178
179 case SDLK_RETURN:
180 case SDLK_KP_ENTER:
182 return true;
183
184 case SDLK_UP:
185 case SDLK_DOWN: {
187 if (option) {
188
189 ssize_t index = $(options, indexOfObject, option);
190 if (event->key.key == SDLK_UP) {
191 index = (index - 1 + options->count) % options->count;
192 } else {
193 index = (index + 1) % options->count;
194 }
195
196 option = $(options, objectAtIndex, index);
197
199 if (this->delegate.didSelectOption) {
200 this->delegate.didSelectOption(this, option);
201 }
202 }
203 return true;
204 }
205 }
206 }
207
209}
@ ControlStateHighlighted
static void selectOption(Select *self, Option *option)
static bool captureEvent(Control *self, const SDL_Event *event)
static void becomeTouchResponder(View *self)
static bool didReceiveEvent(const View *self, const SDL_Event *event)
Controls are Views which capture and respond to events.
unsigned int state
The bit mask of ControlState.