int kiss_combobox_event(kiss_combobox *combobox, SDL_Event *event, int *draw) { int firstline, index; if (!combobox || !combobox->visible) return 0; if (kiss_vscrollbar_event(&combobox->vscrollbar, event, draw) && combobox->textbox.array->length - combobox->textbox.maxlines >= 0) { combobox->vscrollbar.step = 0.; if (combobox->textbox.array->length - combobox->textbox.maxlines > 0) combobox->vscrollbar.step = 1. / (combobox->textbox.array->length - combobox->textbox.maxlines); firstline = (int) ((combobox->textbox.array->length - combobox->textbox.maxlines) * combobox->vscrollbar.fraction + 0.5); if (firstline >= 0) combobox->textbox.firstline = firstline; *draw = 1; } if (!event) return 0; if (event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_EXPOSED) *draw = 1; if (event->type == SDL_MOUSEBUTTONDOWN && kiss_pointinrect(event->button.x, event->button.y, &combobox->entry.rect)) { combobox->window.visible = 1; *draw = 1; } if (kiss_entry_event(&combobox->entry, event, draw)) { combobox->window.visible = 0; strcpy(combobox->text, combobox->entry.text); *draw = 1; return 1; } else if (kiss_textbox_event(&combobox->textbox, event, draw)) { combobox->window.visible = 0; combobox->entry.active = 0; if (combobox->entry.wdw) combobox->entry.wdw->focus = 1; combobox->entry.focus = 0; index = combobox->textbox.firstline + combobox->textbox.selectedline; kiss_string_copy(combobox->entry.text, kiss_maxlength(kiss_textfont, combobox->entry.textwidth, (char *) kiss_array_data(combobox->textbox.array, index), NULL), (char *) kiss_array_data(combobox->textbox.array, index), NULL); *draw = 1; return 1; } return 0; }
static void vscrollbar2_event(kiss_vscrollbar *vscrollbar, SDL_Event *e, kiss_textbox *textbox2, int *draw) { int firstline; if (kiss_vscrollbar_event(vscrollbar, e, draw) && textbox2->array->length) { firstline = (int) ((textbox2->array->length - textbox2->maxlines) * vscrollbar->fraction + 0.5); if (firstline >= 0) textbox2->firstline = firstline; *draw = 1; } }