コード例 #1
0
ファイル: kiss_widgets.c プロジェクト: IceOrchid/kiss_sdl
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;
}
コード例 #2
0
ファイル: kiss_example1.c プロジェクト: AVividLight/kiss_sdl
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;
}