void update_random_value(int type,int type_num,int motion_type) { float random_walk_value = 0.1; float random_rotate_value = 0.025; switch(motion_type) { case 0: update_values(0,-random_walk_value,0,-random_walk_value,type,type_num); break; case 1: update_values(0,random_walk_value,0,random_walk_value,type,type_num); break; case 2: update_values(-random_walk_value,0,-random_walk_value,0,type,type_num); break; case 3: update_values(random_walk_value,0,random_walk_value,0,type,type_num); break; case 4: rotate_object(-atan(random_rotate_value),-1,type,type_num); break; case 5: rotate_object(atan(random_rotate_value),1,type,type_num); break; } glutPostRedisplay(); }
void AbstractForm::set_xy_of_point(int point, float x, float y) { points[point].set_x(x); points[point].set_y(y); update_bounding_box(x,y); update_values(); }
static void poll_devices (void) { int n; int mixernum; value_packet_t value_packet; for (mixernum=0;mixernum<num_mixers;mixernum++) if (mixer_open_mask[mixernum / 8] & 1<<(mixernum % 8)) { update_values (mixernum); n = mixc_get_all_values (mixernum, value_packet, 1); if (n==0) /* Nothing changed */ continue; send_response_long (OSSMIX_EVENT_VALUE, n, mixernum, 0, 0, 0, (void *) &value_packet, n * sizeof (value_record_t), 1); mixc_clear_changeflags (mixernum); } n=ossmix_get_nmixers(); if (n>num_mixers) { num_mixers=n; send_response (OSSMIX_EVENT_NEWMIXER, n, 0, 0, 0, 0, 1); } }
/// This handles the more difficult case of setting individual slices of a var. static int set_var_slices(const wchar_t *cmd, set_cmd_opts_t &opts, const wchar_t *varname, wcstring_list_t &new_values, std::vector<long> &indexes, int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { UNUSED(parser); if (opts.append || opts.prepend) { streams.err.append_format( L"%ls: Cannot use --append or --prepend when assigning to a slice", cmd); builtin_print_error_trailer(parser, streams.err, cmd); return STATUS_INVALID_ARGS; } if (indexes.size() != static_cast<size_t>(argc)) { streams.err.append_format(BUILTIN_SET_MISMATCHED_ARGS, cmd, indexes.size(), argc); return STATUS_INVALID_ARGS; } int scope = compute_scope(opts); // calculate the variable scope based on the provided options const auto var_str = parser.vars().get(varname, scope); if (var_str) var_str->to_list(new_values); // Slice indexes have been calculated, do the actual work. wcstring_list_t result; for (int i = 0; i < argc; i++) result.push_back(argv[i]); int retval = update_values(new_values, indexes, result); if (retval != STATUS_CMD_OK) { streams.err.append_format(BUILTIN_SET_ARRAY_BOUNDS_ERR, cmd); return retval; } return STATUS_CMD_OK; }
void AbstractForm::add_point_to_form(float x, float y) { Point new_point(x,y); points.push_back(new_point); update_bounding_box(x,y); update_values(); }
AbstractForm::AbstractForm(string name, vector<Point> points) { #ifdef DEBUG_AF printf("CONSTRUCTOR: %s\n", __PRETTY_FUNCTION__); #endif this->name = name; this->points = vector<Point>(points); number_of_points = points.size(); this->id = total_number_of_abstract_forms++; dx = 0; dy = 0; min_x = 0; max_x = 0; min_y = 0; max_y = 0; fits_with_optimal_rotation = false; size_of_area = 0; convex_hull.reserve(number_of_points); calc_bounding_box(); #ifdef DEBUG_AF printf("Created abstractForm with bounding box %.2f/%.2f - %.2f/%.2f\n", min_x, min_y, min_x + dx, min_y + dy); #endif convex_hull = vector<int>(); update_values(); }
gradient_radial_focus() : m_r(100 * gradient_subpixel_scale) , m_fx(0) , m_fy(0) { update_values(); }
void init(scalar r, scalar fx, scalar fy) { m_r = iround(r * gradient_subpixel_scale); m_fx = iround(fx * gradient_subpixel_scale); m_fy = iround(fy * gradient_subpixel_scale); update_values(); }
static void style_selected (Widget w, int i, XmToggleButtonCallbackStruct * cbs) { RouteStyleType *style; int j, n; if (cbs && cbs->set == 0) { XmToggleButtonSetState (w, 1, 0); return; } style = PCB->RouteStyle + i; SetLineSize (style->Thick); SetViaSize (style->Diameter, true); SetViaDrillingHole (style->Hole, true); SetKeepawayWidth (style->Keepaway); if (style_dialog) { for (j = 0; j < NUM_STYLES; j++) if (j != i) XmToggleButtonSetState (style_pb[j], 0, 0); else XmToggleButtonSetState (style_pb[j], 1, 0); update_values (); } else lesstif_update_status_line (); for (n = 0; n < num_style_buttons; n++) { for (j = 0; j < NUM_STYLES; j++) if (j != i) XmToggleButtonSetState (style_button_list[n].w[j], 0, 0); else XmToggleButtonSetState (style_button_list[n].w[j], 1, 0); } }
static int RouteStylesChanged (int argc, char **argv, Coord x, Coord y) { int i, j, h; if (!PCB || !PCB->RouteStyle[0].Name) return 0; update_style_buttons (); if (!style_dialog) return 0; for (j = 0; j < NUM_STYLES; j++) { h = hash (PCB->RouteStyle[j].Name); if (name_hashes[j] == h) continue; name_hashes[j] = h; n = 0; stdarg (XmNlabelString, XmStringCreatePCB (PCB->RouteStyle[j].Name)); if (style_dialog) XtSetValues (style_pb[j], args, n); for (i = 0; i < num_style_buttons; i++) XtSetValues (style_button_list[i].w[j], args, n); } update_values (); return 0; }
virtual void go() { release(); param *p = param::instance(); update_values(p); Iso_rectangle_2 bbox = get_bbox(p); std::string ndvi_file = p->get<boost::filesystem::path>("ndvi").string(); std::string dsm_file = p->get<boost::filesystem::path>("dsm" ).string(); clip_bbox(bbox,ndvi_file); clip_bbox(bbox,dsm_file ); gradient_functor gf(p->get<double>("sigmaD")); oriented_gradient_view grad_view(dsm_file, bbox, gf); oriented_ndvi_view ndvi_view(ndvi_file, bbox); m_confg_visitor->add_layer(ndvi_file); m_confg_visitor->add_layer(dsm_file); set_bbox(p,bbox); wxPoint p0(wxCoord(bbox.min().x()),wxCoord(bbox.min().y())); wxPoint p1(wxCoord(bbox.max().x()),wxCoord(bbox.max().y())); m_confg_visitor->set_bbox(wxRect(p0,p1)); init_visitor (p,*m_visitor); create_configuration(p,grad_view,ndvi_view,m_config); create_sampler (p,m_sampler); create_schedule (p,m_schedule); create_end_test (p,m_end_test); m_thread = new boost::thread( simulated_annealing::optimize<configuration,sampler,schedule,end_test,visitor>, boost::ref(*m_config), boost::ref(*m_sampler), boost::ref(*m_schedule), boost::ref(*m_end_test), boost::ref(*m_visitor) ); }
static void update_preview (GimpPreview *preview, GimpDrawable *drawable) { update_values (); grid (gimp_item_get_image (drawable->drawable_id), drawable, preview); }
static void gnl_object_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GnlObject *gnlobject = (GnlObject *) object; g_return_if_fail (GNL_IS_OBJECT (object)); switch (prop_id) { case PROP_START: gnlobject->start = g_value_get_uint64 (value); update_values (gnlobject); break; case PROP_DURATION: gnlobject->duration = g_value_get_int64 (value); update_values (gnlobject); break; case PROP_MEDIA_START: gnlobject->media_start = g_value_get_uint64 (value); break; case PROP_MEDIA_DURATION: gnlobject->media_duration = g_value_get_int64 (value); update_values (gnlobject); break; case PROP_PRIORITY: gnlobject->priority = g_value_get_uint (value); break; case PROP_ACTIVE: gnlobject->active = g_value_get_boolean (value); break; case PROP_CAPS: gnl_object_set_caps (gnlobject, gst_value_get_caps (value)); break; case PROP_EXPANDABLE: if (g_value_get_boolean (value)) GST_OBJECT_FLAG_SET (gnlobject, GNL_OBJECT_EXPANDABLE); else GST_OBJECT_FLAG_UNSET (gnlobject, GNL_OBJECT_EXPANDABLE); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
void handle_special_keyboard_keys(int key,int x,int y) { if(key == GLUT_KEY_DOWN) { update_values(0,-trans_val,0,-trans_val,select_type,select_number); } if(key == GLUT_KEY_UP) { update_values(0,trans_val,0,trans_val,select_type,select_number); } if(key == GLUT_KEY_LEFT) { update_values(-trans_val,0,-trans_val,0,select_type,select_number); } if(key == GLUT_KEY_RIGHT) { update_values(trans_val,0,trans_val,0,select_type,select_number); } }
static void units_cb () { if (unit == get_unit_struct ("mm")) unit = get_unit_struct ("mil"); else unit = get_unit_struct ("mm"); ustr = XmStringCreateLocalized ((char *)unit->suffix); update_values (); }
void AbstractForm::erase_point_at_index(int index) { points.erase(points.begin()+index); calc_bounding_box(); update_values(); }
void lesstif_styles_update_values () { if (!style_dialog) { lesstif_update_status_line (); return; } unit = Settings.grid_unit; ustr = XmStringCreateLocalized ((char *)Settings.grid_unit->suffix); update_values (); }
static void page_switched(NoiseSynthControls *controls, G_GNUC_UNUSED GtkNotebookPage *page, gint pagenum) { if (controls->in_init) return; controls->args->active_page = pagenum; if (pagenum == PAGE_GENERATOR) update_values(controls); }
/** * \brief Fill the list of fields. */ void bf::item_field_edit::fill_fields() { DeleteAllItems(); if ( empty() ) return; enumerate_properties(); update_values(); if ( m_last_selected_field != wxNOT_FOUND ) if ( m_last_selected_field < GetItemCount() ) { Select(m_last_selected_field); EnsureVisible(m_last_selected_field); } } // item_field_edit::fill_fields()
static gboolean nle_object_commit_func (NleObject * object, gboolean recurse) { GST_DEBUG_OBJECT (object, "Commiting object changed"); if (object->commit_needed == FALSE) { GST_INFO_OBJECT (object, "No changes to commit"); return FALSE; } update_values (object); GST_DEBUG_OBJECT (object, "Done commiting"); return TRUE; }
/** * \brief Toggle the value of a boolean field. * \param f The type of the field we are editing. */ void bf::item_field_edit::toggle_boolean_field_value( const type_field& f ) { CLAW_PRECOND(!f.is_list()); CLAW_PRECOND(f.get_field_type() == type_field::boolean_field_type); bool_type v; if ( !get_common_value(f, v) ) v.set_value(true); else v.set_value(!v.get_value()); set_field_value_event<bool_type> event ( f.get_name(), v, set_field_value_event<bool_type>::set_field_value_event_type, GetId() ); event.SetEventObject(this); if( ProcessEvent(event) ) update_values(); } // item_field_edit::toggle_boolean_field_value()
void *Worker(void *arg) { int row = 0; while (row < size) { row = get_new_row(); if (row >= size) break; int total, i, j, first, last, max, maxi, maxj, min, mini, minj; #ifdef DEBUG printf("worker %d (pthread id %d) calcultaion row %d of size: %d\n", pthread_self(), pthread_self(), row, size); #endif /* determine first and last rows of my strip */ i = row; /* sum values in my strip */ total = 0; max = -1000; maxi = 0; maxj = 0; min = 1000; mini = 0; minj = 0; for (j = 0; j < size; j++) { if (matrix[i][j] > max) { max = matrix[i][j]; maxi = i; maxj = j; } if (matrix[i][j] < min) { min = matrix[i][j]; mini = i; minj = j; } total += matrix[i][j]; } update_values(total, max, maxi, maxj, min, mini, minj); } }
/** * \brief Event sent when the user activates an item. * \param event The event. */ void bf::item_field_edit::on_item_activated( wxListEvent& event ) { std::string name; if ( get_field_name(event.GetIndex(), name) ) create_field_editor( name ); else { if ( m_hidden.find(name) == m_hidden.end() ) m_hidden.insert(name); else m_hidden.erase(name); DeleteAllItems(); enumerate_properties(); update_values(); if ( event.GetIndex() < GetItemCount() ) Select( event.GetIndex() ); } } // item_field_edit::on_item_activated()
/// The set builtin creates, updates, and erases (removes, deletes) variables. int builtin_set(parser_t &parser, io_streams_t &streams, wchar_t **argv) { wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); // Flags to set the work mode. int local = 0, global = 0, exportv = 0; int erase = 0, list = 0, unexport = 0; int universal = 0, query = 0; bool shorten_ok = true; bool preserve_failure_exit_status = true; const int incoming_exit_status = proc_get_last_status(); // Variables used for performing the actual work. wchar_t *dest = NULL; int retcode = STATUS_CMD_OK; int scope; int slice = 0; // Variables used for parsing the argument list. This command is atypical in using the "+" // (REQUIRE_ORDER) option for flag parsing. This is not typical of most fish commands. It means // we stop scanning for flags when the first non-flag argument is seen. static const wchar_t *short_options = L"+LUeghlnqux"; static const struct woption long_options[] = {{L"export", no_argument, NULL, 'x'}, {L"global", no_argument, NULL, 'g'}, {L"local", no_argument, NULL, 'l'}, {L"erase", no_argument, NULL, 'e'}, {L"names", no_argument, NULL, 'n'}, {L"unexport", no_argument, NULL, 'u'}, {L"universal", no_argument, NULL, 'U'}, {L"long", no_argument, NULL, 'L'}, {L"query", no_argument, NULL, 'q'}, {L"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}}; // Parse options to obtain the requested operation and the modifiers. int opt; wgetopter_t w; while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { switch (opt) { case 'e': { erase = 1; preserve_failure_exit_status = false; break; } case 'n': { list = 1; preserve_failure_exit_status = false; break; } case 'x': { exportv = 1; break; } case 'l': { local = 1; break; } case 'g': { global = 1; break; } case 'u': { unexport = 1; break; } case 'U': { universal = 1; break; } case 'L': { shorten_ok = false; break; } case 'q': { query = 1; preserve_failure_exit_status = false; break; } case 'h': { builtin_print_help(parser, streams, cmd, streams.out); return STATUS_CMD_OK; } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } default: { DIE("unexpected retval from wgetopt_long"); break; } } } // Ok, all arguments have been parsed, let's validate them. If we are checking the existance of // a variable (-q) we can not also specify scope. if (query && (erase || list)) { streams.err.append_format(BUILTIN_ERR_COMBO, cmd); builtin_print_help(parser, streams, cmd, streams.err); return STATUS_INVALID_ARGS; } // We can't both list and erase variables. if (erase && list) { streams.err.append_format(BUILTIN_ERR_COMBO, cmd); builtin_print_help(parser, streams, cmd, streams.err); return STATUS_INVALID_ARGS; } // Variables can only have one scope. if (local + global + universal > 1) { streams.err.append_format(BUILTIN_ERR_GLOCAL, cmd); builtin_print_help(parser, streams, cmd, streams.err); return STATUS_INVALID_ARGS; } // Variables can only have one export status. if (exportv && unexport) { streams.err.append_format(BUILTIN_ERR_EXPUNEXP, argv[0]); builtin_print_help(parser, streams, cmd, streams.err); return STATUS_INVALID_ARGS; } // Calculate the scope value for variable assignement. scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (exportv ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL : 0) | ENV_USER; if (query) { // Query mode. Return the number of variables that do not exist out of the specified // variables. int i; for (i = w.woptind; i < argc; i++) { wchar_t *arg = argv[i]; int slice = 0; dest = wcsdup(arg); assert(dest); if (wcschr(dest, L'[')) { slice = 1; *wcschr(dest, L'[') = 0; } if (slice) { std::vector<long> indexes; wcstring_list_t result; size_t j; env_var_t dest_str = env_get_string(dest, scope); if (!dest_str.missing()) tokenize_variable_array(dest_str, result); if (!parse_index(indexes, arg, dest, result.size(), streams)) { builtin_print_help(parser, streams, cmd, streams.err); retcode = 1; break; } for (j = 0; j < indexes.size(); j++) { long idx = indexes[j]; if (idx < 1 || (size_t)idx > result.size()) { retcode++; } } } else { if (!env_exist(arg, scope)) { retcode++; } } free(dest); } return retcode; } if (list) { // Maybe we should issue an error if there are any other arguments? print_variables(0, 0, shorten_ok, scope, streams); return STATUS_CMD_OK; } if (w.woptind == argc) { // Print values of variables. if (erase) { streams.err.append_format(_(L"%ls: Erase needs a variable name\n"), cmd); builtin_print_help(parser, streams, cmd, streams.err); retcode = STATUS_INVALID_ARGS; } else { print_variables(1, 1, shorten_ok, scope, streams); } return retcode; } dest = wcsdup(argv[w.woptind]); assert(dest); if (wcschr(dest, L'[')) { slice = 1; *wcschr(dest, L'[') = 0; } if (!valid_var_name(dest)) { streams.err.append_format(BUILTIN_ERR_VARNAME, cmd, dest); builtin_print_help(parser, streams, argv[0], streams.err); return STATUS_INVALID_ARGS; } // Set assignment can work in two modes, either using slices or using the whole array. We detect // which mode is used here. if (slice) { // Slice mode. std::vector<long> indexes; wcstring_list_t result; const env_var_t dest_str = env_get_string(dest, scope); if (!dest_str.missing()) { tokenize_variable_array(dest_str, result); } else if (erase) { retcode = 1; } if (!retcode) { for (; w.woptind < argc; w.woptind++) { if (!parse_index(indexes, argv[w.woptind], dest, result.size(), streams)) { builtin_print_help(parser, streams, argv[0], streams.err); retcode = 1; break; } size_t idx_count = indexes.size(); size_t val_count = argc - w.woptind - 1; if (!erase) { if (val_count < idx_count) { streams.err.append_format(_(BUILTIN_SET_ARG_COUNT), argv[0]); builtin_print_help(parser, streams, argv[0], streams.err); retcode = 1; break; } if (val_count == idx_count) { w.woptind++; break; } } } } if (!retcode) { // Slice indexes have been calculated, do the actual work. if (erase) { erase_values(result, indexes); my_env_set(dest, result, scope, streams); } else { wcstring_list_t value; while (w.woptind < argc) { value.push_back(argv[w.woptind++]); } if (update_values(result, indexes, value)) { streams.err.append_format(L"%ls: ", argv[0]); streams.err.append_format(ARRAY_BOUNDS_ERR); streams.err.push_back(L'\n'); } my_env_set(dest, result, scope, streams); } } } else { w.woptind++; // No slicing. if (erase) { if (w.woptind != argc) { streams.err.append_format(_(L"%ls: Values cannot be specfied with erase\n"), argv[0]); builtin_print_help(parser, streams, argv[0], streams.err); retcode = 1; } else { retcode = env_remove(dest, scope); } } else { wcstring_list_t val; for (int i = w.woptind; i < argc; i++) val.push_back(argv[i]); retcode = my_env_set(dest, val, scope, streams); } } // Check if we are setting variables above the effective scope. See // https://github.com/fish-shell/fish-shell/issues/806 env_var_t global_dest = env_get_string(dest, ENV_GLOBAL); if (universal && !global_dest.missing()) { streams.err.append_format( _(L"%ls: Warning: universal scope selected, but a global variable '%ls' exists.\n"), L"set", dest); } free(dest); if (retcode == STATUS_CMD_OK && preserve_failure_exit_status) retcode = incoming_exit_status; return retcode; }
static gint dialog (gint32 image_ID, GimpDrawable *drawable) { GtkWidget *dlg; GtkWidget *main_vbox; GtkWidget *vbox; GtkSizeGroup *group; GtkWidget *label; GtkWidget *preview; GtkWidget *button; GtkWidget *width; GtkWidget *space; GtkWidget *offset; GtkWidget *chain_button; GtkWidget *table; GimpUnit unit; gdouble xres; gdouble yres; gboolean run; g_return_val_if_fail (main_dialog == NULL, FALSE); gimp_ui_init (PLUG_IN_BINARY, TRUE); main_dialog = dlg = gimp_dialog_new (_("Grid"), PLUG_IN_ROLE, NULL, 0, gimp_standard_help_func, PLUG_IN_PROC, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dlg), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gimp_window_set_transient (GTK_WINDOW (dlg)); /* Get the image resolution and unit */ gimp_image_get_resolution (image_ID, &xres, &yres); unit = gimp_image_get_unit (image_ID); main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), main_vbox, TRUE, TRUE, 0); gtk_widget_show (main_vbox); preview = gimp_drawable_preview_new (drawable, NULL); gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0); gtk_widget_show (preview); g_signal_connect (preview, "invalidated", G_CALLBACK (update_preview), drawable); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0); gtk_widget_show (vbox); /* The width entries */ width = gimp_size_entry_new (3, /* number_of_fields */ unit, /* unit */ "%a", /* unit_format */ TRUE, /* menu_show_pixels */ TRUE, /* menu_show_percent */ FALSE, /* show_refval */ SPIN_BUTTON_WIDTH, /* spinbutton_usize */ GIMP_SIZE_ENTRY_UPDATE_SIZE); /* update_policy */ gtk_box_pack_start (GTK_BOX (vbox), width, FALSE, FALSE, 0); gtk_widget_show (width); /* set the unit back to pixels, since most times we will want pixels */ gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (width), GIMP_UNIT_PIXEL); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 0, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 1, yres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (width), 2, xres, TRUE); /* set the size (in pixels) that will be treated as 0% and 100% */ gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (width), 2, 0.0, drawable->width); /* set upper and lower limits (in pixels) */ gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 0, 0.0, drawable->height); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 1, 0.0, drawable->width); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (width), 2, 0.0, MAX (drawable->width, drawable->height)); gtk_table_set_row_spacing (GTK_TABLE (width), 0, 6); gtk_table_set_col_spacings (GTK_TABLE (width), 6); gtk_table_set_col_spacing (GTK_TABLE (width), 2, 12); /* initialize the values */ gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (width), 0, grid_cfg.hwidth); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (width), 1, grid_cfg.vwidth); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (width), 2, grid_cfg.iwidth); /* attach labels */ gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Horizontal\nLines"), 0, 1, 0.0); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Vertical\nLines"), 0, 2, 0.0); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Intersection"), 0, 3, 0.0); label = gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (width), _("Width:"), 1, 0, 0.0); group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); gtk_size_group_add_widget (group, label); g_object_unref (group); /* put a chain_button under the size_entries */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (grid_cfg.hwidth == grid_cfg.vwidth) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (width), chain_button, 1, 3, 2, 3); gtk_widget_show (chain_button); /* connect to the 'value-changed' signal because we have to take care * of keeping the entries in sync when the chainbutton is active */ g_signal_connect (width, "value-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect_swapped (width, "value-changed", G_CALLBACK (gimp_preview_invalidate), preview); /* The spacing entries */ space = gimp_size_entry_new (3, /* number_of_fields */ unit, /* unit */ "%a", /* unit_format */ TRUE, /* menu_show_pixels */ TRUE, /* menu_show_percent */ FALSE, /* show_refval */ SPIN_BUTTON_WIDTH, /* spinbutton_usize */ GIMP_SIZE_ENTRY_UPDATE_SIZE); /* update_policy */ gtk_box_pack_start (GTK_BOX (vbox), space, FALSE, FALSE, 0); gtk_widget_show (space); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (space), GIMP_UNIT_PIXEL); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 0, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 1, yres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (space), 2, xres, TRUE); /* set the size (in pixels) that will be treated as 0% and 100% */ gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (space), 2, 0.0, drawable->width); /* set upper and lower limits (in pixels) */ gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 0, 1.0, drawable->height); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 1, 1.0, drawable->width); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (space), 2, 0.0, MAX (drawable->width, drawable->height)); gtk_table_set_col_spacings (GTK_TABLE (space), 6); gtk_table_set_col_spacing (GTK_TABLE (space), 2, 12); /* initialize the values */ gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (space), 0, grid_cfg.hspace); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (space), 1, grid_cfg.vspace); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (space), 2, grid_cfg.ispace); /* attach labels */ label = gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (space), _("Spacing:"), 1, 0, 0.0); gtk_size_group_add_widget (group, label); /* put a chain_button under the spacing_entries */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (grid_cfg.hspace == grid_cfg.vspace) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (space), chain_button, 1, 3, 2, 3); gtk_widget_show (chain_button); /* connect to the 'value-changed' and "unit-changed" signals because * we have to take care of keeping the entries in sync when the * chainbutton is active */ g_signal_connect (space, "value-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect (space, "unit-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect_swapped (space, "value-changed", G_CALLBACK (gimp_preview_invalidate), preview); /* The offset entries */ offset = gimp_size_entry_new (3, /* number_of_fields */ unit, /* unit */ "%a", /* unit_format */ TRUE, /* menu_show_pixels */ TRUE, /* menu_show_percent */ FALSE, /* show_refval */ SPIN_BUTTON_WIDTH, /* spinbutton_usize */ GIMP_SIZE_ENTRY_UPDATE_SIZE); /* update_policy */ gtk_box_pack_start (GTK_BOX (vbox), offset, FALSE, FALSE, 0); gtk_widget_show (offset); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (offset), GIMP_UNIT_PIXEL); /* set the resolution to the image resolution */ gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 0, xres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 1, yres, TRUE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (offset), 2, xres, TRUE); /* set the size (in pixels) that will be treated as 0% and 100% */ gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 0, 0.0, drawable->height); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 1, 0.0, drawable->width); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (offset), 2, 0.0, drawable->width); /* set upper and lower limits (in pixels) */ gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 0, 0.0, drawable->height); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 1, 0.0, drawable->width); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (offset), 2, 0.0, MAX (drawable->width, drawable->height)); gtk_table_set_col_spacings (GTK_TABLE (offset), 6); gtk_table_set_col_spacing (GTK_TABLE (offset), 2, 12); /* initialize the values */ gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (offset), 0, grid_cfg.hoffset); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (offset), 1, grid_cfg.voffset); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (offset), 2, grid_cfg.ioffset); /* attach labels */ label = gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (offset), _("Offset:"), 1, 0, 0.0); gtk_size_group_add_widget (group, label); /* this is a weird hack: we put a table into the offset table */ table = gtk_table_new (3, 3, FALSE); gtk_table_attach_defaults (GTK_TABLE (offset), table, 1, 4, 2, 3); gtk_table_set_row_spacing (GTK_TABLE (table), 0, 10); gtk_table_set_col_spacing (GTK_TABLE (table), 1, 12); /* put a chain_button under the offset_entries */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (grid_cfg.hoffset == grid_cfg.voffset) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), chain_button, 0, 2, 0, 1); gtk_widget_show (chain_button); /* connect to the 'value-changed' and "unit-changed" signals because * we have to take care of keeping the entries in sync when the * chainbutton is active */ g_signal_connect (offset, "value-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect (offset, "unit-changed", G_CALLBACK (entry_callback), chain_button); g_signal_connect_swapped (offset, "value-changed", G_CALLBACK (gimp_preview_invalidate), preview); /* put a chain_button under the color_buttons */ chain_button = gimp_chain_button_new (GIMP_CHAIN_BOTTOM); if (gimp_rgba_distance (&grid_cfg.hcolor, &grid_cfg.vcolor) < 0.0001) gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), chain_button, 0, 2, 2, 3); gtk_widget_show (chain_button); /* attach color selectors */ hcolor_button = gimp_color_button_new (_("Horizontal Color"), COLOR_BUTTON_WIDTH, 16, &grid_cfg.hcolor, GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_button_set_update (GIMP_COLOR_BUTTON (hcolor_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), hcolor_button, 0, 1, 1, 2); gtk_widget_show (hcolor_button); g_signal_connect (hcolor_button, "color-changed", G_CALLBACK (gimp_color_button_get_color), &grid_cfg.hcolor); g_signal_connect (hcolor_button, "color-changed", G_CALLBACK (color_callback), chain_button); g_signal_connect_swapped (hcolor_button, "color-changed", G_CALLBACK (gimp_preview_invalidate), preview); vcolor_button = gimp_color_button_new (_("Vertical Color"), COLOR_BUTTON_WIDTH, 16, &grid_cfg.vcolor, GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_button_set_update (GIMP_COLOR_BUTTON (vcolor_button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), vcolor_button, 1, 2, 1, 2); gtk_widget_show (vcolor_button); g_signal_connect (vcolor_button, "color-changed", G_CALLBACK (gimp_color_button_get_color), &grid_cfg.vcolor); g_signal_connect (vcolor_button, "color-changed", G_CALLBACK (color_callback), chain_button); g_signal_connect_swapped (vcolor_button, "color-changed", G_CALLBACK (gimp_preview_invalidate), preview); button = gimp_color_button_new (_("Intersection Color"), COLOR_BUTTON_WIDTH, 16, &grid_cfg.icolor, GIMP_COLOR_AREA_SMALL_CHECKS); gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE); gtk_table_attach_defaults (GTK_TABLE (table), button, 2, 3, 1, 2); gtk_widget_show (button); g_signal_connect (button, "color-changed", G_CALLBACK (gimp_color_button_get_color), &grid_cfg.icolor); g_signal_connect_swapped (button, "color-changed", G_CALLBACK (gimp_preview_invalidate), preview); gtk_widget_show (table); gtk_widget_show (dlg); g_object_set_data (G_OBJECT (dlg), "width", width); g_object_set_data (G_OBJECT (dlg), "space", space); g_object_set_data (G_OBJECT (dlg), "offset", offset); run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK); if (run) update_values (); gtk_widget_destroy (dlg); return run; }
static int AdjustStyle (int argc, char **argv, Coord x, Coord y) { if (!mainwind) return 1; if (style_dialog == 0) { int i; unit = Settings.grid_unit; ustr = XmStringCreateLocalized ((char *)unit->suffix); n = 0; stdarg (XmNautoUnmanage, False); stdarg (XmNtitle, "Route Styles"); style_dialog = XmCreateFormDialog (mainwind, "style", args, n); n = 0; stdarg (XmNtopAttachment, XmATTACH_FORM); stdarg (XmNleftAttachment, XmATTACH_FORM); stdarg (XmNrightAttachment, XmATTACH_FORM); value_form = XmCreateForm (style_dialog, "values", args, n); XtManageChild (value_form); n = 0; stdarg (XmNtopAttachment, XmATTACH_FORM); stdarg (XmNrightAttachment, XmATTACH_FORM); stdarg (XmNbottomAttachment, XmATTACH_FORM); stdarg (XmNfractionBase, 4); stdarg (XmNresizePolicy, XmRESIZE_GROW); units_form = XmCreateForm (value_form, "units", args, n); XtManageChild (units_form); n = 0; stdarg (XmNtopAttachment, XmATTACH_FORM); stdarg (XmNbottomAttachment, XmATTACH_FORM); stdarg (XmNleftAttachment, XmATTACH_FORM); stdarg (XmNfractionBase, 4); value_labels = XmCreateForm (value_form, "values", args, n); XtManageChild (value_labels); n = 0; stdarg (XmNtopAttachment, XmATTACH_FORM); stdarg (XmNbottomAttachment, XmATTACH_FORM); stdarg (XmNrightAttachment, XmATTACH_WIDGET); stdarg (XmNrightWidget, units_form); stdarg (XmNleftAttachment, XmATTACH_WIDGET); stdarg (XmNleftWidget, value_labels); stdarg (XmNfractionBase, 4); value_texts = XmCreateForm (value_form, "values", args, n); XtManageChild (value_texts); for (i = 0; i < SSNUM; i++) { style_values[i] = style_value (i); name_hashes[i] = hash (PCB->RouteStyle[i].Name); } for (i = 0; i < NUM_STYLES; i++) style_pb[i] = style_button (i); update_values (); update_style_buttons (); } XtManageChild (style_dialog); return 0; }
static gboolean noise_synth_dialog(NoiseSynthArgs *args, GwyDimensionArgs *dimsargs, GwyContainer *data, GwyDataField *dfield_template, gint id) { GtkWidget *dialog, *table, *vbox, *hbox, *notebook, *label; NoiseSynthControls controls; GwyDataField *dfield; GwyPixmapLayer *layer; gboolean finished; gint response; gint row; gwy_clear(&controls, 1); controls.in_init = TRUE; controls.args = args; dialog = gtk_dialog_new_with_buttons(_("Random Noise"), NULL, 0, _("_Reset"), RESPONSE_RESET, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); gwy_help_add_to_proc_dialog(GTK_DIALOG(dialog), GWY_HELP_DEFAULT); controls.dialog = dialog; hbox = gtk_hbox_new(FALSE, 2); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 4); vbox = gtk_vbox_new(FALSE, 4); gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 4); controls.mydata = gwy_container_new(); dfield = gwy_data_field_new(PREVIEW_SIZE, PREVIEW_SIZE, dimsargs->measure*PREVIEW_SIZE, dimsargs->measure*PREVIEW_SIZE, TRUE); gwy_container_set_object_by_name(controls.mydata, "/0/data", dfield); controls.noise = gwy_data_field_new_alike(dfield, FALSE); if (dfield_template) { gwy_app_sync_data_items(data, controls.mydata, id, 0, FALSE, GWY_DATA_ITEM_PALETTE, 0); controls.surface = gwy_synth_surface_for_preview(dfield_template, PREVIEW_SIZE); controls.zscale = gwy_data_field_get_rms(dfield_template); } controls.view = gwy_data_view_new(controls.mydata); layer = gwy_layer_basic_new(); g_object_set(layer, "data-key", "/0/data", "gradient-key", "/0/base/palette", NULL); gwy_data_view_set_base_layer(GWY_DATA_VIEW(controls.view), layer); gtk_box_pack_start(GTK_BOX(vbox), controls.view, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), gwy_synth_instant_updates_new(&controls, &controls.update_now, &controls.update, &args->update), FALSE, FALSE, 0); g_signal_connect_swapped(controls.update_now, "clicked", G_CALLBACK(preview), &controls); gtk_box_pack_start(GTK_BOX(vbox), gwy_synth_random_seed_new(&controls, &controls.seed, &args->seed), FALSE, FALSE, 0); controls.randomize = gwy_synth_randomize_new(&args->randomize); gtk_box_pack_start(GTK_BOX(vbox), controls.randomize, FALSE, FALSE, 0); notebook = gtk_notebook_new(); gtk_box_pack_start(GTK_BOX(hbox), notebook, TRUE, TRUE, 4); g_signal_connect_swapped(notebook, "switch-page", G_CALLBACK(page_switched), &controls); controls.dims = gwy_dimensions_new(dimsargs, dfield_template); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), gwy_dimensions_get_widget(controls.dims), gtk_label_new(_("Dimensions"))); if (controls.dims->add) g_signal_connect_swapped(controls.dims->add, "toggled", G_CALLBACK(noise_synth_invalidate), &controls); table = gtk_table_new(6 + (dfield_template ? 1 : 0), 4, FALSE); controls.table = GTK_TABLE(table); gtk_table_set_row_spacings(controls.table, 2); gtk_table_set_col_spacings(controls.table, 6); gtk_container_set_border_width(GTK_CONTAINER(table), 4); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table, gtk_label_new(_("Generator"))); row = 0; controls.distribution = distribution_selector_new(&controls); gwy_table_attach_hscale(table, row, _("_Distribution:"), NULL, GTK_OBJECT(controls.distribution), GWY_HSCALE_WIDGET); row++; label = gtk_label_new(_("Direction:")); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row+1, GTK_FILL, 0, 0, 0); row++; controls.direction = gwy_radio_buttons_createl(G_CALLBACK(direction_type_changed), &controls, args->direction, _("S_ymmetrical"), NOISE_DIRECTION_BOTH, _("One-sided _positive"), NOISE_DIRECTION_UP, _("One-sided _negative"), NOISE_DIRECTION_DOWN, NULL); row = gwy_radio_buttons_attach_to_table(controls.direction, GTK_TABLE(table), 3, row); gtk_table_set_row_spacing(GTK_TABLE(table), row-1, 8); row = gwy_synth_attach_height(&controls, row, &controls.sigma, &args->sigma, _("_RMS:"), NULL, &controls.sigma_units); if (dfield_template) { controls.sigma_init = gtk_button_new_with_mnemonic(_("_Like Current Channel")); g_signal_connect_swapped(controls.sigma_init, "clicked", G_CALLBACK(sigma_init_clicked), &controls); gtk_table_attach(GTK_TABLE(table), controls.sigma_init, 1, 3, row, row+1, GTK_FILL, 0, 0, 0); row++; } gtk_widget_show_all(dialog); controls.in_init = FALSE; /* Must be done when widgets are shown, see GtkNotebook docs */ gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), args->active_page); update_values(&controls); noise_synth_invalidate(&controls); finished = FALSE; while (!finished) { response = gtk_dialog_run(GTK_DIALOG(dialog)); switch (response) { case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_DELETE_EVENT: case GTK_RESPONSE_OK: gtk_widget_destroy(dialog); case GTK_RESPONSE_NONE: finished = TRUE; break; case RESPONSE_RESET: { gboolean temp = args->update; gint temp2 = args->active_page; *args = noise_synth_defaults; args->active_page = temp2; args->update = temp; } controls.in_init = TRUE; update_controls(&controls, args); controls.in_init = FALSE; if (args->update) preview(&controls); break; default: g_assert_not_reached(); break; } } if (controls.sid) { g_source_remove(controls.sid); controls.sid = 0; } g_object_unref(controls.mydata); gwy_object_unref(controls.surface); gwy_object_unref(controls.noise); gwy_dimensions_free(controls.dims); return response == GTK_RESPONSE_OK; }
/** * \brief Refresh the values of the fields. */ void bf::item_field_edit::refresh() { update_values(); } // item_field_edit::refresh()
/** The set builtin. Creates, updates and erases environment variables and environemnt variable arrays. */ static int builtin_set( parser_t &parser, wchar_t **argv ) { /** Variables used for parsing the argument list */ static const struct woption long_options[] = { { L"export", no_argument, 0, 'x' } , { L"global", no_argument, 0, 'g' } , { L"local", no_argument, 0, 'l' } , { L"erase", no_argument, 0, 'e' } , { L"names", no_argument, 0, 'n' } , { L"unexport", no_argument, 0, 'u' } , { L"universal", no_argument, 0, 'U' } , { L"long", no_argument, 0, 'L' } , { L"query", no_argument, 0, 'q' } , { L"help", no_argument, 0, 'h' } , { 0, 0, 0, 0 } } ; const wchar_t *short_options = L"+xglenuULqh"; int argc = builtin_count_args(argv); /* Flags to set the work mode */ int local = 0, global = 0, exportv = 0; int erase = 0, list = 0, unexport=0; int universal = 0, query=0; bool shorten_ok = true; /* Variables used for performing the actual work */ wchar_t *dest = 0; int retcode=0; int scope; int slice=0; int i; wchar_t *bad_char; /* Parse options to obtain the requested operation and the modifiers */ woptind = 0; while (1) { int c = wgetopt_long(argc, argv, short_options, long_options, 0); if (c == -1) { break; } switch(c) { case 0: break; case 'e': erase = 1; break; case 'n': list = 1; break; case 'x': exportv = 1; break; case 'l': local = 1; break; case 'g': global = 1; break; case 'u': unexport = 1; break; case 'U': universal = 1; break; case 'L': shorten_ok = false; break; case 'q': query = 1; break; case 'h': builtin_print_help( parser, argv[0], stdout_buffer ); return 0; case '?': builtin_unknown_option( parser, argv[0], argv[woptind-1] ); return 1; default: break; } } /* Ok, all arguments have been parsed, let's validate them */ /* If we are checking the existance of a variable (-q) we can not also specify scope */ if( query && (erase || list) ) { append_format(stderr_buffer, BUILTIN_ERR_COMBO, argv[0] ); builtin_print_help( parser, argv[0], stderr_buffer ); return 1; } /* We can't both list and erase varaibles */ if( erase && list ) { append_format(stderr_buffer, BUILTIN_ERR_COMBO, argv[0] ); builtin_print_help( parser, argv[0], stderr_buffer ); return 1; } /* Variables can only have one scope */ if( local + global + universal > 1 ) { append_format(stderr_buffer, BUILTIN_ERR_GLOCAL, argv[0] ); builtin_print_help( parser, argv[0], stderr_buffer ); return 1; } /* Variables can only have one export status */ if( exportv && unexport ) { append_format(stderr_buffer, BUILTIN_ERR_EXPUNEXP, argv[0] ); builtin_print_help( parser, argv[0], stderr_buffer ); return 1; } /* Calculate the scope value for variable assignement */ scope = (local ? ENV_LOCAL : 0) | (global ? ENV_GLOBAL : 0) | (exportv ? ENV_EXPORT : 0) | (unexport ? ENV_UNEXPORT : 0) | (universal ? ENV_UNIVERSAL:0) | ENV_USER; if( query ) { /* Query mode. Return the number of variables that do not exist out of the specified variables. */ int i; for( i=woptind; i<argc; i++ ) { wchar_t *arg = argv[i]; int slice=0; if( !(dest = wcsdup(arg))) { DIE_MEM(); } if( wcschr( dest, L'[' ) ) { slice = 1; *wcschr( dest, L'[' )=0; } if( slice ) { std::vector<long> indexes; wcstring_list_t result; size_t j; env_var_t dest_str = env_get_string(dest); if (! dest_str.missing()) tokenize_variable_array( dest_str, result ); if( !parse_index( indexes, arg, dest, result.size() ) ) { builtin_print_help( parser, argv[0], stderr_buffer ); retcode = 1; break; } for( j=0; j < indexes.size() ; j++ ) { long idx = indexes[j]; if( idx < 1 || (size_t)idx > result.size() ) { retcode++; } } } else { if( !env_exist( arg, scope ) ) { retcode++; } } free( dest ); } return retcode; } if( list ) { /* Maybe we should issue an error if there are any other arguments? */ print_variables(0, 0, shorten_ok, scope); return 0; } if( woptind == argc ) { /* Print values of variables */ if( erase ) { append_format(stderr_buffer, _(L"%ls: Erase needs a variable name\n"), argv[0] ); builtin_print_help( parser, argv[0], stderr_buffer ); retcode = 1; } else { print_variables( 1, 1, shorten_ok, scope ); } return retcode; } if( !(dest = wcsdup(argv[woptind]))) { DIE_MEM(); } if( wcschr( dest, L'[' ) ) { slice = 1; *wcschr( dest, L'[' )=0; } if( !wcslen( dest ) ) { free( dest ); append_format(stderr_buffer, BUILTIN_ERR_VARNAME_ZERO, argv[0] ); builtin_print_help( parser, argv[0], stderr_buffer ); return 1; } if( (bad_char = wcsvarname( dest ) ) ) { append_format(stderr_buffer, BUILTIN_ERR_VARCHAR, argv[0], *bad_char ); builtin_print_help( parser, argv[0], stderr_buffer ); free( dest ); return 1; } if( slice && erase && (scope != ENV_USER) ) { free( dest ); append_format(stderr_buffer, _(L"%ls: Can not specify scope when erasing array slice\n"), argv[0] ); builtin_print_help( parser, argv[0], stderr_buffer ); return 1; } /* set assignment can work in two modes, either using slices or using the whole array. We detect which mode is used here. */ if( slice ) { /* Slice mode */ int idx_count, val_count; wcstring_list_t values; std::vector<long> indexes; wcstring_list_t result; const env_var_t dest_str = env_get_string(dest); if (! dest_str.missing()) tokenize_variable_array( dest_str, result ); for( ; woptind<argc; woptind++ ) { if( !parse_index( indexes, argv[woptind], dest, result.size() ) ) { builtin_print_help( parser, argv[0], stderr_buffer ); retcode = 1; break; } val_count = argc-woptind-1; idx_count = indexes.size(); if( !erase ) { if( val_count < idx_count ) { append_format(stderr_buffer, _(BUILTIN_SET_ARG_COUNT), argv[0] ); builtin_print_help( parser, argv[0], stderr_buffer ); retcode=1; break; } if( val_count == idx_count ) { woptind++; break; } } } if( !retcode ) { /* Slice indexes have been calculated, do the actual work */ if( erase ) { erase_values(result, indexes); my_env_set( dest, result, scope); } else { wcstring_list_t value; // al_init(&value); while( woptind < argc ) { value.push_back( argv[woptind++] ); } if( update_values( result, indexes, value ) ) { append_format(stderr_buffer, L"%ls: ", argv[0] ); append_format(stderr_buffer, ARRAY_BOUNDS_ERR ); stderr_buffer.push_back(L'\n'); } my_env_set(dest, result, scope); // al_destroy( &value ); } } // al_foreach( &result, &free ); // al_destroy( &result ); // al_destroy(&indexes); // al_destroy(&values); } else { woptind++; /* No slicing */ if( erase ) { if( woptind != argc ) { append_format(stderr_buffer, _(L"%ls: Values cannot be specfied with erase\n"), argv[0] ); builtin_print_help( parser, argv[0], stderr_buffer ); retcode=1; } else { retcode = env_remove( dest, scope ); } } else { wcstring_list_t val; for( i=woptind; i<argc; i++ ) val.push_back(argv[i]); retcode = my_env_set( dest, val, scope ); } } free( dest ); return retcode; }
void InputDeviceProvider_Win32Hid::update(void *preparse_data, void *report, int report_size) { update_buttons(preparse_data, report, report_size); update_values(preparse_data, report, report_size); }