void ui_container::mousePress(QMouseEvent *mouse) { for(int cou = elements.size() - 1; cou >=0; cou--) { auto i = elements[cou]; auto p = i->get_position(); QRect rect(p, i->size); if(rect.contains(mouse->pos())) { for(int j = cou; j < elements.size() - 1; j++) { std::swap(elements[j], elements[j + 1]); } i->mousePress(mouse); break; } } }
// get_location - updates the provided location with the latest calculated location // returns true on success (i.e. the EKF knows it's latest position), false on failure bool AP_AHRS_NavEKF::get_location(struct Location &loc) const { switch (ekf_type()) { case EKF_TYPE_NONE: // We are not using an EKF so no data return false; case EKF_TYPE2: default: return EKF2.getLLH(loc); case EKF_TYPE3: return EKF3.getLLH(loc); #if CONFIG_HAL_BOARD == HAL_BOARD_SITL case EKF_TYPE_SITL: return get_position(loc); #endif } }
void Dialog::save_geometry() { int y, x, w, h; get_position(x, y); get_size(w, h); // g_print ("write %d %d %d %d\n", x, y, w, h); if (x<0) x=0; if (y<0) y=0; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setInt(_prefs_path + "/x", x); prefs->setInt(_prefs_path + "/y", y); prefs->setInt(_prefs_path + "/w", w); prefs->setInt(_prefs_path + "/h", h); }
void tm_frame_rep::dialogue_start (string name, widget wid) { if (is_nil (dialogue_win)) { string lan= get_output_language (); if (lan == "russian") lan= "english"; name= translate (name, "english", lan); dialogue_wid= wid; dialogue_win= plain_window_widget (dialogue_wid, name); widget win= concrete_window () -> win; SI ox, oy, dx, dy, ex= 0, ey= 0; get_position (win, ox, oy); get_size (win, dx, dy); get_size (dialogue_win, ex, ey); ox += (dx - ex) >> 1; oy -= (dy - ey) >> 1; set_position (dialogue_win, ox, oy); set_visibility (dialogue_win, true); } }
void PointLight::shade( Ray3D& ray ) { if (!ray.intersection.none){ Colour I_a = _col_ambient; Colour I_d = _col_diffuse; Colour I_s = _col_specular; Colour r_a = ray.intersection.enteringMaterial->ambient; Colour r_d = ray.intersection.enteringMaterial->diffuse; Colour r_s = ray.intersection.enteringMaterial->specular; double alpha = ray.intersection.enteringMaterial->specular_exp; Colour r_g = Colour(); Colour I_spec = Colour(); Vector3D view = Vector3D(ray.origin - ray.intersection.point); Vector3D n = ray.intersection.normal; n.normalize(); Vector3D s = Vector3D(get_position() - ray.intersection.point); s.normalize(); Vector3D c = -ray.dir; c.normalize(); Vector3D m = (2 * (s.dot(n)) * n) - s; m.normalize(); Colour ambient = r_a * I_a; Colour diffuse = std::max(n.dot(s), 0.0) * r_d * I_d; Colour specular = pow(std::max(0.0, c.dot(m)), alpha) * r_s * I_s; ray.col = ambient + diffuse + specular; ray.col.clamp(); } }
/* Update Targets, Gains, and Max Vals */ void bot_behavior_update() { if (has_puck()) { positioning_LED(RED); x_target = x_goal; y_target = y_goal; max_theta = M_PI/2; theta_kd = 0.05; theta_kp = 1.6; max_duty_cycle = DUTY_CYCLE_PUCK; m_green(OFF); return; } if (!has_puck()) { positioning_LED(RED); float position_buffer[3]; get_position(position_buffer); if((puck_dist>800) && (fabs(position_buffer[0]-x_goal)<(fabs(x_puck-x_goal)))) { x_target = -x_goal; y_target = y_goal; } else { x_target = x_puck; y_target = y_puck; if (!x_puck && !y_puck) { positioning_LED(BLUE); } } max_theta = M_PI; theta_kd = 0; theta_kp = 2.2; max_duty_cycle = DUTY_CYCLE_SEEK; m_green(ON); return; } }
/* * Look up the fraction of values less than (or equal, if 'equal' argument * is true) a given const in a histogram of range bounds. */ static double calc_hist_selectivity_scalar(TypeCacheEntry *typcache, RangeBound *constbound, RangeBound *hist, int hist_nvalues, bool equal) { Selectivity selec; int index; /* * Find the histogram bin the given constant falls into. Estimate * selectivity as the number of preceding whole bins. */ index = rbound_bsearch(typcache, constbound, hist, hist_nvalues, equal); selec = (Selectivity) (Max(index, 0)) / (Selectivity) (hist_nvalues - 1); /* Adjust using linear interpolation within the bin */ if (index >= 0 && index < hist_nvalues - 1) selec += get_position(typcache, constbound, &hist[index], &hist[index + 1]) / (Selectivity) (hist_nvalues - 1); return selec; }
/** * Check to see whether there are any hazards within reasonable range in * vicinity of current heading. */ bool HazardWarningModule::is_known_relevant_hazards(Position &pos, Heading &hdng) { for (auto itr = _hazards.begin(); itr != _hazards.end(); ++itr) { //For each hazard, //Get the distance from current position to hazard position Position hazard_pos = itr->get_position(); Distance euclidean_dist = MathUtils::get_distance(pos, hazard_pos); if (euclidean_dist > HAZARD_DIST_THRESHOLD) continue; //get heading from current position to hazard position //If the heading is within threshold save Heading hazard_hdng; hazard_hdng.set_from_pts(pos, hazard_pos); double delta = std::abs(hdng.get_heading() - hazard_hdng.get_heading()); Heading delta_hdng(delta); if (delta_hdng < HAZARD_HEADING_THRESHOLD) return true; } return false; }
/// Finds the nearest star from a given position /// \param position The position from which the nearest star shall be found /// \return An iterator to the star or an end-vector if there are no stars. std::vector<star>::const_iterator get_nearest_star(const util::vector2& position) const { auto nearest_star = _deflectors.end(); util::scalar min_distance = std::numeric_limits<util::scalar>::max(); for(auto it = _deflectors.begin(); it != _deflectors.end(); ++it) { util::vector2 diff_vector = position; util::sub(diff_vector, it->get_position()); util::scalar dist = util::dot(diff_vector, diff_vector); if(dist < min_distance && dist != 0.0) { min_distance = dist; nearest_star = it; } } return nearest_star; }
void XFormNode::calc_matrix(long time) { Vector3 tmp_pos; Quaternion tmp_rot; Vector3 tmp_scaling; long t = (time - anim_start_time) * get_anim_speed(); tmp_pos = get_position(t); tmp_rot = get_rotation(t).normalized(); tmp_scaling = get_scaling(t); xform_mat.reset_identity(); xform_mat.translate(tmp_pos); xform_mat.rotate(tmp_rot); xform_mat.scale(Vector4(tmp_scaling)); xform_mat = local_mat * xform_mat; if(parent){ xform_mat = parent->xform_mat * xform_mat; } }
int get_direction(t_player *src, t_player *dest, t_orientation ori) { int x; int y; int ret; ret = 0; if (src && dest) { x = dest->pos->x - src->pos->x; y = dest->pos->y - src->pos->y; if (x != 0 && y != 0) { ret = get_position(x, y, abs(x), abs(y)); ret += 2 * ori; return (ret > 8 ? ret %= 8 : ret); } else return (0); } return (0); }
// ------------------------------------------------------- // artifact as it appears on the adventure map // ------------------------------------------------------- void t_adv_artifact::activate_trigger( t_army* army, t_adv_map_point const& point, t_direction direction, t_adventure_frame* frame ) { destroy(); // we should not be deleted by this, because the caller has a reference. if (!army->get_owner()->is_computer()) { army->add( m_artifact ); std::string text = m_artifact.get_pickup_text(); std::string name = m_artifact.get_name(); t_adventure_map* map = get_map(); t_adventure_map_window* map_window = frame->get_map_window(); t_level_map_point_2d location = get_position(); t_screen_point screen_point = get_screen_point( *map, *this, location ) - map_window->get_view_pos(); t_artifact_type type = m_artifact.get_icon(); t_bitmap_layer_ptr icon = get_icon( type ); //t_bitmap_layer_cache_window_ptr icon_window; t_counted_ptr<t_basic_dialog> dialog = new t_basic_dialog( frame ); dialog->add_ok_button(); //icon_window = new t_bitmap_layer_cache_window( icon, t_screen_point(0,0), dialog, false ); //icon_window->set_help_balloon_text( m_artifact.get_name() ); //icon_window->set_right_click_text( m_artifact.get_help_text() ); dialog->add_artifact( m_artifact, 1, true ); dialog->set_text( text ); //dialog->add_display_window( icon_window, name ); dialog->set_title( get_name() ); dialog->open( screen_point, true, k_align_bottom ); t_sound_cache music = get_music_playing(); stop_music(); get_dialog_sound( k_dialog_sound_treasure )->play( get_sound_volume() ); dialog->run_modal(); play_music( music ); } else ai_give_artifact_to_army( *army, m_artifact ); }
static Bool draw_main(ModeInfo *mi, rubikblocks_conf *cp) { int i; double x, y, z; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); get_position(cp->rot, &x, &y, &z, !cp->button_down); glTranslatef((x-0.5)*6, (y-0.5)*6, -20); /* Do it twice because we don't track the device's orientation. */ glRotatef( current_device_rotation(), 0, 0, 1); gltrackball_rotate(cp->trackball); glRotatef(-current_device_rotation(), 0, 0, 1); get_rotation(cp->rot, &x, &y, &z, !cp->button_down); glRotatef(x*360, 1, 0, 0); glRotatef(y*360, 0, 1, 0); glRotatef(z*360, 0, 0, 1); glScalef(size, size, size); if(cp->wire) glColor3f(0.7, 0.7, 0.7); if(!cp->pause) for(i = 0; i < 27; i++) if(cp->pieces[i].act) mult_quat(cp->qfram, cp->pieces[i].qr); for(i = 0; i < 27; i++) { glPushMatrix(); if(fabs(cp->pieces[i].qr[0]) < 1) glRotatef(360/M_PI*acos(cp->pieces[i].qr[0]), cp->pieces[i].qr[1], cp->pieces[i].qr[2], cp->pieces[i].qr[3]); glCallList(cp->list_base + i); glPopMatrix(); } if((cp->t += tspeed) > cp->tmax) finish(cp); return True; }
void set_val(char * x, int v){ int pos = get_position(x); if(var_names[pos] != NULL && strcmp(x, var_names[pos]) == 0){ var_vals[pos] = v; } else{ if(known_var < MAX_VAR){ int i; for(i=known_var; i>pos; i--){ var_names[i] = var_names[i-1]; var_vals[i] = var_vals[i-1]; } var_names[pos] = strdup(x); var_vals[pos] = v; known_var++; } else { fprintf(stderr, "Too many variables\n"); exit(1); } } }
void textbox::append_text(const std::string& text, bool auto_scroll, const SDL_Color& color) { if(text_image_.get() == NULL) { set_text(text, color); return; } //disallow adding multi-line text to a single-line text box if(wrap_ == false && std::find_if(text.begin(),text.end(),utils::isnewline) != text.end()) { return; } const bool is_at_bottom = get_position() == get_max_position(); const wide_string& wtext = utils::string_to_wstring(text); const surface new_text = add_text_line(wtext, color); surface new_surface = create_compatible_surface(text_image_,std::max<size_t>(text_image_->w,new_text->w),text_image_->h+new_text->h); SDL_SetAlpha(new_text.get(),0,0); SDL_SetAlpha(text_image_.get(),0,0); sdl_blit(text_image_,NULL,new_surface,NULL); SDL_Rect target = create_rect(0 , text_image_->h , new_text->w , new_text->h); sdl_blit(new_text,NULL,new_surface,&target); text_image_.assign(new_surface); text_.resize(text_.size() + wtext.size()); std::copy(wtext.begin(),wtext.end(),text_.end()-wtext.size()); set_dirty(true); update_text_cache(false); if(auto_scroll && is_at_bottom) scroll_to_bottom(); handle_text_changed(text_); }
bool graphic_bct(t_graphic *graphic, char *cmd) { uint x; uint y; bool success; char *answer; uint *res; if (!get_position(cmd, &x, &y)) return (error_type_sbp(graphic, cmd)); if (x >= gs_get_map_width() || y >= gs_get_map_height()) return (error_type_sbp(graphic, cmd)); res = g_server.world.cell[(x + (y * gs_get_map_width()))].res; if (asprintf(&answer, "bct %u %u %u %u %u %u %u %u %u", x, y, res[0], res[1], res[2], res[3], res[4], res[5], res[6]) == -1) { graphic_smg_KO(graphic); return (print_perror("fail to allocate new graphic message")); } success = client_write_to(graphic->client, answer); free(answer); return (success); }
void Ghost::search_path() { current_path_point = 0; if (ptr_pacman == nullptr) return; Game_Board & map = Game_Board::get_instance(); Vector_2D ghost_position = map.position_in_map(get_position()); Vector_2D pacman_position = map.position_in_map(ptr_pacman->get_position()); path_to_follow = ptr_find_path_algorithm->find_path(ghost_position, pacman_position, id); if (path_to_follow.empty()) return; path_to_follow.takeFirst(); max_path_size_to_follow = real(path_to_follow.size()) / path_size_proportion; }
static gboolean set_status(struct media_player *mp, DBusMessageIter *iter) { const char *value; if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING) return FALSE; dbus_message_iter_get_basic(iter, &value); DBG("Status=%s", value); if (g_strcmp0(mp->status, value) == 0) return TRUE; mp->position = get_position(mp); g_timer_start(mp->timer); g_free(mp->status); mp->status = g_strdup(value); avrcp_player_event(mp->player, AVRCP_EVENT_STATUS_CHANGED, mp->status); return TRUE; }
Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { Vector2 g = p_xform.xform(get_global_position()); Vector2 l = p_xform.xform(get_position() + p_local_ofs); Ref<InputEventMouseButton> mb; mb.instance(); mb->set_device(get_device()); mb->set_modifiers_from_event(this); mb->set_position(l); mb->set_global_position(g); mb->set_button_mask(get_button_mask()); mb->set_pressed(pressed); mb->set_doubleclick(doubleclick); mb->set_factor(factor); mb->set_button_index(button_index); return mb; }
Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { Vector2 g = p_xform.xform(get_global_position()); Vector2 l = p_xform.xform(get_position() + p_local_ofs); Vector2 r = p_xform.basis_xform(get_relative()); Vector2 s = p_xform.basis_xform(get_speed()); Ref<InputEventMouseMotion> mm; mm.instance(); mm->set_device(get_device()); mm->set_modifiers_from_event(this); mm->set_position(l); mm->set_global_position(g); mm->set_button_mask(get_button_mask()); mm->set_relative(r); mm->set_speed(s); return mm; }
/* * Adjusts the desired velocity for the circular fence. */ void AC_Avoid::adjust_velocity_circle(const float kP, const float accel_cmss, Vector2f &desired_vel) { // exit if circular fence is not enabled if ((_fence.get_enabled_fences() & AC_FENCE_TYPE_CIRCLE) == 0) { return; } // exit if the circular fence has already been breached if ((_fence.get_breaches() & AC_FENCE_TYPE_CIRCLE) != 0) { return; } // get position as a 2D offset in cm from ahrs home const Vector2f position_xy = get_position(); float speed = desired_vel.length(); // get the fence radius in cm const float fence_radius = _fence.get_radius() * 100.0f; // get the margin to the fence in cm const float margin = get_margin(); if (!is_zero(speed) && position_xy.length() <= fence_radius) { // Currently inside circular fence Vector2f stopping_point = position_xy + desired_vel*(get_stopping_distance(kP, accel_cmss, speed)/speed); float stopping_point_length = stopping_point.length(); if (stopping_point_length > fence_radius - margin) { // Unsafe desired velocity - will not be able to stop before fence breach // Project stopping point radially onto fence boundary // Adjusted velocity will point towards this projected point at a safe speed Vector2f target = stopping_point * ((fence_radius - margin) / stopping_point_length); Vector2f target_direction = target - position_xy; float distance_to_target = target_direction.length(); float max_speed = get_max_speed(kP, accel_cmss, distance_to_target); desired_vel = target_direction * (MIN(speed,max_speed) / distance_to_target); } } }
/* * Chybova funkce, VRACI SE * Zpusob zpracovani udava argument 'action' * Doporuceny format: * cast_prekladace: duvod * pr: * error("scanner: Nedostatek pameti pro lexem!\n"); */ void error(TErrEnum action, char *format, ...) { va_list arguments; Tgp_info info; static bool enable = true; /* Povol vypis. */ if (enable == false) return; info = get_position(GET); va_start(arguments, format); fprintf(stderr, "ifj06: Chyba: "); switch(action) { case RAW: fprintf(stderr, "\n"); break; case ROWONLY: fprintf(stderr, "Radek %d\n", info.row); break; case ROWLEX: fprintf(stderr, "Radek %d: Lexem %d\n", info.row, info.lexeme); break; default: fprintf(stderr, "Neznamy chybovy vystup\n"); break; } vfprintf(stderr, format, arguments); va_end(arguments); #ifndef ERROR_DEBUG enable = false; #endif return; }
void SearchNotesWidget::save_position() { int width; int height; EmbeddableWidgetHost *current_host = host(); if(!current_host || !current_host->running()) { return; } Glib::RefPtr<Gio::Settings> settings = Preferences::obj() .get_schema_settings(Preferences::SCHEMA_GNOTE); settings->set_int(Preferences::SEARCH_WINDOW_SPLITTER_POS, get_position()); Gtk::Window *window = dynamic_cast<Gtk::Window*>(current_host); if(!window || (window->get_window()->get_state() & Gdk::WINDOW_STATE_MAXIMIZED) != 0) { return; } window->get_size(width, height); settings->set_int(Preferences::SEARCH_WINDOW_WIDTH, width); settings->set_int(Preferences::SEARCH_WINDOW_HEIGHT, height); }
static void my_resize_panel(PANEL ** pans, int which, FillPanel myFill) { if (pans[which] != 0) { int code; int y0, x0; int y1, x1; WINDOW *win = panel_window(pans[which]); char also[80]; getbegyx(win, y0, x0); sprintf(also, " (start %d,%d)", y0, x0); wmove(stdscr, y0, x0); while ((code = get_position("Resize panel", also, which, &x1, &y1)) == 0) { ; } if (code > 0) { WINDOW *next = newwin(ABS(y1 - y0) + 1, ABS(x1 - x0) + 1, MIN(y0, y1), MIN(x0, x1)); if (next != 0) { keypad(next, TRUE); if (use_colors) { wbkgdset(next, (chtype) (COLOR_PAIR(which) | ' ')); } else if (!unboxed) { wbkgdset(next, A_BOLD | ' '); } replace_panel(pans[which], next); myFill(pans[which]); delwin(win); } } } }
GString * format_ipv (guint id, guint pos, guint val) { GString *buf = g_string_sized_new(1); GString *vec_buf = g_string_sized_new(1); XmlSettings *xml = get_xml_settings(id, pos); GString *val_buf; if (!xml) { g_warning("Failed to find xml settings for position %d id %d.", id, pos); g_string_printf(buf, "%s", "error"); return buf; } val_buf = format_value(xml, val); g_string_printf(vec_buf, "(%d, %d, %d)", pos, id, val); g_string_printf(buf, "%-16s %s: %s: %s", vec_buf->str, get_position(pos), xml->label, val_buf->str); g_string_free(vec_buf, TRUE); g_string_free(val_buf, TRUE); return buf; }
static void my_move_panel(PANEL ** pans, int which, bool continuous) { if (pans[which] != 0) { int code; int y0, x0; int y1, x1; WINDOW *win = panel_window(pans[which]); char also[80]; getbegyx(win, y0, x0); sprintf(also, " (start %d,%d)", y0, x0); wmove(stdscr, y0, x0); while ((code = get_position("Move panel", also, which, &x1, &y1)) == 0) { if (continuous) { move_panel(pans[which], y1, x1); pflush(); } } if (code > 0) { move_panel(pans[which], y1, x1); } } }
void text_x11(display_t *out, char *text, int n) { float x, y; char *tmp; XWindow *win; win = plot_window( CURRENT ); xwindow_font_load(win); tmp = fstrdup(text, n); tmp = encode(tmp); get_position(&x, &y); x = view_to_x11_x(x, win); y = view_to_x11_y(y, win); switch( win->font->type) { case XFONT_TYPE_SOFTWARE: softwaretext(out, text, n); break; case XFONT_TYPE_CORE: xwindow_draw_string_core(win, tmp, x, y); break; case XFONT_TYPE_XFT: xwindow_draw_string_xft(win, tmp, x, y); break; default: fprintf(stderr, "SAC: Unknown X11 Font Subsystem\n"); break; } free(tmp); tmp = NULL; }
static int render_row(HexView* prView, const int row) { ColorConfig* prPcolor = NULL; ColorConfig* prCcolor = NULL; CursorPos* prCursor = NULL; CursorPos* prPos = NULL; Dimension* prSize = NULL; SceUInt32 address = 0; if (prView == NULL) { return HEXVIEW_NULLPTR; } prPcolor = get_panelcolor(prView); prCcolor = get_cursorcolor(prView); prCursor = get_cursorpos(prView); prPos = get_position(prView); prSize = get_size(prView); pspDebugScreenSetXY(prPos->x, prPos->y + row); if (row == prCursor->y) { if (cursor_color(prView) < 0) { return HEXVIEW_FAILURE; } } else { if (panel_color(prView) < 0) { return HEXVIEW_FAILURE; } } address = row_address(prView, row); pspDebugScreenKprintf("0x%08X", address); pspDebugScreenSetBackColor(prPcolor->background); pspDebugScreenSetTextColor(prPcolor->text); return HEXVIEW_SUCCESS; }
void Ghost::update(const real & dt) { Vector_2D v = ptr_pacman->get_position() - get_position(); if (v.magnitude() < SCALE) { if (status == Attacking) Telegram_Sender::get_instance().send_global_message(this, Pacman_Was_Killed); else { Audio::get_instance().play_eat_ghost(); init(Vector_2D(1, 1), listener.old_speed); listener.old_speed = get_speed(); status = Running_Away; set_speed(50); path_to_follow.empty(); current_path_point = 0; max_path_size_to_follow = 0; } } Segment_Follower::update(dt); }
void move_list(t_win *win, t_ios *term, int x, int y) { char *buf; int select; t_wsize ws; int resize; if (tcsetattr(0, TCSADRAIN, term) == -1) leave_term(); buf = ft_memalloc(5); win->stop = 0; read(0, buf, 3); resize = reset_val(term, &ws, 0); if (resize != 0) { y = win->position / win->max_y; x = win->position % win->max_y; check_move(buf, &y, &x, win); select = check_buf(buf, win, win->position, term); get_position(win, select, &x, &y); print_arg(&(win->arg), win, win->position, find_space(win->arg)); } free(buf); }