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; }
int kiss_entry_new(kiss_entry *entry, kiss_window *wdw, int decorate, char *text, int x, int y, int w) { if (!entry || w < 2 * kiss_border + kiss_textfont.advance || !text) return -1; entry->bg = kiss_white; entry->normalcolor = kiss_black; entry->activecolor = kiss_blue; entry->textwidth = w - 2 * kiss_border; kiss_string_copy(entry->text, kiss_maxlength(kiss_textfont, entry->textwidth, text, NULL), text, NULL); kiss_makerect(&entry->rect, x, y, w, kiss_textfont.fontheight + 2 * kiss_border); entry->decorate = decorate; entry->textx = x + kiss_border; entry->texty = y + kiss_border; entry->active = 0; entry->visible = 0; entry->focus = 0; entry->wdw = wdw; return 0; }
static void button_ok1_event(kiss_button *button, SDL_Event *e, kiss_window *window1, kiss_window *window2, kiss_label *label_sel, kiss_entry *entry, kiss_label *label_res, kiss_progressbar *progressbar, int *draw) { char buf[KISS_MAX_LENGTH]; if (kiss_button_event(button, e, draw)) { kiss_string_copy(buf, kiss_maxlength(kiss_textfont, window2->rect.w - 2 * kiss_vslider.w, label_sel->text, entry->text), label_sel->text, entry->text); kiss_string_copy(label_res->text, KISS_MAX_LABEL, "The following path was selected:\n", buf); window2->visible = 1; window2->focus = 1; window1->focus = 0; button->prelight = 0; progressbar->fraction = 0.; progressbar->run = 1; *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; }