예제 #1
0
파일: menubar.cpp 프로젝트: chys87/tiary
void MenuBar::slot_clicked (size_t k)
{
	for (;;) {
		assert (k < item_list.size ());

		// Get the item
		Item &item = item_list[k];

		// Highlight the selected item
		choose_palette (PALETTE_ID_MENUBAR_SELECT);
		item.text.output(*this, {item.w, 0}, item.text.get_width());

		Size left = window().get_pos() + get_pos() + Size{item.w, 1};
		Size right{get_screen_width(), left.y};

		// Pop out sub menu
		MenuItem *chosen_item = item.menu->show (left, right);

		// Restore display
		choose_palette (PALETTE_ID_MENUBAR);
		item.text.output(*this, {item.w, 0}, item.text.get_width());

		// Deal with the result
		if (chosen_item) {
			chosen_item->action.emit ();
			break;
		}

		// LEFT/RIGHT key?
		MouseEvent me_buf;
		wchar_t c = window().get_noblock(&me_buf);
		if (c == LEFT) {
			k = (k + item_list.size () - 1) % item_list.size ();
		}
		else if (c == RIGHT) {
			k = (k + 1) % item_list.size ();
		}
		else {
			if (c) {
				if (c == MOUSE) {
					window().unget(me_buf);
				}
				else {
					window().unget(c);
				}
			}
			break;
		}
	}
}
예제 #2
0
파일: draw.c 프로젝트: thomaselain/fractol
void	draw_window(t_env *e)
{
	int		x;
	int		y;
	void	(*f)(int x, int y, t_env *e, int i);

	y = -1;
	e->data = mlx_get_data_addr(e->img, &(e->bpp), &(e->sl), &(e->endi));
	if (ft_strcmp(e->fractal, "mandelbrot") == 0)
		(f) = &mandelbrot;
	else if (ft_strcmp(e->fractal, "julia") == 0)
		(f) = &julia;
	else if (ft_strcmp(e->fractal, "fisheye") == 0)
		(f) = &fisheye;
	else if (ft_strcmp(e->fractal, "burningship") == 0)
		(f) = &burningship;
	choose_palette(e);
	while (++y < WIN_Y && f)
	{
		x = -1;
		while (++x < WIN_X)
			f(x, y, e, 0);
	}
	mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0);
	mlx_string_put(e->mlx, e->win, 0, 2, 0x808080, "Fractale\t\t: ");
	mlx_string_put(e->mlx, e->win, 110, 2, 0x808080, e->fractal);
}
예제 #3
0
파일: listbox.cpp 프로젝트: chys87/tiary
void ListBox::redraw ()
{
	unsigned disp_wid = get_size().x - 1; // Reserve one for scrollbar
	unsigned disp_hgt = get_size().y;
	if (disp_wid==0 || disp_hgt==0) {
		return;
	}
	choose_palette (PALETTE_ID_LISTBOX);
	clear ();
	const Scroll::Info info = scroll_.get_info();
	for (unsigned i=0; i<info.len; ++i) {
		const std::wstring &str = items[info.first+i];
		choose_palette ((select_any && i==info.focus_pos) ? PALETTE_ID_LISTBOX_SELECT : PALETTE_ID_LISTBOX);
		Size pos{0, i};
		unsigned strwid = ucs_width (str);
		// Are we going to overflow?
		if (strwid <= disp_wid) {
			//NO:
			pos = put (pos, str);
			if (select_any && i==info.focus_pos) // Focus? Highlight the whole line
				clear(pos, {disp_wid - pos.x, 1});
		}
		else {
			// YES: Cannot display all
			size_t display_wchars = max_chars_in_width (str, maxS (disp_wid - 4, 0));
			put (pos, str.c_str (), display_wchars);
			choose_palette (PALETTE_ID_LISTBOX);
			pos = put(Size(maxS(disp_wid - 4, 0), i), L' ');
			attribute_toggle (REVERSE);
			pos = put (pos, L"...");
		}
	}
	// Display the scroll bar
	choose_palette (PALETTE_ID_LISTBOX);
	clear({disp_wid, 0}, {1, disp_hgt});
	attribute_toggle (REVERSE);
	ScrollBarInfo scrollbar = scrollbar_info (disp_hgt, items.size(), info.first);
	clear({disp_wid, scrollbar.pos}, {1, scrollbar.size});

	move_cursor({0, info.focus_pos});
}
예제 #4
0
파일: menubar.cpp 프로젝트: chys87/tiary
void MenuBar::redraw ()
{
	choose_palette (PALETTE_ID_MENUBAR);
	clear ();
	for (ItemList::iterator it=item_list.begin(); it!=item_list.end(); ++it) {
		it->text.output(*this, {it->w, 0}, it->text.get_width ());
	}
	unsigned x = 0;
	if (!item_list.empty ()) {
		x = item_list.back ().w + item_list.back ().text.get_width () + 2;
	}
	if (x < get_size ().x) {
		// Align to the right
		unsigned w = minU (get_size ().x - x, text.get_width ());
		x = get_size ().x - w;
		text.output(*this, {x, 0}, w);
	}
}
예제 #5
0
void CheckBox::redraw ()
{
	choose_palette (is_focus () ? PALETTE_ID_CHECKBOX_FOCUS : PALETTE_ID_CHECKBOX);
	clear ();
	unsigned wid = get_size().x;
	Size pos = make_size ();
	if (wid >= 3) {
		pos = put (pos, L'[');
	}
	move_cursor (pos);
	// U+00D7 is Multipilcation sign
	pos = put (pos, status ? (
				terminal_emulator_correct_wcwidth () ? L'\u00d7' : L'x'
				) : L' ');
	if (wid >= 3) {
		put (pos, L']');
	}
}
예제 #6
0
void DropList::redraw ()
{
	choose_palette (is_focus () ? PALETTE_ID_DROPLIST_FOCUS : PALETTE_ID_DROPLIST);
	clear ();
	put (make_size (), items[select]);
}
예제 #7
0
파일: mainctrl.cpp 프로젝트: chys87/tiary
void MainCtrl::redraw ()
{
	choose_palette (ui::PALETTE_ID_ENTRY);
	clear ();

	if (w().entries.empty ()) {
		put(ui::Size{}, L"No entry yet.");
		put(ui::Size{0, 1}, L"Press \"a\" to create one; press Esc for the menu.");
#ifdef TIARY_USE_MOUSE
		put(ui::Size{0, 2}, L"You can also use your mouse.");
#endif
		return;
	}

	if (w().filtered_entries_ && w().filtered_entries_->empty ()) {
		put(ui::Size{}, L"This is in filtered mode.");
		put(ui::Size{0, 1}, L"But no entry satisfies your requirement.");
		put(ui::Size{0, 2}, L"Press Ctrl-G to modify your filter; or LEFT to see all entries.");
		return;
	}

	unsigned expand_lines = w().global_options.get_num (GLOBAL_OPTION_EXPAND_LINES);
	scroll_.modify_height(get_size().y - expand_lines + 1);

	ui::Scroll::Info info = scroll_.get_info();

	ui::Size pos{};

	std::wstring date_format = w().global_options.get_wstring (GLOBAL_OPTION_DATETIME_FORMAT);

	// Build a map to get entry ID from pointer
	std::map <const DiaryEntry *, unsigned> id_map;
	for (size_t i=0; i<w().entries.size (); ++i) {
		id_map.insert (std::make_pair (w().entries[i], i+1));
	}
	// Is there a filter?
	const DiaryEntryList &ent_lst = w().get_current_list ();

	wchar_t *disp_buffer = new wchar_t [get_size ().x];

	for (unsigned i=0; i<info.len; ++i) {

		choose_palette (i == info.focus_pos ? ui::PALETTE_ID_ENTRY_SELECT : ui::PALETTE_ID_ENTRY);

		if (i == info.focus_pos) {
			move_cursor (pos);
			clear(pos, ui::Size{get_size().x, expand_lines});
		}
		const DiaryEntry &entry = *ent_lst[i+info.first];

		// Entry ID
		pos = put(pos, format(L"%04a  "sv, id_map[&entry]));

		// Date
		choose_palette (i == info.focus_pos ? ui::PALETTE_ID_ENTRY_DATE_SELECT : ui::PALETTE_ID_ENTRY_DATE);
		pos = put(pos, entry.local_time.format(date_format));
		pos.x++;

		// Title
		SplitStringLine split_info;
		const std::wstring &title = entry.title;
		choose_palette (i == info.focus_pos ? ui::PALETTE_ID_ENTRY_TITLE_SELECT : ui::PALETTE_ID_ENTRY_TITLE);
		split_line(&split_info, maxS (0, get_size().x-pos.x), title, 0, SPLIT_NEWLINE_AS_SPACE|SPLIT_CUT_WORD);
		pos = put (pos, disp_buffer,
				std::replace_copy_if (
						&title[split_info.begin], &title[split_info.begin+split_info.len],
						disp_buffer, [](auto x) { return !iswprint(x); }, L' ') - disp_buffer);
		pos.x++;

		// Labels
		const DiaryEntry::LabelList &labels = entry.labels;
		choose_palette (i == info.focus_pos ? ui::PALETTE_ID_ENTRY_LABELS_SELECT : ui::PALETTE_ID_ENTRY_LABELS);
		int left_wid = get_size().x - pos.x;
		for (DiaryEntry::LabelList::const_iterator it=labels.begin(); it!=labels.end(); ) {
			if (left_wid < 3) {
				break;
			}
			unsigned labelwid = ucs_width (*it);
			if (labelwid + 2 > unsigned (left_wid)) {
				pos = put (pos, L"...", 3);
				break;
			}
			pos = put (pos, *it);
			if (++it != labels.end ()) {
				pos = put (pos, L',');
			}
		}
		pos.x++;

		choose_palette (i == info.focus_pos ? ui::PALETTE_ID_ENTRY_TEXT_SELECT : ui::PALETTE_ID_ENTRY_TEXT);
		const std::wstring &text = entry.text;
		size_t offset = 0;
		if (i == info.focus_pos && expand_lines >= 2) {
			// Current entry
			// [Date] [Title] [Labels]
			// [...]
			for (unsigned j=1; j<expand_lines; ++j) {
				pos = ui::Size{0, pos.y + 1};
				offset = split_line(&split_info, get_size().x, text, offset,
						SPLIT_NEWLINE_AS_SPACE);
				wchar_t *bufend = std::replace_copy_if (
						&text[split_info.begin], &text[split_info.begin+split_info.len],
						disp_buffer, [](auto x) { return !iswprint(x); }, L' ');
				pos = put (pos, disp_buffer, bufend-disp_buffer);
			}
		} else {
			// Other entry
			// [Date] [Title] [Labels] [...]
			offset = split_line(&split_info, maxS (0, get_size().x - pos.x), text, offset,
					SPLIT_NEWLINE_AS_SPACE|SPLIT_CUT_WORD);
			wchar_t *bufend = std::replace_copy_if (
					&text[split_info.begin], &text[split_info.begin+split_info.len],
					disp_buffer, [](auto x) { return !iswprint(x); }, L' ');
			pos = put (pos, disp_buffer, bufend-disp_buffer);
		}
		pos = ui::Size{0, pos.y + 1};
	}
	delete [] disp_buffer;
}