int kiss_combobox_new(kiss_combobox *combobox, kiss_window *wdw, char *text, kiss_array *a, int x, int y, int w, int h) { if (!combobox || !a || !text) return -1; kiss_entry_new(&combobox->entry, wdw, 1, text, x, y, w); strcpy(combobox->text, combobox->entry.text); kiss_window_new(&combobox->window, NULL, 0, x, y + combobox->entry.rect.h, w + kiss_up.w, h); if (kiss_textbox_new(&combobox->textbox, &combobox->window, 1, a, x, y + combobox->entry.rect.h, w, h) == -1) return -1; if (kiss_vscrollbar_new(&combobox->vscrollbar, &combobox->window, x + combobox->textbox.rect.w, combobox->textbox.rect.y, combobox->textbox.rect.h) == -1) return -1; combobox->visible = 0; combobox->wdw = wdw; combobox->vscrollbar.step = 0.; if (combobox->textbox.array->length - combobox->textbox.maxlines > 0) combobox->vscrollbar.step = 1. / (combobox->textbox.array->length - combobox->textbox.maxlines); return 0; }
int main(int argc, char **argv) { SDL_Renderer *renderer; SDL_Event e; kiss_array objects, a; kiss_window window; kiss_label label1 = {0}, label2 = {0}; kiss_button button_ok = {0}; kiss_hscrollbar hscrollbar = {0}; kiss_entry entry = {0}; kiss_combobox combobox = {0}; kiss_selectbutton select1 = {0}, select2 = {0}; char stext[KISS_MAX_LENGTH]; int combobox_width, combobox_height, entry_width; int first, draw, quit, i; quit = 0; draw = 1; first = 0; strcpy(stext, ""); /* Combobox textbox width and height */ combobox_width = 150; combobox_height = 66; entry_width = 250; renderer = kiss_init("kiss_sdl example 2", &objects, 640, 480); if (!renderer) return 1; kiss_array_new(&a); for (i = 0; cities[i].population; i++) kiss_array_appendstring(&a, 0, cities[i].name, NULL); kiss_array_append(&objects, ARRAY_TYPE, &a); /* Arrange the widgets nicely relative to each other */ kiss_window_new(&window, NULL, 1, 0, 0, kiss_screen_width, kiss_screen_height); kiss_label_new(&label1, &window, "Population", kiss_screen_width / 2 - (combobox_width + kiss_up.w - kiss_edge) / 2 + kiss_edge, 6 * kiss_textfont.lineheight); kiss_selectbutton_new(&select1, &window, label1.rect.x + combobox_width + kiss_up.w - kiss_edge - kiss_selected.w, label1.rect.y + kiss_textfont.ascent - kiss_selected.h); kiss_label_new(&label2, &window, "Area", label1.rect.x, label1.rect.y + 2 * kiss_textfont.lineheight); kiss_selectbutton_new(&select2, &window, select1.rect.x, label2.rect.y + kiss_textfont.ascent - kiss_selected.h); kiss_combobox_new(&combobox, &window, "none", &a, label1.rect.x - kiss_edge, label2.rect.y + 2 * kiss_textfont.lineheight, combobox_width, combobox_height); kiss_entry_new(&entry, &window, 1, "", kiss_screen_width / 2 - entry_width / 2 + kiss_edge, combobox.entry.rect.y + combobox.entry.rect.h + 2 * kiss_textfont.lineheight + kiss_border, entry_width); kiss_hscrollbar_new(&hscrollbar, &window, entry.rect.x, entry.rect.y + entry.rect.h, entry.rect.w); kiss_button_new(&button_ok, &window, "OK", entry.rect.x + entry.rect.w - kiss_edge - kiss_normal.w, entry.rect.y + entry.rect.h + kiss_left.h + 2 * kiss_normal.h); select1.selected = 1; hscrollbar.step = 0.; /* Do that, and all widgets associated with the window will show */ window.visible = 1; while (!quit) { /* Some code may be written here */ SDL_Delay(10); while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) quit = 1; kiss_window_event(&window, &e, &draw); select1_event(&select1, &e, &select2, &draw); select2_event(&select2, &e, &select1, &draw); combobox_event(&combobox, &e, stext, &entry, &select1, &select2, &hscrollbar, &draw); hscrollbar_event(&hscrollbar, &e, stext, &first, &entry, &draw); button_ok_event(&button_ok, &e, &quit, &draw); } kiss_combobox_event(&combobox, NULL, &draw); hscrollbar_event(&hscrollbar, NULL, stext, &first, &entry, &draw); if (!draw) continue; SDL_RenderClear(renderer); kiss_window_draw(&window, renderer); kiss_button_draw(&button_ok, renderer); kiss_hscrollbar_draw(&hscrollbar, renderer); kiss_entry_draw(&entry, renderer); kiss_combobox_draw(&combobox, renderer); kiss_selectbutton_draw(&select2, renderer); kiss_label_draw(&label2, renderer); kiss_selectbutton_draw(&select1, renderer); kiss_label_draw(&label1, renderer); SDL_RenderPresent(renderer); draw = 0; } kiss_clean(&objects); return 0; }
int main(int argc, char **argv) { SDL_Renderer *renderer; SDL_Event e; kiss_array objects, a1, a2; kiss_window window1, window2; kiss_label label1 = {0}, label2 = {0}, label_sel = {0}, label_res = {0}; kiss_button button_ok1 = {0}, button_ok2 = {0}, button_cancel = {0}; kiss_textbox textbox1 = {0}, textbox2 = {0}; kiss_vscrollbar vscrollbar1 = {0}, vscrollbar2 = {0}; kiss_progressbar progressbar = {0}; kiss_entry entry = {0}; int textbox_width, textbox_height, window2_width, window2_height, draw, quit; quit = 0; draw = 1; textbox_width = 250; textbox_height = 250; window2_width = 400; window2_height = 168; renderer = kiss_init("kiss_sdl example 1", &objects, 640, 480); if (!renderer) return 1; kiss_array_new(&a1); kiss_array_append(&objects, ARRAY_TYPE, &a1); kiss_array_new(&a2); kiss_array_append(&objects, ARRAY_TYPE, &a2); /* Arrange the widgets nicely relative to each other */ kiss_window_new(&window1, NULL, 1, 0, 0, kiss_screen_width, kiss_screen_height); kiss_textbox_new(&textbox1, &window1, 1, &a1, kiss_screen_width / 2 - (2 * textbox_width + 2 * kiss_up.w - kiss_edge) / 2, 3 * kiss_normal.h, textbox_width, textbox_height); kiss_vscrollbar_new(&vscrollbar1, &window1, textbox1.rect.x + textbox_width, textbox1.rect.y, textbox_height); kiss_textbox_new(&textbox2, &window1, 1, &a2, vscrollbar1.uprect.x + kiss_up.w, textbox1.rect.y, textbox_width, textbox_height); kiss_vscrollbar_new(&vscrollbar2, &window1, textbox2.rect.x + textbox_width, vscrollbar1.uprect.y, textbox_height); kiss_label_new(&label1, &window1, "Folders", textbox1.rect.x + kiss_edge, textbox1.rect.y - kiss_textfont.lineheight); kiss_label_new(&label2, &window1, "Files", textbox2.rect.x + kiss_edge, textbox1.rect.y - kiss_textfont.lineheight); kiss_label_new(&label_sel, &window1, "", textbox1.rect.x + kiss_edge, textbox1.rect.y + textbox_height + kiss_normal.h); kiss_entry_new(&entry, &window1, 1, "kiss", textbox1.rect.x, label_sel.rect.y + kiss_textfont.lineheight, 2 * textbox_width + 2 * kiss_up.w + kiss_edge); kiss_button_new(&button_cancel, &window1, "Cancel", entry.rect.x + entry.rect.w - kiss_edge - kiss_normal.w, entry.rect.y + entry.rect.h + kiss_normal.h); kiss_button_new(&button_ok1, &window1, "OK", button_cancel.rect.x - 2 * kiss_normal.w, button_cancel.rect.y); kiss_window_new(&window2, NULL, 1, kiss_screen_width / 2 - window2_width / 2, kiss_screen_height / 2 - window2_height / 2, window2_width, window2_height); kiss_label_new(&label_res, &window2, "", window2.rect.x + kiss_up.w, window2.rect.y + kiss_vslider.h); label_res.textcolor = kiss_blue; kiss_progressbar_new(&progressbar, &window2, window2.rect.x + kiss_up.w - kiss_edge, window2.rect.y + window2.rect.h / 2 - kiss_bar.h / 2 - kiss_border, window2.rect.w - 2 * kiss_up.w + 2 * kiss_edge); kiss_button_new(&button_ok2, &window2, "OK", window2.rect.x + window2.rect.w / 2 - kiss_normal.w / 2, progressbar.rect.y + progressbar.rect.h + 2 * kiss_vslider.h); dirent_read(&textbox1, &vscrollbar1, &textbox2, &vscrollbar2, &label_sel); /* Do that, and all widgets associated with the window will show */ window1.visible = 1; while (!quit) { /* Some code may be written here */ SDL_Delay(10); while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) quit = 1; kiss_window_event(&window2, &e, &draw); kiss_window_event(&window1, &e, &draw); textbox1_event(&textbox1, &e, &vscrollbar1, &textbox2, &vscrollbar2, &label_sel, &draw); vscrollbar1_event(&vscrollbar1, &e, &textbox1, &draw); textbox2_event(&textbox2, &e, &vscrollbar2, &entry, &draw); vscrollbar2_event(&vscrollbar2, &e, &textbox2, &draw); button_ok1_event(&button_ok1, &e, &window1, &window2, &label_sel, &entry, &label_res, &progressbar, &draw); button_cancel_event(&button_cancel, &e, &quit, &draw); kiss_entry_event(&entry, &e, &draw); button_ok2_event(&button_ok2, &e, &window1, &window2, &progressbar, &draw); } vscrollbar1_event(&vscrollbar1, NULL, &textbox1, &draw); vscrollbar2_event(&vscrollbar2, NULL, &textbox2, &draw); kiss_progressbar_event(&progressbar, NULL, &draw); if (!draw) continue; SDL_RenderClear(renderer); kiss_window_draw(&window1, renderer); kiss_label_draw(&label1, renderer); kiss_label_draw(&label2, renderer); kiss_textbox_draw(&textbox1, renderer); kiss_vscrollbar_draw(&vscrollbar1, renderer); kiss_textbox_draw(&textbox2, renderer); kiss_vscrollbar_draw(&vscrollbar2, renderer); kiss_label_draw(&label_sel, renderer); kiss_entry_draw(&entry, renderer); kiss_button_draw(&button_ok1, renderer); kiss_button_draw(&button_cancel, renderer); kiss_window_draw(&window2, renderer); kiss_label_draw(&label_res, renderer); kiss_progressbar_draw(&progressbar, renderer); kiss_button_draw(&button_ok2, renderer); SDL_RenderPresent(renderer); draw = 0; } kiss_clean(&objects); return 0; }