void code_editor_widget::select_token(const std::string& row, int& begin_row, int& end_row, int& begin_col, int& end_col) { std::pair<int,int> key(begin_row, begin_col); if(bracket_match_.count(key)) { begin_row = bracket_match_.find(key)->second.front().first; begin_col = bracket_match_.find(key)->second.front().second; end_row = bracket_match_.find(key)->second.back().first; end_col = bracket_match_.find(key)->second.back().second+1; return; } text_editor_widget::select_token(row, begin_row, end_row, begin_col, end_col); std::string token(row.begin() + begin_col, row.begin() + end_col); boost::regex numeric_regex("-?\\d+(\\.\\d+)?", boost::regex::perl); std::cerr << "token: (" << token << ")\n"; if(boost::regex_match(token.c_str(), numeric_regex)) { const decimal current_value(decimal::from_string(token)); if(current_value <= 10000000 && current_value >= -10000000) { slider_.reset(new slider(200, boost::bind(&code_editor_widget::on_slider_move, this, _1))); slider_decimal_ = std::count(token.begin(), token.end(), '.') ? true : false; slider_magnitude_ = (abs(current_value.as_int())+1) * 5; const decimal slider_value = (current_value - decimal::from_int(-slider_magnitude_)) / decimal::from_int(slider_magnitude_*2); slider_->set_position(slider_value.as_float()); std::pair<int,int> pos = char_position_on_screen(begin_row, (begin_col+end_col)/2); row_slider_ = begin_row; begin_col_slider_ = begin_col; end_col_slider_ = end_col; int x = pos.second - slider_->width()/2; int y = pos.first + 20 - slider_->height(); if(x < 10) { x = 10; } if(x > width() - slider_->width()) { x = width() - slider_->width(); } if(y < 20) { y += 60; } if(y > height() - slider_->height()) { y = height() - slider_->height(); } slider_->set_loc(x, y); } } }
void code_editor_widget::select_token(const std::string& row, int& begin_row, int& end_row, int& begin_col, int& end_col) { std::pair<int,int> key(begin_row, begin_col); if(bracket_match_.count(key)) { begin_row = bracket_match_.find(key)->second.front().first; begin_col = bracket_match_.find(key)->second.front().second; end_row = bracket_match_.find(key)->second.back().first; end_col = bracket_match_.find(key)->second.back().second+1; return; } text_editor_widget::select_token(row, begin_row, end_row, begin_col, end_col); std::string token(row.begin() + begin_col, row.begin() + end_col); boost::regex numeric_regex("-?\\d+(\\.\\d+)?", boost::regex::perl); std::cerr << "token: (" << token << ")\n"; if(boost::regex_match(token.c_str(), numeric_regex)) { const decimal current_value(decimal::from_string(token)); if(current_value <= 10000000 && current_value >= -10000000) { slider_.reset(new slider(200, boost::bind(&code_editor_widget::on_slider_move, this, _1))); slider_decimal_ = std::count(token.begin(), token.end(), '.') ? true : false; slider_magnitude_ = (abs(current_value.as_int())+1) * 5; const decimal slider_value = (current_value - decimal::from_int(-slider_magnitude_)) / decimal::from_int(slider_magnitude_*2); slider_->set_position(slider_value.as_float()); slider_range_.clear(); slider_labels_.clear(); if(current_value > 0) { slider_range_.push_back(slider_range(0.0, 0.1, -current_value*5, -current_value)); slider_range_.push_back(slider_range(0.1, 0.2, -current_value, decimal(0))); slider_range_.push_back(slider_range(0.2, 0.3, decimal(0), current_value)); slider_range_.push_back(slider_range(0.3, 0.5, decimal(0), current_value)); slider_range_.push_back(slider_range(0.5, 0.7, current_value, 2*current_value)); slider_range_.push_back(slider_range(0.7, 0.9, 2*current_value, 5*current_value)); slider_range_.push_back(slider_range(0.9, 1.0, 5*current_value, 10*current_value)); slider_range_.push_back(slider_range(1.0, 2.0, 10*current_value, 20*current_value)); slider_->set_position(0.5); } else { slider_range_.push_back(slider_range(0.0, 0.5, current_value*2, decimal(0))); slider_range_.push_back(slider_range(0.5, 1.0, decimal(0), -current_value*2)); slider_range_.push_back(slider_range(1.0, 2.0, -current_value*2, -current_value*4)); slider_->set_position(0.25); } std::pair<int,int> pos = char_position_on_screen(begin_row, (begin_col+end_col)/2); row_slider_ = begin_row; begin_col_slider_ = begin_col; end_col_slider_ = end_col; int x = pos.second - slider_->width()/2; int y = pos.first + 20 - slider_->height(); if(x < 10) { x = 10; } if(x > width() - slider_->width()) { x = width() - slider_->width(); } if(y < 20) { y += 60; } if(y > height() - slider_->height()) { y = height() - slider_->height(); } slider_->set_loc(x, y); foreach(slider_range& r, slider_range_) { slider_labels_.push_back(widget_ptr(new gui::label(formatter() << r.target_begin, 10))); slider_labels_.back()->set_loc(x + slider_->width()*r.begin - slider_labels_.back()->width()/2, y); } }