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 textbox2_event(kiss_textbox *textbox, SDL_Event *e, kiss_vscrollbar *vscrollbar2, kiss_entry *entry, int *draw) { int index; if (kiss_textbox_event(textbox, e, draw)) { index = textbox->firstline + textbox->selectedline; if (strcmp((char *) kiss_array_data(textbox->array, index), "")) { kiss_string_copy(entry->text, entry->textwidth / kiss_textfont.advance, (char *) kiss_array_data(textbox->array, index), NULL); *draw = 1; } } }
/* The widget arguments are widgets that this widget talks with */ static void textbox1_event(kiss_textbox *textbox, SDL_Event *e, kiss_vscrollbar *vscrollbar1, kiss_textbox *textbox2, kiss_vscrollbar *vscrollbar2, kiss_label *label_sel, int *draw) { int index; if (kiss_textbox_event(textbox, e, draw)) { index = textbox->firstline + textbox->selectedline; if (strcmp((char *) kiss_array_data(textbox->array, index), "")) { textbox->selectedline = -1; kiss_chdir((char *) kiss_array_data(textbox->array, index)); dirent_read(textbox, vscrollbar1, textbox2, vscrollbar2, label_sel); *draw = 1; } } }
int kiss_textbox_draw(kiss_textbox *textbox, SDL_Renderer *renderer) { SDL_Rect highlightrect; char buf[KISS_MAX_LENGTH]; int numoflines, i; if (textbox && textbox->wdw) textbox->visible = textbox->wdw->visible; if (!textbox || !textbox->visible || !renderer) return 0; kiss_fillrect(renderer, &textbox->rect, textbox->bg); if (textbox->decorate) kiss_decorate(renderer, &textbox->rect, kiss_blue, kiss_edge); if (textbox->highlightline >= 0) { kiss_makerect(&highlightrect, textbox->textrect.x, textbox->textrect.y + textbox->highlightline * kiss_textfont.lineheight, textbox->textrect.w, kiss_textfont.lineheight); kiss_fillrect(renderer, &highlightrect, textbox->hlcolor); } if (!textbox->array || !textbox->array->length) return 0; numoflines = textbox_numoflines(textbox); for (i = 0; i < numoflines; i++) { kiss_string_copy(buf, kiss_maxlength(kiss_textfont, textbox->textwidth, (char *) kiss_array_data(textbox->array, textbox->firstline + i), NULL), (char *) kiss_array_data(textbox->array, textbox->firstline + i), NULL); kiss_rendertext(renderer, buf, textbox->textrect.x, textbox->textrect.y + i * kiss_textfont.lineheight + kiss_textfont.spacing / 2, kiss_textfont, textbox->textcolor); } return 1; }