//------------------------------------------------------------------------ bool slider_ctrl_impl::on_arrow_keys(bool left, bool right, bool down, bool up) { double d = 0.005; if(m_num_steps) { d = 1.0 / m_num_steps; } if(right || up) { m_preview_value += d; if(m_preview_value > 1.0) m_preview_value = 1.0; normalize_value(true); return true; } if(left || down) { m_preview_value -= d; if(m_preview_value < 0.0) m_preview_value = 0.0; normalize_value(true); return true; } return false; }
//------------------------------------------------------------------------ void slider_ctrl_impl::value(double value) { m_preview_value = (value - m_min) / (m_max - m_min); if(m_preview_value > 1.0) m_preview_value = 1.0; if(m_preview_value < 0.0) m_preview_value = 0.0; normalize_value(true); }
virtual void add_loop(array_wrapper_base const& loop_headers, std::vector<array_wrapper_base*> const& values) { if (record_mode) { flush_category(); } int col_count = loop_headers.size(); assert(col_count>0); size_t period_index=loop_headers[0].find('.', 0); std::string category = loop_headers[0].substr(0, period_index); for (int i=0; i<col_count; ++i) { if (loop_headers[i].compare(0, period_index, category) != 0) { std::cerr << "Error: loop contained mixed categories " << loop_headers[i] << " and " << loop_headers[0] << "." << std::endl; exit(1); } if (i>0) { std::cout<<"\t"; } else { std::cout << "#" << category << "\t"; } std::cout << loop_headers[i].substr(period_index+1); } std::cout<<std::endl; int row_count = values[0]->size(); for (int row=0; row < row_count; ++row) { for (int i=0; i < col_count; ++i) { std::cout << "\t"; array_wrapper_base *col_vals=values[i]; std::cout << normalize_value( (*col_vals)[row] ); } std::cout << std::endl; } }
virtual void add_data_item(std::string const& tag, std::string const& value) { size_t period_index = tag.find('.', 0); std::string this_category = tag.substr(0, period_index); std::string this_key = tag.substr(period_index+1); if ( this_category != last_category ) { if ( record_mode ) { flush_category(); } last_category = this_category; } if (record_mode) { category_headers << "\t"; category_values << "\t"; } else { category_headers << "#" << this_category << "\t"; category_values << "\t"; } category_headers << this_key; category_values << normalize_value(value); record_mode = true; }
//------------------------------------------------------------------------ bool slider_ctrl_impl::on_mouse_button_up(double, double) { m_mouse_move = false; normalize_value(true); return true; }
//------------------------------------------------------------------------ void slider_ctrl_impl::rewind(unsigned idx) { m_idx = idx; switch(idx) { default: case 0: // Background m_vertex = 0; m_vx[0] = m_x1 - m_border_extra; m_vy[0] = m_y1 - m_border_extra; m_vx[1] = m_x2 + m_border_extra; m_vy[1] = m_y1 - m_border_extra; m_vx[2] = m_x2 + m_border_extra; m_vy[2] = m_y2 + m_border_extra; m_vx[3] = m_x1 - m_border_extra; m_vy[3] = m_y2 + m_border_extra; break; case 1: // Triangle m_vertex = 0; if(m_descending) { m_vx[0] = m_x1; m_vy[0] = m_y1; m_vx[1] = m_x2; m_vy[1] = m_y1; m_vx[2] = m_x1; m_vy[2] = m_y2; m_vx[3] = m_x1; m_vy[3] = m_y1; } else { m_vx[0] = m_x1; m_vy[0] = m_y1; m_vx[1] = m_x2; m_vy[1] = m_y1; m_vx[2] = m_x2; m_vy[2] = m_y2; m_vx[3] = m_x1; m_vy[3] = m_y1; } break; case 2: m_text.text(m_str_format.c_str()); if(m_str_format.length() > 2) { char_type buf[256]; _stprintf (buf, m_str_format.c_str(), value()); m_text.text(buf); } m_text.start_point(m_x1, m_y1); m_text.size((m_y2 - m_y1) * 1.2, m_y2 - m_y1); m_text_poly.width(m_text_thickness); m_text_poly.line_join(round_join); m_text_poly.line_cap(round_cap); m_text_poly.rewind(0); break; case 3: // pointer preview m_ellipse.init(m_xs1 + (m_xs2 - m_xs1) * m_preview_value, (m_ys1 + m_ys2) / 2.0, m_y2 - m_y1, m_y2 - m_y1, 32); break; case 4: // pointer normalize_value(false); m_ellipse.init(m_xs1 + (m_xs2 - m_xs1) * m_value, (m_ys1 + m_ys2) / 2.0, m_y2 - m_y1, m_y2 - m_y1, 32); m_ellipse.rewind(0); break; case 5: m_storage.remove_all(); if(m_num_steps) { unsigned i; double d = (m_xs2 - m_xs1) / m_num_steps; if(d > 0.004) d = 0.004; for(i = 0; i < m_num_steps + 1; i++) { double x = m_xs1 + (m_xs2 - m_xs1) * i / m_num_steps; m_storage.move_to(x, m_y1); m_storage.line_to(x - d * (m_x2 - m_x1), m_y1 - m_border_extra); m_storage.line_to(x + d * (m_x2 - m_x1), m_y1 - m_border_extra); } } } }
int cmd_config(int argc, const char **argv, const char *prefix) { int nongit = !startup_info->have_repository; char *value; given_config_file = getenv(CONFIG_ENVIRONMENT); argc = parse_options(argc, argv, prefix, builtin_config_options, builtin_config_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (use_global_config + use_system_config + use_local_config + !!given_config_file > 1) { error("only one config file at a time."); usage_with_options(builtin_config_usage, builtin_config_options); } if (use_global_config) { char *user_config = NULL; char *xdg_config = NULL; home_config_paths(&user_config, &xdg_config, "config"); if (access(user_config, R_OK) && !access(xdg_config, R_OK)) given_config_file = xdg_config; else if (user_config) given_config_file = user_config; else die("$HOME not set"); } else if (use_system_config) given_config_file = git_etc_gitconfig(); else if (use_local_config) given_config_file = git_pathdup("config"); else if (given_config_file) { if (!is_absolute_path(given_config_file) && prefix) given_config_file = xstrdup(prefix_filename(prefix, strlen(prefix), given_config_file)); } if (respect_includes == -1) respect_includes = !given_config_file; if (end_null) { term = '\0'; delim = '\n'; key_delim = '\n'; } if (HAS_MULTI_BITS(types)) { error("only one type at a time."); usage_with_options(builtin_config_usage, builtin_config_options); } if (get_color_slot) actions |= ACTION_GET_COLOR; if (get_colorbool_slot) actions |= ACTION_GET_COLORBOOL; if ((get_color_slot || get_colorbool_slot) && types) { error("--get-color and variable type are incoherent"); usage_with_options(builtin_config_usage, builtin_config_options); } if (HAS_MULTI_BITS(actions)) { error("only one action at a time."); usage_with_options(builtin_config_usage, builtin_config_options); } if (actions == 0) switch (argc) { case 1: actions = ACTION_GET; break; case 2: actions = ACTION_SET; break; case 3: actions = ACTION_SET_ALL; break; default: usage_with_options(builtin_config_usage, builtin_config_options); } if (actions == ACTION_LIST) { check_argc(argc, 0, 0); if (git_config_with_options(show_all_config, NULL, given_config_file, respect_includes) < 0) { if (given_config_file) die_errno("unable to read config file '%s'", given_config_file); else die("error processing config file(s)"); } } else if (actions == ACTION_EDIT) { check_argc(argc, 0, 0); if (!given_config_file && nongit) die("not in a git directory"); git_config(git_default_config, NULL); launch_editor(given_config_file ? given_config_file : git_path("config"), NULL, NULL); } else if (actions == ACTION_SET) { int ret; check_argc(argc, 2, 2); value = normalize_value(argv[0], argv[1]); ret = git_config_set_in_file(given_config_file, argv[0], value); if (ret == CONFIG_NOTHING_SET) error("cannot overwrite multiple values with a single value\n" " Use a regexp, --add or --replace-all to change %s.", argv[0]); return ret; } else if (actions == ACTION_SET_ALL) { check_argc(argc, 2, 3); value = normalize_value(argv[0], argv[1]); return git_config_set_multivar_in_file(given_config_file, argv[0], value, argv[2], 0); } else if (actions == ACTION_ADD) { check_argc(argc, 2, 2); value = normalize_value(argv[0], argv[1]); return git_config_set_multivar_in_file(given_config_file, argv[0], value, "^$", 0); } else if (actions == ACTION_REPLACE_ALL) { check_argc(argc, 2, 3); value = normalize_value(argv[0], argv[1]); return git_config_set_multivar_in_file(given_config_file, argv[0], value, argv[2], 1); } else if (actions == ACTION_GET) { check_argc(argc, 1, 2); return get_value(argv[0], argv[1]); } else if (actions == ACTION_GET_ALL) { do_all = 1; check_argc(argc, 1, 2); return get_value(argv[0], argv[1]); } else if (actions == ACTION_GET_REGEXP) { show_keys = 1; use_key_regexp = 1; do_all = 1; check_argc(argc, 1, 2); return get_value(argv[0], argv[1]); } else if (actions == ACTION_UNSET) { check_argc(argc, 1, 2); if (argc == 2) return git_config_set_multivar_in_file(given_config_file, argv[0], NULL, argv[1], 0); else return git_config_set_in_file(given_config_file, argv[0], NULL); } else if (actions == ACTION_UNSET_ALL) { check_argc(argc, 1, 2); return git_config_set_multivar_in_file(given_config_file, argv[0], NULL, argv[1], 1); } else if (actions == ACTION_RENAME_SECTION) { int ret; check_argc(argc, 2, 2); ret = git_config_rename_section_in_file(given_config_file, argv[0], argv[1]); if (ret < 0) return ret; if (ret == 0) die("No such section!"); } else if (actions == ACTION_REMOVE_SECTION) { int ret; check_argc(argc, 1, 1); ret = git_config_rename_section_in_file(given_config_file, argv[0], NULL); if (ret < 0) return ret; if (ret == 0) die("No such section!"); } else if (actions == ACTION_GET_COLOR) { get_color(argv[0]); } else if (actions == ACTION_GET_COLORBOOL) { if (argc == 1) color_stdout_is_tty = git_config_bool("command line", argv[0]); return get_colorbool(argc != 0); } return 0; }
int cmd_config(int argc, const char **argv, const char *prefix) { int nongit; char* value; const char *file = setup_git_directory_gently(&nongit); while (1 < argc) { if (!strcmp(argv[1], "--int")) type = T_INT; else if (!strcmp(argv[1], "--bool")) type = T_BOOL; else if (!strcmp(argv[1], "--bool-or-int")) type = T_BOOL_OR_INT; else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l")) { if (argc != 2) usage(git_config_set_usage); if (git_config(show_all_config) < 0 && file && errno) die("unable to read config file %s: %s", file, strerror(errno)); return 0; } else if (!strcmp(argv[1], "--global")) { char *home = getenv("HOME"); if (home) { char *user_config = xstrdup(mkpath("%s/.gitconfig", home)); setenv(CONFIG_ENVIRONMENT, user_config, 1); free(user_config); } else { die("$HOME not set"); } } else if (!strcmp(argv[1], "--system")) setenv(CONFIG_ENVIRONMENT, git_etc_gitconfig(), 1); else if (!strcmp(argv[1], "--file") || !strcmp(argv[1], "-f")) { if (argc < 3) usage(git_config_set_usage); if (!is_absolute_path(argv[2]) && file) file = prefix_filename(file, strlen(file), argv[2]); else file = argv[2]; setenv(CONFIG_ENVIRONMENT, file, 1); argc--; argv++; } else if (!strcmp(argv[1], "--null") || !strcmp(argv[1], "-z")) { term = '\0'; delim = '\n'; key_delim = '\n'; } else if (!strcmp(argv[1], "--rename-section")) { int ret; if (argc != 4) usage(git_config_set_usage); ret = git_config_rename_section(argv[2], argv[3]); if (ret < 0) return ret; if (ret == 0) { fprintf(stderr, "No such section!\n"); return 1; } return 0; } else if (!strcmp(argv[1], "--remove-section")) { int ret; if (argc != 3) usage(git_config_set_usage); ret = git_config_rename_section(argv[2], NULL); if (ret < 0) return ret; if (ret == 0) { fprintf(stderr, "No such section!\n"); return 1; } return 0; } else if (!strcmp(argv[1], "--get-color")) { return get_color(argc-2, argv+2); } else if (!strcmp(argv[1], "--get-colorbool")) { return get_colorbool(argc-2, argv+2); } else break; argc--; argv++; } switch (argc) { case 2: return get_value(argv[1], NULL); case 3: if (!strcmp(argv[1], "--unset")) return git_config_set(argv[2], NULL); else if (!strcmp(argv[1], "--unset-all")) return git_config_set_multivar(argv[2], NULL, NULL, 1); else if (!strcmp(argv[1], "--get")) return get_value(argv[2], NULL); else if (!strcmp(argv[1], "--get-all")) { do_all = 1; return get_value(argv[2], NULL); } else if (!strcmp(argv[1], "--get-regexp")) { show_keys = 1; use_key_regexp = 1; do_all = 1; return get_value(argv[2], NULL); } else { value = normalize_value(argv[1], argv[2]); return git_config_set(argv[1], value); } case 4: if (!strcmp(argv[1], "--unset")) return git_config_set_multivar(argv[2], NULL, argv[3], 0); else if (!strcmp(argv[1], "--unset-all")) return git_config_set_multivar(argv[2], NULL, argv[3], 1); else if (!strcmp(argv[1], "--get")) return get_value(argv[2], argv[3]); else if (!strcmp(argv[1], "--get-all")) { do_all = 1; return get_value(argv[2], argv[3]); } else if (!strcmp(argv[1], "--get-regexp")) { show_keys = 1; use_key_regexp = 1; do_all = 1; return get_value(argv[2], argv[3]); } else if (!strcmp(argv[1], "--add")) { value = normalize_value(argv[2], argv[3]); return git_config_set_multivar(argv[2], value, "^$", 0); } else if (!strcmp(argv[1], "--replace-all")) { value = normalize_value(argv[2], argv[3]); return git_config_set_multivar(argv[2], value, NULL, 1); } else { value = normalize_value(argv[1], argv[2]); return git_config_set_multivar(argv[1], value, argv[3], 0); } case 5: if (!strcmp(argv[1], "--replace-all")) { value = normalize_value(argv[2], argv[3]); return git_config_set_multivar(argv[2], value, argv[4], 1); } case 1: default: usage(git_config_set_usage); } return 0; }
void Construct(const std::string& _id, const std::string& _name, unsigned int _length, const raw_pair<std::string, value_t>* _value_pairs, size_t nvalues, const std::string& value_default_name) { ConstructBasic(_id, _name, _length, value_t()); ConstructValues(_value_pairs, nvalues); value_default = normalize_value(value_default_name); }