Пример #1
0
void code_editor_widget::on_slider_move(double value)
{
	if(record_op("slider")) {
		save_undo_state();
	}

	std::ostringstream s;
	value = (value - 0.5)*2.0; // normalize to [-1.0,1.0] range.

	const decimal new_value(value*slider_magnitude_);
	if(slider_decimal_) {
		s << new_value;
	} else {
		s << new_value.as_int();
	}

	std::string new_string = s.str();

	ASSERT_LOG(row_slider_ >= 0 && row_slider_ < get_data().size(), "Illegal row value for slider: " << row_slider_ << " / " << get_data().size());
	std::string row = get_data()[row_slider_];

	row.erase(row.begin() + begin_col_slider_, row.begin() + end_col_slider_);
	row.insert(row.begin() + begin_col_slider_, new_string.begin(), new_string.end());

	const int old_end = end_col_slider_;
	end_col_slider_ = begin_col_slider_ + new_string.size();

	if(cursor_row() == row_slider_ && cursor_col() == old_end) {
		set_cursor(cursor_row(), end_col_slider_);
	}

	set_row_contents(row_slider_, row);
}
Пример #2
0
graphics::color code_editor_widget::get_character_color(int row, int col) const
{
	std::map<std::pair<int, int>, std::vector<std::pair<int, int> > >::const_iterator itor = bracket_match_.find(std::pair<int,int>(row,col));
	if(itor != bracket_match_.end()) {
		for(int n = 0; n != itor->second.size(); ++n) {
			const int match_row = itor->second[n].first;
			const int match_col = itor->second[n].second;
			if(cursor_row() == match_row) {
				if(cursor_col() == match_col+1 || colors_[match_row].size() == match_col+1 && cursor_col() > match_col+1) {
					return graphics::color(255, 0, 0);
				}
			}
		}
	}

	ASSERT_LOG(row >= 0 && row < colors_.size(), "Invalid row: " << row << " /" << colors_.size());
	ASSERT_LOG(col >= 0 && col < colors_[row].size(), "Invalid col: " << col << " /" << colors_[row].size());
	return colors_[row][col];
}
Пример #3
0
/* 
	We do not want to redraw our input window every time the cursor blinks.
	We only redraw the character under the cursor.
	For that we have to known the position in the text at which the cursor is.
	If the cursor is past the last character in the window text, we draw a space.
*/	
static uint8_t
draw_cursor(struct Window *win, uint8_t cursor_pos, uint8_t reversed){
	char ch;
	int cc;
	
	set_font(win->font);			// necessary !
	cc = cursor_col(cursor_pos);
	
	/* If we are past the text length, draw space */
	if (cursor_pos >= win->text_len) ch = ' ';
	else ch = win->txt[cursor_pos];
	
	if (reversed)
		draw_char(win_txt_row(win), win_txt_col(win)+ cc, ch, win->bg_color, win->fg_color, txt_col_lim(win) - cc ); 
	else	
		draw_char(win_txt_row(win), win_txt_col(win)+ cc, ch, win->fg_color, win->bg_color, txt_col_lim(win) - cc ); 
	
	return 1;
};