Beispiel #1
0
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});
}
Rect InputProcessing::getRightEyePosition(Mat frame, Rect facePosition) {
    Size minS((int)(facePosition.width*.15), (int)(facePosition.height*.15));
    Size maxS((int)(facePosition.width*.4), (int)(facePosition.height*.4));
    vector<Rect> eyes(1);
    facePosition.width /= 2;
    facePosition.height /= 2;
    facePosition.y += facePosition.height / 3;
    Mat  face(frame, facePosition);
    eyeCascade.detectMultiScale(face, eyes, 1.05, 3, CV_HAAR_FIND_BIGGEST_OBJECT,minS,maxS);
    if (eyes.size() == 0) {
        return  Rect(0,0,0,0);
    }
    eyes.at(0).x += facePosition.x;
    eyes.at(0).y += facePosition.y;
    //from empirical observations, cascades tend to crop right parts for both eyes, so we add width
    eyes.at(0).width += (int) ceil(eyes.at(0).width *.125);
    return eyes.at(0);
}
Beispiel #3
0
bool ListBox::on_key (wchar_t key)
{
	Scroll::Info scroll_info = scroll_.get_info();
	switch (key) {
		case UP:
		case 'k':
			if (!select_any) {
				if (items.empty ()) {
					return false;
				}
				set_select (scroll_info.focus);
				return true;
			}
			else {
				if (items.size () == 0) {
					return false;
				}
				if (scroll_info.focus == 0) {
					return false;
				}
				set_select (scroll_info.focus - 1);
				return true;
			}

		case DOWN:
		case 'j':
			if (!select_any) {
				if (items.empty ()) {
					return false;
				}
				set_select (scroll_info.focus);
				return true;
			}
			else {
				if (items.size () == 0) {
					return false;
				}
				if (scroll_info.focus + 1 >= items.size ()) {
					return false;
				}
				set_select (scroll_info.focus + 1);
				return true;
			}

		case PAGEUP:
			if (items.size () == 0) {
				return false;
			}
			if (scroll_info.focus == 0) {
				return false;
			}
			set_select (maxS (0, scroll_info.focus - get_size().y + 1));
			return true;

		case PAGEDOWN:
			if (items.size () == 0) {
				return false;
			}
			if (scroll_info.focus + 1 >= items.size ()) {
				return false;
			}
			set_select (minS (scroll_info.focus + get_size().y - 1, items.size () - 1));
			return true;

		case HOME:
		case L'g':
		case L'0':
		case L'^':
			if (items.size () == 0) {
				return false;
			}
			set_select (0);
			return true;

		case END:
		case L'G':
		case L'$':
			if (items.size () == 0) {
				return false;
			}
			set_select (items.size () - 1);
			return true;

		case L' ':
			if (select_any) {
				return false;
			}
			else {
				set_select (scroll_info.focus);
				return true;
			}

		default:
			return false;
	}
	assert (false);
}
Beispiel #4
0
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;
}