116 {
117
119
120 const Array *options = (Array *) this->options;
121
122 if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
125 return true;
126 }
127 }
128
129 if (event->type == SDL_EVENT_MOUSE_BUTTON_UP) {
131 self->
state &= ~ControlStateHighlighted;
132
133 for (size_t i = 0; i < options->count; i++) {
134
135 Option *option = $(options, objectAtIndex, i);
138 if (this->delegate.didSelectOption) {
139 this->delegate.didSelectOption(this, option);
140 }
141 return true;
142 }
143 }
144 } else {
146 return true;
147 }
148 }
149
150 if (event->type == SDL_EVENT_KEY_DOWN) {
151
152 switch (event->key.key) {
153
154 case SDLK_ESCAPE:
155 self->
state &= ~ControlStateHighlighted;
156 return true;
157
158 case SDLK_RETURN:
159 case SDLK_KP_ENTER:
161 return true;
162
163 case SDLK_UP:
164 case SDLK_DOWN: {
166 if (option) {
167
168 ssize_t index = $(options, indexOfObject, option);
169 if (event->key.key == SDLK_UP) {
170 index = (index - 1 + options->count) % options->count;
171 } else {
172 index = (index + 1) % options->count;
173 }
174
175 option = $(options, objectAtIndex, index);
176
178 if (this->delegate.didSelectOption) {
179 this->delegate.didSelectOption(this, option);
180 }
181 }
182 return true;
183 }
184 }
185 }
186
188}
@ 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.