void GraphNode::_notification(int p_what) { if (p_what==NOTIFICATION_DRAW) { Ref<StyleBox> sb; if (comment) { sb = get_stylebox( selected? "commentfocus" : "comment"); } else { sb = get_stylebox( selected ? "selectedframe" : "frame"); } sb=sb->duplicate(); sb->call("set_modulate",modulate); Ref<Texture> port =get_icon("port"); Ref<Texture> close =get_icon("close"); Ref<Texture> resizer =get_icon("resizer"); int close_offset = get_constant("close_offset"); Ref<Font> title_font = get_font("title_font"); int title_offset = get_constant("title_offset"); Color title_color = get_color("title_color"); Point2i icofs = -port->get_size()*0.5; int edgeofs=get_constant("port_offset"); icofs.y+=sb->get_margin(MARGIN_TOP); draw_style_box(sb,Rect2(Point2(),get_size())); switch(overlay) { case OVERLAY_DISABLED: { } break; case OVERLAY_BREAKPOINT: { draw_style_box(get_stylebox("breakpoint"),Rect2(Point2(),get_size())); } break; case OVERLAY_POSITION: { draw_style_box(get_stylebox("position"),Rect2(Point2(),get_size())); } break; } int w = get_size().width-sb->get_minimum_size().x; if (show_close) w-=close->get_width(); draw_string(title_font,Point2(sb->get_margin(MARGIN_LEFT),-title_font->get_height()+title_font->get_ascent()+title_offset),title,title_color,w); if (show_close) { Vector2 cpos = Point2(w+sb->get_margin(MARGIN_LEFT),-close->get_height()+close_offset); draw_texture(close,cpos); close_rect.pos=cpos; close_rect.size=close->get_size(); } else { close_rect=Rect2(); } for (Map<int,Slot>::Element *E=slot_info.front();E;E=E->next()) { if (E->key() < 0 || E->key()>=cache_y.size()) continue; if (!slot_info.has(E->key())) continue; const Slot &s=slot_info[E->key()]; //left if (s.enable_left) { Ref<Texture> p = port; if (s.custom_slot_left.is_valid()) { p=s.custom_slot_left; } p->draw(get_canvas_item(),icofs+Point2(edgeofs,cache_y[E->key()]),s.color_left); } if (s.enable_right) { Ref<Texture> p = port; if (s.custom_slot_right.is_valid()) { p=s.custom_slot_right; } p->draw(get_canvas_item(),icofs+Point2(get_size().x-edgeofs,cache_y[E->key()]),s.color_right); } } if (resizeable) { draw_texture(resizer,get_size()-resizer->get_size()); } } if (p_what==NOTIFICATION_SORT_CHILDREN) { _resort(); } }
Point2 SFAsset::GetPosition() { return Point2(bbox->centre->getX(), bbox->centre->getY()); }
void CollisionShape2DEditor::_canvas_draw() { if (!node) { return; } if (!node->get_shape().is_valid()) { return; } _get_current_shape_type(); if (shape_type == -1) { return; } Control *c = canvas_item_editor->get_viewport_control(); Matrix32 gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Ref<Texture> h = get_icon("EditorHandle","EditorIcons"); Vector2 size = h->get_size()*0.5; handles.clear(); switch (shape_type) { case CAPSULE_SHAPE: { Ref<CapsuleShape2D> shape = node->get_shape(); handles.resize(2); float radius = shape->get_radius(); float height = shape->get_height()/2; handles[0] = Point2(radius, -height); handles[1] = Point2(0,-(height + radius)); c->draw_texture(h, gt.xform(handles[0])-size); c->draw_texture(h, gt.xform(handles[1])-size); } break; case CIRCLE_SHAPE: { Ref<CircleShape2D> shape = node->get_shape(); handles.resize(1); handles[0] = Point2(shape->get_radius(),0); c->draw_texture(h, gt.xform(handles[0])-size); } break; case CONCAVE_POLYGON_SHAPE: { } break; case CONVEX_POLYGON_SHAPE: { } break; case LINE_SHAPE: { Ref<LineShape2D> shape = node->get_shape(); handles.resize(2); handles[0] = shape->get_normal() * shape->get_d(); handles[1] = shape->get_normal() * (shape->get_d() + 30.0); c->draw_texture(h,gt.xform(handles[0])-size); c->draw_texture(h,gt.xform(handles[1])-size); } break; case RAY_SHAPE: { Ref<RayShape2D> shape = node->get_shape(); handles.resize(1); handles[0] = Point2(0,shape->get_length()); c->draw_texture(h,gt.xform(handles[0])-size); } break; case RECTANGLE_SHAPE: { Ref<RectangleShape2D> shape = node->get_shape(); handles.resize(2); Vector2 ext = shape->get_extents(); handles[0] = Point2(ext.x,0); handles[1] = Point2(0,-ext.y); c->draw_texture(h,gt.xform(handles[0])-size); c->draw_texture(h,gt.xform(handles[1])-size); } break; case SEGMENT_SHAPE: { Ref<SegmentShape2D> shape = node->get_shape(); handles.resize(2); handles[0] = shape->get_a(); handles[1] = shape->get_b(); c->draw_texture(h, gt.xform(handles[0])-size); c->draw_texture(h, gt.xform(handles[1])-size); } break; } }
void FindReplaceDialog::_replace() { text_edit->begin_complex_operation(); if (is_replace_all_mode()) { //line as x so it gets priority in comparison, column as y Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column()); Point2i prev_match = Point2(-1, -1); bool selection_enabled = text_edit->is_selection_active(); Point2i selection_begin, selection_end; if (selection_enabled) { selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column()); selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column()); } int vsval = text_edit->get_v_scroll(); //int hsval = text_edit->get_h_scroll(); text_edit->cursor_set_line(0); text_edit->cursor_set_column(0); int rc = 0; while (_search()) { if (!text_edit->is_selection_active()) { //search selects break; } //replace area Point2i match_from(text_edit->get_selection_from_line(), text_edit->get_selection_from_column()); Point2i match_to(text_edit->get_selection_to_line(), text_edit->get_selection_to_column()); if (match_from < prev_match) break; //done prev_match = match_to; if (selection_enabled && is_replace_selection_only()) { if (match_from < selection_begin || match_to > selection_end) continue; //replace but adjust selection bounds text_edit->insert_text_at_cursor(get_replace_text()); if (match_to.x == selection_end.x) selection_end.y += get_replace_text().length() - get_search_text().length(); } else { //just replace text_edit->insert_text_at_cursor(get_replace_text()); } rc++; } //restore editor state (selection, cursor, scroll) text_edit->cursor_set_line(orig_cursor.x); text_edit->cursor_set_column(orig_cursor.y); if (selection_enabled && is_replace_selection_only()) { //reselect text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y); } else { text_edit->deselect(); } text_edit->set_v_scroll(vsval); //text_edit->set_h_scroll(hsval); error_label->set_text(vformat(TTR("Replaced %d occurrence(s)."), rc)); //hide(); } else { if (text_edit->get_selection_text() == get_search_text()) { text_edit->insert_text_at_cursor(get_replace_text()); } _search(); } text_edit->end_complex_operation(); }
void ParticleTracer::process(const WorkUnit *workUnit, WorkResult *workResult, const bool &stop) { const RangeWorkUnit *range = static_cast<const RangeWorkUnit *>(workUnit); MediumSamplingRecord mRec; Intersection its; ref<Sensor> sensor = m_scene->getSensor(); bool needsTimeSample = sensor->needsTimeSample(); PositionSamplingRecord pRec(sensor->getShutterOpen() + 0.5f * sensor->getShutterOpenTime()); Ray ray; m_sampler->generate(Point2i(0)); for (size_t index = range->getRangeStart(); index <= range->getRangeEnd() && !stop; ++index) { m_sampler->setSampleIndex(index); /* Sample an emission */ if (needsTimeSample) pRec.time = sensor->sampleTime(m_sampler->next1D()); const Emitter *emitter = NULL; const Medium *medium; Spectrum power; Ray ray; if (m_emissionEvents) { /* Sample the position and direction component separately to generate emission events */ power = m_scene->sampleEmitterPosition(pRec, m_sampler->next2D()); emitter = static_cast<const Emitter *>(pRec.object); medium = emitter->getMedium(); /* Forward the sampling event to the attached handler */ handleEmission(pRec, medium, power); DirectionSamplingRecord dRec; power *= emitter->sampleDirection(dRec, pRec, emitter->needsDirectionSample() ? m_sampler->next2D() : Point2(0.5f)); ray.setTime(pRec.time); ray.setOrigin(pRec.p); ray.setDirection(dRec.d); } else { /* Sample both components together, which is potentially faster / uses a better sampling strategy */ power = m_scene->sampleEmitterRay(ray, emitter, m_sampler->next2D(), m_sampler->next2D(), pRec.time); medium = emitter->getMedium(); handleNewParticle(); } int depth = 1, nullInteractions = 0; bool delta = false; Spectrum throughput(1.0f); // unitless path throughput (used for russian roulette) while (!throughput.isZero() && (depth <= m_maxDepth || m_maxDepth < 0)) { m_scene->rayIntersectAll(ray, its); /* ==================================================================== */ /* Radiative Transfer Equation sampling */ /* ==================================================================== */ if (medium && medium->sampleDistance(Ray(ray, 0, its.t), mRec, m_sampler)) { /* Sample the integral \int_x^y tau(x, x') [ \sigma_s \int_{S^2} \rho(\omega,\omega') L(x,\omega') d\omega' ] dx' */ throughput *= mRec.sigmaS * mRec.transmittance / mRec.pdfSuccess; /* Forward the medium scattering event to the attached handler */ handleMediumInteraction(depth, nullInteractions, delta, mRec, medium, -ray.d, throughput*power); PhaseFunctionSamplingRecord pRec(mRec, -ray.d, EImportance); throughput *= medium->getPhaseFunction()->sample(pRec, m_sampler); delta = false; ray = Ray(mRec.p, pRec.wo, ray.time); ray.mint = 0; } else if (its.t == std::numeric_limits<Float>::infinity()) { /* There is no surface in this direction */ break; } else { /* Sample tau(x, y) (Surface integral). This happens with probability mRec.pdfFailure Account for this and multiply by the proper per-color-channel transmittance. */ if (medium) throughput *= mRec.transmittance / mRec.pdfFailure; const BSDF *bsdf = its.getBSDF(); /* Forward the surface scattering event to the attached handler */ handleSurfaceInteraction(depth, nullInteractions, delta, its, medium, throughput*power); BSDFSamplingRecord bRec(its, m_sampler, EImportance); Spectrum bsdfWeight = bsdf->sample(bRec, m_sampler->next2D()); if (bsdfWeight.isZero()) break; /* Prevent light leaks due to the use of shading normals -- [Veach, p. 158] */ Vector wi = -ray.d, wo = its.toWorld(bRec.wo); Float wiDotGeoN = dot(its.geoFrame.n, wi), woDotGeoN = dot(its.geoFrame.n, wo); if (wiDotGeoN * Frame::cosTheta(bRec.wi) <= 0 || woDotGeoN * Frame::cosTheta(bRec.wo) <= 0) break; /* Keep track of the weight, medium and relative refractive index along the path */ throughput *= bsdfWeight; if (its.isMediumTransition()) medium = its.getTargetMedium(woDotGeoN); if (bRec.sampledType & BSDF::ENull) ++nullInteractions; else delta = bRec.sampledType & BSDF::EDelta; #if 0 /* This is somewhat unfortunate: for accuracy, we'd really want the correction factor below to match the path tracing interpretation of a scene with shading normals. However, this factor can become extremely large, which adds unacceptable variance to output renderings. So for now, it is disabled. The adjoint particle tracer and the photon mapping variants still use this factor for the last bounce -- just not for the intermediate ones, which introduces a small (though in practice not noticeable) amount of error. This is also what the implementation of SPPM by Toshiya Hachisuka does. Ultimately, we'll need better adjoint BSDF sampling strategies that incorporate these extra terms */ /* Adjoint BSDF for shading normals -- [Veach, p. 155] */ throughput *= std::abs( (Frame::cosTheta(bRec.wi) * woDotGeoN)/ (Frame::cosTheta(bRec.wo) * wiDotGeoN)); #endif ray.setOrigin(its.p); ray.setDirection(wo); ray.mint = Epsilon; } if (depth++ >= m_rrDepth) { /* Russian roulette: try to keep path weights equal to one, Stop with at least some probability to avoid getting stuck (e.g. due to total internal reflection) */ Float q = std::min(throughput.max(), (Float) 0.95f); if (m_sampler->next1D() >= q) break; throughput /= q; } } } }
Point2 operator-(const Point2 & p, const Vector2 & v) { return Point2(p.x - v.dx,p.y - v.dy); }
test_report benchmark_test_with_internal_configuration(std::string test_casename, const std::string function_name, int flag, int nVar){ std::ofstream report_file("tests_report_file.txt", std::ios::app); time_t start_time; time (&start_time); std::cout << "test case: " << test_casename << " starts with internal configuration" << std::endl; general_configuration internal_configuration_old("no_filename", 10, //1 - diversify 5, //2 - intensify 15, //3 - reduce 0.00, //4 - SS 0.5, //5 - SSRF 1, //6 - save step 3, //7 - sampling nVar, //8 - nVar 2, //9 - nObj 0, //10 loop limit 3000, //11 evaluations limit 0, //12 Improvements limit , number of consecutive improvements 4, //13 - number of regions 6, //14 - STM size "HV", // 15 "full", //16 -0.05, //17 - starting point 200, //18 300); //19 general_configuration internal_configuration("configuration.txt"); ObjFunction2 test_reference_point=ObjFunction2(2, 22.0); ObjFunction2 test_penalty_point=ObjFunction2(2,33333.0); Point2 test_lower_bound=Point2(nVar,0.0); test_lower_bound[0]=5.0; test_lower_bound[1]=1.0; test_lower_bound[2]=11.0; Point2 test_upper_bound=Point2(nVar,1.0); test_upper_bound[0]=11.0; test_upper_bound[1]=200.0; test_upper_bound[2]=29.0; Point2 test_starting_point=Point2(nVar,0.5); test_starting_point[0]=7.0; test_starting_point[1]=100.0; test_starting_point[2]=24.5; Point2 test_current_step=Point2(nVar,0.05); test_current_step[0]=0.1666666; test_current_step[1]=0.050251256; test_current_step[2]=0.055555556; Overall_Optimisation_Configuration_Settings myConf2(test_casename, internal_configuration, test_reference_point, test_penalty_point, test_lower_bound, test_upper_bound, test_starting_point, test_current_step); const unsigned int n_of_variables=myConf2.getExternalConfigurationFile().getVar(); const unsigned int n_of_objectives=myConf2.getExternalConfigurationFile().getObj(); objective_function_formulae obj_function(n_of_objectives); ObjectiveFunctionBasic<double> TS_ObjFunc(myConf2, obj_function); Container2 MTM(n_of_variables, n_of_objectives, "MTM","./memories"); Container2 IM(n_of_variables, n_of_objectives, "IM","./memories"); Container2 HISTORY(n_of_variables, n_of_objectives, "HISTORY","./memories"); STM_Container2 STM(myConf2.getExternalConfigurationFile().getStmSize(), n_of_variables, "STM", "./memories"); LTM_Container2Basic2<double> LTM( n_of_variables , myConf2.getExternalConfigurationFile().getRegions(), myConf2.get_lower_bound(), myConf2.get_upper_bound(),"LTM", "./memories"); std::cout << "Memories done!" << std::endl; TabuSearch TS(myConf2, flag, TS_ObjFunc, MTM, IM, HISTORY, STM, LTM); double hyper_volume_indicator=TS.search2(); time_t end; time (&end); double dif = difftime (end,start_time); std::cout << "end in " << dif<< "seconds" << std::endl; report_file << test_casename << "\t" << n_of_variables << "\t" << dif << " seconds " << __DATE__ << "\t" << __TIME__ << std::endl; report_file.close(); return test_report(myConf2.getCaseName(), TS.getDatumPnt(), hyper_volume_indicator) ; }
Point2 OSBB10::get_mouse_pos() const { return Point2(); }
void OSBB10::handle_screen_event(bps_event_t *event) { screen_event_t screen_event = screen_event_get_event(event); int screen_val; screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val); int pos[2]; switch (screen_val) { case SCREEN_EVENT_MTOUCH_TOUCH: case SCREEN_EVENT_MTOUCH_RELEASE: { screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_POSITION, pos); InputEvent ievent; ievent.type = InputEvent::SCREEN_TOUCH; ievent.ID = ++last_id; ievent.device = 0; ievent.screen_touch.pressed = (screen_val == SCREEN_EVENT_MTOUCH_TOUCH); ievent.screen_touch.x = pos[0]; ievent.screen_touch.y = pos[1]; Point2 mpos(ievent.screen_touch.x, ievent.screen_touch.y); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pos[0]); ievent.screen_touch.index = pos[0]; last_touch_x[pos[0]] = ievent.screen_touch.x; last_touch_y[pos[0]] = ievent.screen_touch.y; input->parse_input_event( ievent ); if (ievent.screen_touch.index == 0) { InputEvent ievent; ievent.type = InputEvent::MOUSE_BUTTON; ievent.ID = ++last_id; ievent.device = 0; ievent.mouse_button.pressed = (screen_val == SCREEN_EVENT_MTOUCH_TOUCH); ievent.mouse_button.button_index = BUTTON_LEFT; ievent.mouse_button.doubleclick = 0; ievent.mouse_button.x = ievent.mouse_button.global_x = mpos.x; ievent.mouse_button.y = ievent.mouse_button.global_y = mpos.y; input->parse_input_event( ievent ); }; } break; case SCREEN_EVENT_MTOUCH_MOVE: { screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_POSITION, pos); InputEvent ievent; ievent.type = InputEvent::SCREEN_DRAG; ievent.ID = ++last_id; ievent.device = 0; ievent.screen_drag.x = pos[0]; ievent.screen_drag.y = pos[1]; /* screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION, pos); ievent.screen_drag.relative_x = ievent.screen_drag.x - pos[0]; ievent.screen_drag.relative_y = ievent.screen_drag.y - pos[1]; */ screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pos[0]); ievent.screen_drag.index = pos[0]; ievent.screen_drag.relative_x = ievent.screen_drag.x - last_touch_x[ievent.screen_drag.index]; ievent.screen_drag.relative_y = ievent.screen_drag.y - last_touch_y[ievent.screen_drag.index]; last_touch_x[ievent.screen_drag.index] = ievent.screen_drag.x; last_touch_y[ievent.screen_drag.index] = ievent.screen_drag.y; Point2 mpos(ievent.screen_drag.x, ievent.screen_drag.y); Point2 mrel(ievent.screen_drag.relative_x, ievent.screen_drag.relative_y); input->parse_input_event( ievent ); if (ievent.screen_touch.index == 0) { InputEvent ievent; ievent.type = InputEvent::MOUSE_MOTION; ievent.ID = ++last_id; ievent.device = 0; ievent.mouse_motion.x = ievent.mouse_motion.global_x = mpos.x; ievent.mouse_motion.y = ievent.mouse_motion.global_y = mpos.y; input->set_mouse_pos(Point2(ievent.mouse_motion.x,ievent.mouse_motion.y)); ievent.mouse_motion.speed_x=input->get_last_mouse_speed().x; ievent.mouse_motion.speed_y=input->get_last_mouse_speed().y; ievent.mouse_motion.relative_x = mrel.x; ievent.mouse_motion.relative_y = mrel.y; ievent.mouse_motion.button_mask = 1; // pressed input->parse_input_event( ievent ); }; } break; case SCREEN_EVENT_KEYBOARD: { InputEvent ievent; ievent.type = InputEvent::KEY; ievent.ID = ++last_id; ievent.device = 0; int val = 0; screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SCAN, &val); ievent.key.scancode = val; screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &val); ievent.key.unicode = val; if (val == 61448) { ievent.key.scancode = KEY_BACKSPACE; ievent.key.unicode = KEY_BACKSPACE; }; if (val == 61453) { ievent.key.scancode = KEY_ENTER; ievent.key.unicode = KEY_ENTER; }; int flags; screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_FLAGS, &flags); ievent.key.pressed = flags & 1; // bit 1 is pressed apparently int mod; screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); input->parse_input_event( ievent ); } break; default: break; } };
void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { if (p_event->is_action("ui_down") && p_event->is_pressed()) { int search_from = mouse_over + 1; if (search_from >= items.size()) search_from = 0; for (int i = search_from; i < items.size(); i++) { if (i < 0 || i >= items.size()) continue; if (!items[i].separator && !items[i].disabled) { mouse_over = i; emit_signal("id_focused", i); update(); accept_event(); break; } } } else if (p_event->is_action("ui_up") && p_event->is_pressed()) { int search_from = mouse_over - 1; if (search_from < 0) search_from = items.size() - 1; for (int i = search_from; i >= 0; i--) { if (i < 0 || i >= items.size()) continue; if (!items[i].separator && !items[i].disabled) { mouse_over = i; emit_signal("id_focused", i); update(); accept_event(); break; } } } else if (p_event->is_action("ui_left") && p_event->is_pressed()) { Node *n = get_parent(); if (n && Object::cast_to<PopupMenu>(n)) { hide(); accept_event(); } } else if (p_event->is_action("ui_right") && p_event->is_pressed()) { if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator && items[mouse_over].submenu != "" && submenu_over != mouse_over) { _activate_submenu(mouse_over); accept_event(); } } else if (p_event->is_action("ui_accept") && p_event->is_pressed()) { if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator) { if (items[mouse_over].submenu != "" && submenu_over != mouse_over) { _activate_submenu(mouse_over); } else { activate_item(mouse_over); } accept_event(); } } Ref<InputEventMouseButton> b = p_event; if (b.is_valid()) { if (b->is_pressed()) return; int button_idx = b->get_button_index(); switch (button_idx) { case BUTTON_WHEEL_DOWN: { if (get_global_position().y + get_size().y > get_viewport_rect().size.y) { _scroll(-b->get_factor(), b->get_position()); } } break; case BUTTON_WHEEL_UP: { if (get_global_position().y < 0) { _scroll(b->get_factor(), b->get_position()); } } break; default: { // Allow activating item by releasing the LMB or any that was down when the popup appeared if (button_idx == BUTTON_LEFT || (initial_button_mask & (1 << (button_idx - 1)))) { bool was_during_grabbed_click = during_grabbed_click; during_grabbed_click = false; int over = _get_mouse_over(b->get_position()); if (invalidated_click) { invalidated_click = false; break; } if (over < 0) { if (!was_during_grabbed_click) { hide(); } break; //non-activable } if (items[over].separator || items[over].disabled) break; if (items[over].submenu != "") { _activate_submenu(over); return; } activate_item(over); } } } //update(); } Ref<InputEventMouseMotion> m = p_event; if (m.is_valid()) { if (invalidated_click) { moved += m->get_relative(); if (moved.length() > 4) invalidated_click = false; } for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) { if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E->get().has_point(m->get_position())) { call_deferred("hide"); return; } } int over = _get_mouse_over(m->get_position()); int id = (over < 0 || items[over].separator || items[over].disabled) ? -1 : (items[over].ID >= 0 ? items[over].ID : over); if (id < 0) { mouse_over = -1; update(); return; } if (items[over].submenu != "" && submenu_over != over) { submenu_over = over; submenu_timer->start(); } if (over != mouse_over) { mouse_over = over; update(); } } Ref<InputEventPanGesture> pan_gesture = p_event; if (pan_gesture.is_valid()) { if (get_global_position().y + get_size().y > get_viewport_rect().size.y || get_global_position().y < 0) { _scroll(-pan_gesture->get_delta().y, pan_gesture->get_position()); } } }
void PopupMenu::_notification(int p_what) { switch (p_what) { case NOTIFICATION_TRANSLATION_CHANGED: { for (int i = 0; i < items.size(); i++) { items[i].xl_text = tr(items[i].text); } minimum_size_changed(); update(); } break; case NOTIFICATION_DRAW: { RID ci = get_canvas_item(); Size2 size = get_size(); Ref<StyleBox> style = get_stylebox("panel"); Ref<StyleBox> hover = get_stylebox("hover"); Ref<Font> font = get_font("font"); // In Item::checkable_type enum order (less the non-checkable member) Ref<Texture> check[] = { get_icon("checked"), get_icon("radio_checked") }; Ref<Texture> uncheck[] = { get_icon("unchecked"), get_icon("radio_unchecked") }; Ref<Texture> submenu = get_icon("submenu"); Ref<StyleBox> separator = get_stylebox("separator"); style->draw(ci, Rect2(Point2(), get_size())); Point2 ofs = style->get_offset(); int vseparation = get_constant("vseparation"); int hseparation = get_constant("hseparation"); Color font_color = get_color("font_color"); Color font_color_disabled = get_color("font_color_disabled"); Color font_color_accel = get_color("font_color_accel"); Color font_color_hover = get_color("font_color_hover"); float font_h = font->get_height(); for (int i = 0; i < items.size(); i++) { if (i > 0) ofs.y += vseparation; Point2 item_ofs = ofs; float h; Size2 icon_size; item_ofs.x += items[i].h_ofs; if (!items[i].icon.is_null()) { icon_size = items[i].icon->get_size(); h = MAX(icon_size.height, font_h); } else { h = font_h; } if (i == mouse_over) { hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation / 2), Size2(get_size().width - style->get_minimum_size().width + hseparation * 2, h + vseparation))); } if (items[i].separator) { int sep_h = separator->get_center_size().height + separator->get_minimum_size().height; separator->draw(ci, Rect2(item_ofs + Point2(0, Math::floor((h - sep_h) / 2.0)), Size2(get_size().width - style->get_minimum_size().width, sep_h))); } if (items[i].checkable_type) { Texture *icon = (items[i].checked ? check[items[i].checkable_type - 1] : uncheck[items[i].checkable_type - 1]).ptr(); icon->draw(ci, item_ofs + Point2(0, Math::floor((h - icon->get_height()) / 2.0))); item_ofs.x += icon->get_width() + hseparation; } if (!items[i].icon.is_null()) { items[i].icon->draw(ci, item_ofs + Point2(0, Math::floor((h - icon_size.height) / 2.0))); item_ofs.x += items[i].icon->get_width(); item_ofs.x += hseparation; } if (items[i].submenu != "") { submenu->draw(ci, Point2(size.width - style->get_margin(MARGIN_RIGHT) - submenu->get_width(), item_ofs.y + Math::floor(h - submenu->get_height()) / 2)); } item_ofs.y += font->get_ascent(); String text = items[i].shortcut.is_valid() ? String(tr(items[i].shortcut->get_name())) : items[i].xl_text; if (!items[i].separator) { font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, items[i].disabled ? font_color_disabled : (i == mouse_over ? font_color_hover : font_color)); } if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) { //accelerator String text = _get_accel_text(i); item_ofs.x = size.width - style->get_margin(MARGIN_RIGHT) - font->get_string_size(text).width; font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, i == mouse_over ? font_color_hover : font_color_accel); } items[i]._ofs_cache = ofs.y; ofs.y += h; } } break; case NOTIFICATION_MOUSE_ENTER: { grab_focus(); } break; case NOTIFICATION_MOUSE_EXIT: { if (mouse_over >= 0 && (items[mouse_over].submenu == "" || submenu_over != -1)) { mouse_over = -1; update(); } } break; case NOTIFICATION_POST_POPUP: { initial_button_mask = Input::get_singleton()->get_mouse_button_mask(); during_grabbed_click = (bool)initial_button_mask; } break; case NOTIFICATION_POPUP_HIDE: { if (mouse_over >= 0) { mouse_over = -1; update(); } } break; } }
Texture2D::Texture2D(Stream *stream, InstanceManager *manager) : Texture(stream, manager) { m_uvOffset = Point2(stream); m_uvScale = Vector2(stream); }
void BaseButton::_input_event(InputEvent p_event) { if (status.disabled) // no interaction with disabled button return; switch(p_event.type) { case InputEvent::MOUSE_BUTTON: { const InputEventMouseButton &b=p_event.mouse_button; if ( status.disabled || b.button_index!=1 ) return; if (status.pressing_button) break; if (status.click_on_press) { if (b.pressed) { if (!toggle_mode) { //mouse press attempt status.press_attempt=true; status.pressing_inside=true; pressed(); if (get_script_instance()) { Variant::CallError ce; get_script_instance()->call(SceneStringNames::get_singleton()->_pressed,NULL,0,ce); } emit_signal("pressed"); } else { status.pressed=!status.pressed; pressed(); if (get_script_instance()) { Variant::CallError ce; get_script_instance()->call(SceneStringNames::get_singleton()->_pressed,NULL,0,ce); } emit_signal("pressed"); toggled(status.pressed); emit_signal("toggled",status.pressed); } } else { if (status.press_attempt && status.pressing_inside) { // released(); emit_signal("released"); } status.press_attempt=false; } update(); break; } if (b.pressed) { status.press_attempt=true; status.pressing_inside=true; } else { if (status.press_attempt &&status.pressing_inside) { if (!toggle_mode) { //mouse press attempt pressed(); if (get_script_instance()) { Variant::CallError ce; get_script_instance()->call(SceneStringNames::get_singleton()->_pressed,NULL,0,ce); } emit_signal("pressed"); } else { status.pressed=!status.pressed; pressed(); emit_signal("pressed"); toggled(status.pressed); emit_signal("toggled",status.pressed); if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_toggled,status.pressed); } } } status.press_attempt=false; } update(); } break; case InputEvent::MOUSE_MOTION: { if (status.press_attempt && status.pressing_button==0) { bool last_press_inside=status.pressing_inside; status.pressing_inside=has_point(Point2(p_event.mouse_motion.x,p_event.mouse_motion.y)); if (last_press_inside!=status.pressing_inside) update(); } } break; case InputEvent::ACTION: case InputEvent::JOYSTICK_BUTTON: case InputEvent::KEY: { if (p_event.is_echo()) { break; } if (status.disabled) { break; } if (status.press_attempt && status.pressing_button==0) { break; } if (p_event.is_action("ui_accept")) { if (p_event.is_pressed()) { status.pressing_button++; status.press_attempt=true; status.pressing_inside=true; } else if (status.press_attempt) { if (status.pressing_button) status.pressing_button--; if (status.pressing_button) break; status.press_attempt=false; status.pressing_inside=false; if (!toggle_mode) { //mouse press attempt pressed(); emit_signal("pressed"); } else { status.pressed=!status.pressed; pressed(); emit_signal("pressed"); toggled(status.pressed); if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_toggled,status.pressed); } emit_signal("toggled",status.pressed); } } accept_event(); update(); } } } }
ARCFAperture(Stream *stream, InstanceManager *manager) : Texture2D(stream, manager) { m_color0 = Spectrum(stream); m_color1 = Spectrum(stream); m_uvBar = Point2(stream); }
void BitmapFont::_bind_methods() { ClassDB::bind_method(_MD("create_from_fnt","path"),&BitmapFont::create_from_fnt); ClassDB::bind_method(_MD("set_height","px"),&BitmapFont::set_height); ClassDB::bind_method(_MD("set_ascent","px"),&BitmapFont::set_ascent); ClassDB::bind_method(_MD("add_kerning_pair","char_a","char_b","kerning"),&BitmapFont::add_kerning_pair); ClassDB::bind_method(_MD("get_kerning_pair","char_a","char_b"),&BitmapFont::get_kerning_pair); ClassDB::bind_method(_MD("add_texture","texture:Texture"),&BitmapFont::add_texture); ClassDB::bind_method(_MD("add_char","character","texture","rect","align","advance"),&BitmapFont::add_char,DEFVAL(Point2()),DEFVAL(-1)); ClassDB::bind_method(_MD("get_texture_count"),&BitmapFont::get_texture_count); ClassDB::bind_method(_MD("get_texture:Texture","idx"),&BitmapFont::get_texture); ClassDB::bind_method(_MD("get_char_size","char","next"),&BitmapFont::get_char_size,DEFVAL(0)); ClassDB::bind_method(_MD("set_distance_field_hint","enable"),&BitmapFont::set_distance_field_hint); ClassDB::bind_method(_MD("clear"),&BitmapFont::clear); ClassDB::bind_method(_MD("_set_chars"),&BitmapFont::_set_chars); ClassDB::bind_method(_MD("_get_chars"),&BitmapFont::_get_chars); ClassDB::bind_method(_MD("_set_kernings"),&BitmapFont::_set_kernings); ClassDB::bind_method(_MD("_get_kernings"),&BitmapFont::_get_kernings); ClassDB::bind_method(_MD("_set_textures"),&BitmapFont::_set_textures); ClassDB::bind_method(_MD("_get_textures"),&BitmapFont::_get_textures); ClassDB::bind_method(_MD("set_fallback","fallback"),&BitmapFont::set_fallback); ClassDB::bind_method(_MD("get_fallback"),&BitmapFont::get_fallback); ADD_PROPERTY( PropertyInfo( Variant::ARRAY, "textures", PROPERTY_HINT_NONE,"", PROPERTY_USAGE_NOEDITOR ), _SCS("_set_textures"), _SCS("_get_textures") ); ADD_PROPERTY( PropertyInfo( Variant::INT_ARRAY, "chars", PROPERTY_HINT_NONE,"", PROPERTY_USAGE_NOEDITOR ), _SCS("_set_chars"), _SCS("_get_chars") ); ADD_PROPERTY( PropertyInfo( Variant::INT_ARRAY, "kernings", PROPERTY_HINT_NONE,"", PROPERTY_USAGE_NOEDITOR ), _SCS("_set_kernings"), _SCS("_get_kernings") ); ADD_PROPERTY( PropertyInfo( Variant::REAL, "height", PROPERTY_HINT_RANGE,"-1024,1024,1" ), _SCS("set_height"), _SCS("get_height") ); ADD_PROPERTY( PropertyInfo( Variant::REAL, "ascent", PROPERTY_HINT_RANGE,"-1024,1024,1" ), _SCS("set_ascent"), _SCS("get_ascent") ); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "distance_field" ), _SCS("set_distance_field_hint"), _SCS("is_distance_field_hint") ); ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "fallback", PROPERTY_HINT_RESOURCE_TYPE,"BitmapFont" ), _SCS("set_fallback"), _SCS("get_fallback") ); }
bool Path2DEditor::forward_input_event(const InputEvent& p_event) { if (!node) return false; if (!node->is_visible()) return false; if (!node->get_curve().is_valid()) return false; switch(p_event.type) { case InputEvent::MOUSE_BUTTON: { const InputEventMouseButton &mb=p_event.mouse_button; Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = Point2(mb.x,mb.y); Vector2 cpoint = !mb.mod.alt? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform( canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); //first check if a point is to be added (segment split) real_t grab_treshold=EDITOR_DEF("poly_editor/point_grab_radius",8); // Test move point!! if ( mb.pressed && action==ACTION_NONE ) { Ref<Curve2D> curve = node->get_curve(); for(int i=0;i<curve->get_point_count();i++) { bool pointunder=false; { Point2 p = xform.xform( curve->get_point_pos(i) ); if (gpoint.distance_to(p) < grab_treshold ) { if (mb.button_index==BUTTON_LEFT && !mb.mod.shift && mode==MODE_EDIT) { action=ACTION_MOVING_POINT; action_point=i; moving_from=curve->get_point_pos(i); moving_screen_from=gpoint; return true; } else if ((mb.button_index==BUTTON_RIGHT && mode==MODE_EDIT) || (mb.button_index==BUTTON_LEFT && mode==MODE_DELETE)) { undo_redo->create_action(TTR("Remove Point from Curve")); undo_redo->add_do_method(curve.ptr(),"remove_point",i); undo_redo->add_undo_method(curve.ptr(),"add_point",curve->get_point_pos(i),curve->get_point_in(i),curve->get_point_out(i),i); undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->commit_action(); return true; } else pointunder=true; } } if (mb.button_index==BUTTON_LEFT && i<(curve->get_point_count()-1)) { Point2 p = xform.xform( curve->get_point_pos(i)+curve->get_point_out(i) ); if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode==MODE_EDIT_CURVE) ) { action=ACTION_MOVING_OUT; action_point=i; moving_from=curve->get_point_out(i); moving_screen_from=gpoint; return true; } } if (mb.button_index==BUTTON_LEFT && i>0) { Point2 p = xform.xform( curve->get_point_pos(i)+curve->get_point_in(i) ); if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode==MODE_EDIT_CURVE)) { action=ACTION_MOVING_IN; action_point=i; moving_from=curve->get_point_in(i); moving_screen_from=gpoint; return true; } } if (pointunder) return true; } } // Test add point in empty space! if ( mb.pressed && mb.button_index==BUTTON_LEFT && ((mb.mod.command && mode == MODE_EDIT) || mode == MODE_CREATE)) { Ref<Curve2D> curve = node->get_curve(); undo_redo->create_action(TTR("Add Point to Curve")); undo_redo->add_do_method(curve.ptr(),"add_point",cpoint); undo_redo->add_undo_method(curve.ptr(),"remove_point",curve->get_point_count()); undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->commit_action(); action=ACTION_MOVING_POINT; action_point=curve->get_point_count()-1; moving_from=curve->get_point_pos(action_point); moving_screen_from=gpoint; canvas_item_editor->get_viewport_control()->update(); return true; } if ( !mb.pressed && mb.button_index==BUTTON_LEFT && action!=ACTION_NONE) { Ref<Curve2D> curve = node->get_curve(); Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from); switch(action) { case ACTION_MOVING_POINT: { undo_redo->create_action(TTR("Move Point in Curve")); undo_redo->add_do_method(curve.ptr(),"set_point_pos",action_point,cpoint); undo_redo->add_undo_method(curve.ptr(),"set_point_pos",action_point,moving_from); undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->commit_action(); } break; case ACTION_MOVING_IN: { undo_redo->create_action(TTR("Move In-Control in Curve")); undo_redo->add_do_method(curve.ptr(),"set_point_in",action_point,new_pos); undo_redo->add_undo_method(curve.ptr(),"set_point_in",action_point,moving_from); undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->commit_action(); } break; case ACTION_MOVING_OUT: { undo_redo->create_action(TTR("Move Out-Control in Curve")); undo_redo->add_do_method(curve.ptr(),"set_point_out",action_point,new_pos); undo_redo->add_undo_method(curve.ptr(),"set_point_out",action_point,moving_from); undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->commit_action(); } break; } action=ACTION_NONE; return true; } #if 0 switch(mode) { case MODE_CREATE: { if (mb.button_index==BUTTON_LEFT && mb.pressed) { if (!wip_active) { wip.clear(); wip.push_back( canvas_item_editor->snap_point(cpoint) ); wip_active=true; edited_point_pos=canvas_item_editor->snap_point(cpoint); canvas_item_editor->update(); edited_point=1; return true; } else { if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_treshold) { //wip closed _wip_close(); return true; } else { wip.push_back( canvas_item_editor->snap_point(cpoint) ); edited_point=wip.size(); canvas_item_editor->update(); return true; //add wip point } } } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && wip_active) { _wip_close(); } } break; case MODE_EDIT: { if (mb.button_index==BUTTON_LEFT) { if (mb.pressed) { if (mb.mod.control) { if (poly.size() < 3) { undo_redo->create_action(TTR("Edit Poly")); undo_redo->add_undo_method(node,"set_polygon",poly); poly.push_back(cpoint); undo_redo->add_do_method(node,"set_polygon",poly); undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->commit_action(); return true; } //search edges int closest_idx=-1; Vector2 closest_pos; real_t closest_dist=1e10; for(int i=0;i<poly.size();i++) { Vector2 points[2] ={ xform.xform(poly[i]), xform.xform(poly[(i+1)%poly.size()]) }; Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint,points); if (cp.distance_squared_to(points[0])<CMP_EPSILON2 || cp.distance_squared_to(points[1])<CMP_EPSILON2) continue; //not valid to reuse point real_t d = cp.distance_to(gpoint); if (d<closest_dist && d<grab_treshold) { closest_dist=d; closest_pos=cp; closest_idx=i; } } if (closest_idx>=0) { pre_move_edit=poly; poly.insert(closest_idx+1,canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos))); edited_point=closest_idx+1; edited_point_pos=canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos)); node->set_polygon(poly); canvas_item_editor->update(); return true; } } else { //look for points to move int closest_idx=-1; Vector2 closest_pos; real_t closest_dist=1e10; for(int i=0;i<poly.size();i++) { Vector2 cp =xform.xform(poly[i]); real_t d = cp.distance_to(gpoint); if (d<closest_dist && d<grab_treshold) { closest_dist=d; closest_pos=cp; closest_idx=i; } } if (closest_idx>=0) { pre_move_edit=poly; edited_point=closest_idx; edited_point_pos=xform.affine_inverse().xform(closest_pos); canvas_item_editor->update(); return true; } } } else { if (edited_point!=-1) { //apply ERR_FAIL_INDEX_V(edited_point,poly.size(),false); poly[edited_point]=edited_point_pos; undo_redo->create_action(TTR("Edit Poly")); undo_redo->add_do_method(node,"set_polygon",poly); undo_redo->add_undo_method(node,"set_polygon",pre_move_edit); undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->commit_action(); edited_point=-1; return true; } } } if (mb.button_index==BUTTON_RIGHT && mb.pressed && edited_point==-1) { int closest_idx=-1; Vector2 closest_pos; real_t closest_dist=1e10; for(int i=0;i<poly.size();i++) { Vector2 cp =xform.xform(poly[i]); real_t d = cp.distance_to(gpoint); if (d<closest_dist && d<grab_treshold) { closest_dist=d; closest_pos=cp; closest_idx=i; } } if (closest_idx>=0) { undo_redo->create_action(TTR("Edit Poly (Remove Point)")); undo_redo->add_undo_method(node,"set_polygon",poly); poly.remove(closest_idx); undo_redo->add_do_method(node,"set_polygon",poly); undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); undo_redo->commit_action(); return true; } } } break; } #endif } break; case InputEvent::MOUSE_MOTION: { const InputEventMouseMotion &mm=p_event.mouse_motion; if ( action!=ACTION_NONE) { Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = Point2(mm.x,mm.y); Vector2 cpoint = !mm.mod.alt? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform( canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); Ref<Curve2D> curve = node->get_curve(); Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from); switch(action) { case ACTION_MOVING_POINT: { curve->set_point_pos(action_point,cpoint); } break; case ACTION_MOVING_IN: { curve->set_point_in(action_point,new_pos); } break; case ACTION_MOVING_OUT: { curve->set_point_out(action_point,new_pos); } break; } canvas_item_editor->get_viewport_control()->update(); return true; } #if 0 if (edited_point!=-1 && (wip_active || mm.button_mask&BUTTON_MASK_LEFT)) { Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = Point2(mm.x,mm.y); edited_point_pos = canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)); canvas_item_editor->update(); } #endif } break; } return false; }
Point2 operator+(const Point2 & p, const Vector2 & v) { return Point2(p.x + v.dx,p.y + v.dy); }
void PopupMenu::_input_event(const InputEvent &p_event) { switch( p_event.type) { case InputEvent::KEY: { if (!p_event.key.pressed) break; switch(p_event.key.scancode) { case KEY_DOWN: { for(int i=mouse_over+1;i<items.size();i++) { if (i<0 || i>=items.size()) continue; if (!items[i].separator && !items[i].disabled) { mouse_over=i; update(); break; } } } break; case KEY_UP: { for(int i=mouse_over-1;i>=0;i--) { if (i<0 || i>=items.size()) continue; if (!items[i].separator && !items[i].disabled) { mouse_over=i; update(); break; } } } break; case KEY_RETURN: case KEY_ENTER: { if (mouse_over>=0 && mouse_over<items.size() && !items[mouse_over].separator) { activate_item(mouse_over); } } break; } } break; case InputEvent::MOUSE_BUTTON: { const InputEventMouseButton &b=p_event.mouse_button; if (b.pressed) break; switch(b.button_index) { case BUTTON_WHEEL_DOWN: { if (get_global_pos().y + get_size().y > get_viewport_rect().size.y) { int vseparation = get_constant("vseparation"); Ref<Font> font = get_font("font"); Point2 pos = get_pos(); int s = (vseparation+font->get_height())*3; pos.y-=s; set_pos(pos); //update hover InputEvent ie; ie.type=InputEvent::MOUSE_MOTION; ie.mouse_motion.x=b.x; ie.mouse_motion.y=b.y+s; _input_event(ie); } } break; case BUTTON_WHEEL_UP: { if (get_global_pos().y < 0) { int vseparation = get_constant("vseparation"); Ref<Font> font = get_font("font"); Point2 pos = get_pos(); int s = (vseparation+font->get_height())*3; pos.y+=s; set_pos(pos); //update hover InputEvent ie; ie.type=InputEvent::MOUSE_MOTION; ie.mouse_motion.x=b.x; ie.mouse_motion.y=b.y-s; _input_event(ie); } } break; case BUTTON_LEFT: { int over=_get_mouse_over(Point2(b.x,b.y)); if (invalidated_click) { invalidated_click=false; break; } if (over<0 || items[over].separator || items[over].disabled) break; //non-activable if (items[over].submenu!="") { _activate_submenu(over); return; } activate_item(over); } break; } //update(); } break; case InputEvent::MOUSE_MOTION: { if (invalidated_click) { moved+=Vector2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y); if (moved.length()>4) invalidated_click=false; } const InputEventMouseMotion &m=p_event.mouse_motion; for(List<Rect2>::Element *E=autohide_areas.front();E;E=E->next()) { if (!Rect2(Point2(),get_size()).has_point(Point2(m.x,m.y)) && E->get().has_point(Point2(m.x,m.y))) { call_deferred("hide"); return; } } int over=_get_mouse_over(Point2(m.x,m.y)); int id = (over<0 || items[over].separator || items[over].disabled)?-1:items[over].ID; if (id<0) break; if (items[over].submenu!="" && submenu_over!=over) { submenu_over=over; submenu_timer->start(); } if (over!=mouse_over) { mouse_over=over; update(); } } break; } }
ProjectSettings::ProjectSettings(EditorData *p_data) { singleton=this; set_title("Project Settings (engine.cfg)"); undo_redo=&p_data->get_undo_redo(); data=p_data; TabContainer *tab_container = memnew( TabContainer ); add_child(tab_container); set_child_rect(tab_container); //tab_container->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN, 15 ); //tab_container->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END, 15 ); //tab_container->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN, 15 ); //tab_container->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END, 35 ); Control *props_base = memnew( Control ); tab_container->add_child(props_base); props_base->set_name("General"); globals_editor = memnew( PropertyEditor ); props_base->add_child(globals_editor); globals_editor->set_area_as_parent_rect(); globals_editor->hide_top_label(); globals_editor->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN, 55 ); globals_editor->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END, 35 ); globals_editor->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN, 5 ); globals_editor->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END, 5 ); globals_editor->set_capitalize_paths(false); globals_editor->get_tree()->connect("cell_selected",this,"_item_selected"); globals_editor->connect("property_toggled",this,"_item_checked"); globals_editor->connect("property_edited",this,"_settings_prop_edited"); Label *l = memnew( Label ); props_base->add_child(l); l->set_pos(Point2(6,5)); l->set_text("Category:"); l = memnew( Label ); l->set_anchor(MARGIN_LEFT,ANCHOR_RATIO); props_base->add_child(l); l->set_begin(Point2(0.21,5)); l->set_text("Property:"); l = memnew( Label ); l->set_anchor(MARGIN_LEFT,ANCHOR_RATIO); props_base->add_child(l); l->set_begin(Point2(0.51,5)); l->set_text("Type:"); category = memnew( LineEdit ); props_base->add_child(category); category->set_anchor(MARGIN_RIGHT,ANCHOR_RATIO); category->set_begin( Point2(5,25) ); category->set_end( Point2(0.20,26) ); category->connect("text_entered",this,"_item_adds"); property = memnew( LineEdit ); props_base->add_child(property); property->set_anchor(MARGIN_LEFT,ANCHOR_RATIO); property->set_anchor(MARGIN_RIGHT,ANCHOR_RATIO); property->set_begin( Point2(0.21,25) ); property->set_end( Point2(0.50,26) ); property->connect("text_entered",this,"_item_adds"); type = memnew( OptionButton ); props_base->add_child(type); type->set_anchor(MARGIN_LEFT,ANCHOR_RATIO); type->set_anchor(MARGIN_RIGHT,ANCHOR_RATIO); type->set_begin( Point2(0.51,25) ); type->set_end( Point2(0.70,26) ); type->add_item("bool"); type->add_item("int"); type->add_item("float"); type->add_item("string"); Button *add = memnew( Button ); props_base->add_child(add); add->set_anchor(MARGIN_LEFT,ANCHOR_RATIO); add->set_anchor(MARGIN_RIGHT,ANCHOR_RATIO); add->set_begin( Point2(0.71,25) ); add->set_end( Point2(0.85,26) ); add->set_text("Add"); add->connect("pressed",this,"_item_add"); Button *del = memnew( Button ); props_base->add_child(del); del->set_anchor(MARGIN_LEFT,ANCHOR_RATIO); del->set_anchor(MARGIN_RIGHT,ANCHOR_END); del->set_begin( Point2(0.86,25) ); del->set_end( Point2(5,26) ); del->set_text("Del"); del->connect("pressed",this,"_item_del"); Button *save = memnew( Button ); props_base->add_child(save); save->set_anchor(MARGIN_LEFT,ANCHOR_END); save->set_anchor(MARGIN_RIGHT,ANCHOR_END); save->set_anchor(MARGIN_TOP,ANCHOR_END); save->set_anchor(MARGIN_BOTTOM,ANCHOR_END); save->set_begin( Point2(80,28) ); save->set_end( Point2(10,20) ); save->set_text("Save"); save->connect("pressed",this,"_save"); popup_platform = memnew( MenuButton ); popup_platform->set_text("Copy To Platform.."); popup_platform->set_disabled(true); props_base->add_child(popup_platform); popup_platform->set_anchor(MARGIN_LEFT,ANCHOR_BEGIN); popup_platform->set_anchor(MARGIN_RIGHT,ANCHOR_BEGIN); popup_platform->set_anchor(MARGIN_TOP,ANCHOR_END); popup_platform->set_anchor(MARGIN_BOTTOM,ANCHOR_END); popup_platform->set_begin( Point2(10,28) ); popup_platform->set_end( Point2(150,20) ); List<StringName> ep; EditorImportExport::get_singleton()->get_export_platforms(&ep); ep.sort_custom<StringName::AlphCompare>(); for(List<StringName>::Element *E=ep.front();E;E=E->next()) { popup_platform->get_popup()->add_item( E->get() ); } popup_platform->get_popup()->connect("item_pressed",this,"_copy_to_platform"); get_ok()->set_text("Close"); set_hide_on_ok(true); message = memnew( ConfirmationDialog ); add_child(message); // message->get_cancel()->hide(); message->set_hide_on_ok(true); Control *input_base = memnew( Control ); input_base->set_name("Input Map"); input_base->set_area_as_parent_rect();; tab_container->add_child(input_base); l = memnew( Label ); input_base->add_child(l); l->set_pos(Point2(6,5)); l->set_text("Action:"); action_name = memnew( LineEdit ); action_name->set_anchor(MARGIN_RIGHT,ANCHOR_RATIO); action_name->set_begin( Point2(5,25) ); action_name->set_end( Point2(0.85,26) ); input_base->add_child(action_name); action_name->connect("text_entered",this,"_action_adds"); add = memnew( Button ); input_base->add_child(add); add->set_anchor(MARGIN_LEFT,ANCHOR_RATIO); add->set_begin( Point2(0.86,25) ); add->set_anchor(MARGIN_RIGHT,ANCHOR_END); add->set_end( Point2(5,26) ); add->set_text("Add"); add->connect("pressed",this,"_action_add"); input_editor = memnew( Tree ); input_base->add_child(input_editor); input_editor->set_area_as_parent_rect(); input_editor->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN, 55 ); input_editor->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END, 35 ); input_editor->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN, 5 ); input_editor->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END, 5 ); input_editor->connect("item_edited",this,"_action_persist_toggle"); input_editor->connect("button_pressed",this,"_action_button_pressed"); popup_add = memnew( PopupMenu ); add_child(popup_add); popup_add->connect("item_pressed",this,"_add_item"); press_a_key = memnew( ConfirmationDialog ); press_a_key->set_focus_mode(FOCUS_ALL); add_child(press_a_key); l = memnew( Label ); l->set_text("Press a Key.."); l->set_area_as_parent_rect(); l->set_align(Label::ALIGN_CENTER); l->set_margin(MARGIN_TOP,20); l->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_BEGIN,30); press_a_key_label=l; press_a_key->add_child(l); press_a_key->connect("input_event",this,"_wait_for_key"); press_a_key->connect("confirmed",this,"_press_a_key_confirm"); device_input=memnew( ConfirmationDialog ); add_child(device_input); device_input->get_ok()->set_text("Add"); device_input->connect("confirmed",this,"_device_input_add"); l = memnew( Label ); l->set_text("Device:"); l->set_pos(Point2(15,10)); device_input->add_child(l); l = memnew( Label ); l->set_text("Index:"); l->set_pos(Point2(90,10)); device_input->add_child(l); device_index_label=l; device_id = memnew( SpinBox ); device_id->set_pos(Point2(20,30)); device_id->set_size(Size2(70,10)); device_id->set_val(0); device_input->add_child(device_id); device_index = memnew( OptionButton ); device_index->set_pos(Point2(95,30)); device_index->set_size(Size2(300,10)); device_index->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,10); device_input->add_child(device_index); save = memnew( Button ); input_base->add_child(save); save->set_anchor(MARGIN_LEFT,ANCHOR_END); save->set_anchor(MARGIN_RIGHT,ANCHOR_END); save->set_anchor(MARGIN_TOP,ANCHOR_END); save->set_anchor(MARGIN_BOTTOM,ANCHOR_END); save->set_begin( Point2(80,28) ); save->set_end( Point2(10,20) ); save->set_text("Save"); save->connect("pressed",this,"_save"); setting=false; //translations TabContainer *translations = memnew( TabContainer ); translations->set_name("Localization"); tab_container->add_child(translations); { VBoxContainer *tvb = memnew( VBoxContainer ); translations->add_child(tvb); tvb->set_name("Translations"); HBoxContainer *thb = memnew( HBoxContainer); tvb->add_child(thb); thb->add_child( memnew( Label("Translations:"))); thb->add_spacer(); Button *addtr = memnew( Button("Add..") ); addtr->connect("pressed",this,"_translation_file_open"); thb->add_child(addtr); MarginContainer *tmc = memnew( MarginContainer ); tvb->add_child(tmc); tmc->set_v_size_flags(SIZE_EXPAND_FILL); translation_list = memnew( Tree ); translation_list->set_v_size_flags(SIZE_EXPAND_FILL); tmc->add_child(translation_list); translation_file_open=memnew( FileDialog ); add_child(translation_file_open); translation_file_open->set_mode(FileDialog::MODE_OPEN_FILE); translation_file_open->connect("file_selected",this,"_translation_add"); } { VBoxContainer *tvb = memnew( VBoxContainer ); translations->add_child(tvb); tvb->set_name("Remaps"); HBoxContainer *thb = memnew( HBoxContainer); tvb->add_child(thb); thb->add_child( memnew( Label("Resources:"))); thb->add_spacer(); Button *addtr = memnew( Button("Add..") ); addtr->connect("pressed",this,"_translation_res_file_open"); thb->add_child(addtr); MarginContainer *tmc = memnew( MarginContainer ); tvb->add_child(tmc); tmc->set_v_size_flags(SIZE_EXPAND_FILL); translation_remap = memnew( Tree ); translation_remap->set_v_size_flags(SIZE_EXPAND_FILL); translation_remap->connect("cell_selected",this,"_translation_res_select"); tmc->add_child(translation_remap); translation_remap->connect("button_pressed",this,"_translation_res_delete"); translation_res_file_open=memnew( FileDialog ); add_child(translation_res_file_open); translation_res_file_open->set_mode(FileDialog::MODE_OPEN_FILE); translation_res_file_open->connect("file_selected",this,"_translation_res_add"); thb = memnew( HBoxContainer); tvb->add_child(thb); thb->add_child( memnew( Label("Remaps by Locale:"))); thb->add_spacer(); addtr = memnew( Button("Add..") ); addtr->connect("pressed",this,"_translation_res_option_file_open"); translation_res_option_add_button=addtr; thb->add_child(addtr); tmc = memnew( MarginContainer ); tvb->add_child(tmc); tmc->set_v_size_flags(SIZE_EXPAND_FILL); translation_remap_options = memnew( Tree ); translation_remap_options->set_v_size_flags(SIZE_EXPAND_FILL); tmc->add_child(translation_remap_options); translation_remap_options->set_columns(2); translation_remap_options->set_column_title(0,"Path"); translation_remap_options->set_column_title(1,"Locale"); translation_remap_options->set_column_titles_visible(true); translation_remap_options->set_column_expand(0,true); translation_remap_options->set_column_expand(1,false); translation_remap_options->set_column_min_width(1,200); translation_remap_options->connect("item_edited",this,"_translation_res_option_changed"); translation_remap_options->connect("button_pressed",this,"_translation_res_option_delete"); translation_res_option_file_open=memnew( FileDialog ); add_child(translation_res_option_file_open); translation_res_option_file_open->set_mode(FileDialog::MODE_OPEN_FILE); translation_res_option_file_open->connect("file_selected",this,"_translation_res_option_add"); } { VBoxContainer *avb = memnew( VBoxContainer ); tab_container->add_child(avb); avb->set_name("AutoLoad"); HBoxContainer *ahb = memnew( HBoxContainer); avb->add_child(ahb); VBoxContainer *avb_name = memnew( VBoxContainer ); avb_name->set_h_size_flags(SIZE_EXPAND_FILL); autoload_add_name = memnew(LineEdit); avb_name->add_margin_child("Node Name:",autoload_add_name); ahb->add_child(avb_name); VBoxContainer *avb_path = memnew( VBoxContainer ); avb_path->set_h_size_flags(SIZE_EXPAND_FILL); HBoxContainer *ahb_path = memnew( HBoxContainer ); autoload_add_path = memnew(LineEdit); autoload_add_path->set_h_size_flags(SIZE_EXPAND_FILL); ahb_path->add_child(autoload_add_path); Button *browseaa = memnew( Button("..") ); ahb_path->add_child(browseaa); browseaa->connect("pressed",this,"_autoload_file_open"); Button *addaa = memnew( Button("Add") ); ahb_path->add_child(addaa); addaa->connect("pressed",this,"_autoload_add"); avb_path->add_margin_child("Path:",ahb_path); ahb->add_child(avb_path); autoload_list = memnew( Tree ); autoload_list->set_v_size_flags(SIZE_EXPAND_FILL); avb->add_margin_child("List:",autoload_list,true); autoload_file_open=memnew( FileDialog ); add_child(autoload_file_open); autoload_file_open->set_mode(FileDialog::MODE_OPEN_FILE); autoload_file_open->connect("file_selected",this,"_autoload_file_callback"); autoload_list->set_columns(2); autoload_list->set_column_titles_visible(true); autoload_list->set_column_title(0,"name"); autoload_list->set_column_title(1,"path"); autoload_list->connect("button_pressed",this,"_autoload_delete"); } timer = memnew( Timer ); timer->set_wait_time(1.5); timer->connect("timeout",Globals::get_singleton(),"save"); timer->set_one_shot(true); add_child(timer); updating_translations=false; /* Control * es = memnew( Control ); es->set_name("Export"); tab_container->add_child(es); export_settings = memnew( ProjectExportSettings ); es->add_child(export_settings); export_settings->set_area_as_parent_rect(); export_settings->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END, 35 ); */ }
void PopupMenu::_notification(int p_what) { switch(p_what) { case NOTIFICATION_DRAW: { RID ci = get_canvas_item(); Size2 size=get_size(); Ref<StyleBox> style = get_stylebox("panel"); Ref<StyleBox> hover = get_stylebox("hover"); Ref<Font> font = get_font("font"); Ref<Texture> check = get_icon("checked"); Ref<Texture> uncheck = get_icon("unchecked"); Ref<Texture> submenu= get_icon("submenu"); Ref<StyleBox> separator = get_stylebox("separator"); style->draw( ci, Rect2( Point2(), get_size() ) ); Point2 ofs=style->get_offset(); int vseparation = get_constant("vseparation"); int hseparation = get_constant("hseparation"); Color font_color = get_color("font_color"); Color font_color_disabled = get_color("font_color_disabled"); Color font_color_accel = get_color("font_color_accel"); Color font_color_hover = get_color("font_color_hover"); float font_h=font->get_height(); for (int i=0;i<items.size();i++) { if (i>0) ofs.y+=vseparation; Point2 item_ofs=ofs; float h; Size2 icon_size; if (!items[i].icon.is_null()) { icon_size = items[i].icon->get_size(); h = MAX( icon_size.height, font_h ); } else { h=font_h; } if (i==mouse_over) { hover->draw(ci, Rect2( ofs+Point2(-hseparation,-vseparation), Size2( get_size().width - style->get_minimum_size().width + hseparation*2, h+vseparation*2 ) )); } if (items[i].separator) { int sep_h=separator->get_center_size().height+separator->get_minimum_size().height; separator->draw(ci, Rect2( ofs+Point2(0,Math::floor((h-sep_h)/2.0)), Size2( get_size().width - style->get_minimum_size().width , sep_h ) )); } if (items[i].checkable) { if (items[i].checked) check->draw(ci, item_ofs+Point2(0,Math::floor((h-check->get_height())/2.0))); else uncheck->draw(ci, item_ofs+Point2(0,Math::floor((h-check->get_height())/2.0))); item_ofs.x+=check->get_width()+hseparation; } if (!items[i].icon.is_null()) { items[i].icon->draw( ci, item_ofs+Point2(0,Math::floor((h-icon_size.height)/2.0))); item_ofs.x+=items[i].icon->get_width(); item_ofs.x+=hseparation; } if (items[i].submenu!="") { submenu->draw( ci, Point2(size.width - style->get_margin(MARGIN_RIGHT) - submenu->get_width(),item_ofs.y+Math::floor(h-submenu->get_height())/2)); } item_ofs.y+=font->get_ascent(); if (!items[i].separator) font->draw(ci,item_ofs+Point2(0,Math::floor((h-font_h)/2.0)),items[i].text,items[i].disabled?font_color_disabled:(i==mouse_over?font_color_hover:font_color)); if (items[i].accel) { //accelerator String text = _get_accel_text(items[i].accel); item_ofs.x=size.width-style->get_margin(MARGIN_RIGHT)-font->get_string_size(text).width; font->draw(ci,item_ofs+Point2(0,Math::floor((h-font_h)/2.0)),text,i==mouse_over?font_color_hover:font_color_accel); } items[i]._ofs_cache=ofs.y; ofs.y+=h; } } break; case NOTIFICATION_MOUSE_ENTER: { grab_focus(); } break; case NOTIFICATION_MOUSE_EXIT: { if (mouse_over>=0) { mouse_over=-1; update(); } } break; } }
void FindReplaceBar::_replace_all() { // line as x so it gets priority in comparison, column as y Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column()); Point2i prev_match = Point2(-1, -1); bool selection_enabled = text_edit->is_selection_active(); Point2i selection_begin, selection_end; if (selection_enabled) { selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column()); selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column()); } int vsval = text_edit->get_v_scroll(); text_edit->cursor_set_line(0); text_edit->cursor_set_column(0); String replace_text = get_replace_text(); int search_text_len = get_search_text().length(); int rc = 0; replace_all_mode = true; text_edit->begin_complex_operation(); while (search_next()) { // replace area Point2i match_from(result_line, result_col); Point2i match_to(result_line, result_col + search_text_len); if (match_from < prev_match) break; // done prev_match = Point2i(result_line, result_col + replace_text.length()); text_edit->select(result_line, result_col, result_line, match_to.y); if (selection_enabled && is_selection_only()) { if (match_from < selection_begin || match_to > selection_end) continue; // replace but adjust selection bounds text_edit->insert_text_at_cursor(replace_text); if (match_to.x == selection_end.x) selection_end.y += replace_text.length() - search_text_len; } else { // just replace text_edit->insert_text_at_cursor(replace_text); } rc++; } text_edit->end_complex_operation(); replace_all_mode = false; // restore editor state (selection, cursor, scroll) text_edit->cursor_set_line(orig_cursor.x); text_edit->cursor_set_column(orig_cursor.y); if (selection_enabled && is_selection_only()) { // reselect text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y); } else { text_edit->deselect(); } text_edit->set_v_scroll(vsval); set_error(vformat(TTR("Replaced %d occurrence(s)."), rc)); }
SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_open_instance) { connect_to_script_mode = false; undo_redo = NULL; tree_dirty = true; selected = NULL; marked_selectable = false; marked_children_selectable = false; can_rename = p_can_rename; can_open_instance = p_can_open_instance; display_foreign = false; editor_selection = NULL; if (p_label) { Label *label = memnew(Label); label->set_position(Point2(10, 0)); label->set_text(TTR("Scene Tree (Nodes):")); add_child(label); } tree = memnew(Tree); tree->set_anchor(MARGIN_RIGHT, ANCHOR_END); tree->set_anchor(MARGIN_BOTTOM, ANCHOR_END); tree->set_begin(Point2(0, p_label ? 18 : 0)); tree->set_end(Point2(0, 0)); tree->add_constant_override("button_margin", 0); add_child(tree); tree->set_drag_forwarding(this); if (p_can_rename) { tree->set_allow_rmb_select(true); tree->connect("item_rmb_selected", this, "_rmb_select"); tree->connect("empty_tree_rmb_selected", this, "_rmb_select"); } tree->connect("cell_selected", this, "_selected_changed"); tree->connect("item_edited", this, "_renamed", varray(), CONNECT_DEFERRED); tree->connect("multi_selected", this, "_cell_multi_selected"); tree->connect("button_pressed", this, "_cell_button_pressed"); tree->connect("nothing_selected", this, "_deselect_items"); //tree->connect("item_edited", this,"_renamed",Vector<Variant>(),true); error = memnew(AcceptDialog); add_child(error); warning = memnew(AcceptDialog); add_child(warning); warning->set_title(TTR("Node Configuration Warning!")); show_enabled_subscene = false; last_hash = 0; pending_test_update = false; updating_tree = false; blocked = 0; update_timer = memnew(Timer); update_timer->connect("timeout", this, "_update_tree"); update_timer->set_one_shot(true); update_timer->set_wait_time(0.5); add_child(update_timer); script_types = memnew(List<StringName>); ClassDB::get_inheriters_from_class("Script", script_types); }
FindReplaceDialog::FindReplaceDialog() { set_self_modulate(Color(1, 1, 1, 0.8)); VBoxContainer *vb = memnew(VBoxContainer); add_child(vb); search_text = memnew(LineEdit); vb->add_margin_child(TTR("Search"), search_text); search_text->connect("text_entered", this, "_search_text_entered"); replace_label = memnew(Label); replace_label->set_text(TTR("Replace By")); vb->add_child(replace_label); replace_mc = memnew(MarginContainer); vb->add_child(replace_mc); replace_text = memnew(LineEdit); replace_text->set_anchor(MARGIN_RIGHT, ANCHOR_END); replace_text->set_begin(Point2(15, 132)); replace_text->set_end(Point2(-15, 135)); replace_mc->add_child(replace_text); replace_text->connect("text_entered", this, "_replace_text_entered"); MarginContainer *opt_mg = memnew(MarginContainer); vb->add_child(opt_mg); VBoxContainer *svb = memnew(VBoxContainer); opt_mg->add_child(svb); svb->add_child(memnew(Label)); whole_words = memnew(CheckButton); whole_words->set_text(TTR("Whole Words")); svb->add_child(whole_words); case_sensitive = memnew(CheckButton); case_sensitive->set_text(TTR("Case Sensitive")); svb->add_child(case_sensitive); backwards = memnew(CheckButton); backwards->set_text(TTR("Backwards")); svb->add_child(backwards); opt_mg = memnew(MarginContainer); vb->add_child(opt_mg); VBoxContainer *rvb = memnew(VBoxContainer); opt_mg->add_child(rvb); replace_vb = rvb; //rvb ->add_child(memnew(HSeparator)); rvb->add_child(memnew(Label)); prompt = memnew(CheckButton); prompt->set_text(TTR("Prompt On Replace")); rvb->add_child(prompt); prompt->connect("pressed", this, "_prompt_changed"); selection_only = memnew(CheckButton); selection_only->set_text(TTR("Selection Only")); rvb->add_child(selection_only); int margin = get_constant("margin", "Dialogs"); int button_margin = get_constant("button_margin", "Dialogs"); skip = memnew(Button); skip->set_anchor(MARGIN_LEFT, ANCHOR_END); skip->set_anchor(MARGIN_TOP, ANCHOR_END); skip->set_anchor(MARGIN_RIGHT, ANCHOR_END); skip->set_anchor(MARGIN_BOTTOM, ANCHOR_END); skip->set_begin(Point2(-70, -button_margin)); skip->set_end(Point2(-10, -margin)); skip->set_text(TTR("Skip")); add_child(skip); skip->connect("pressed", this, "_skip_pressed"); error_label = memnew(Label); error_label->set_align(Label::ALIGN_CENTER); error_label->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); vb->add_child(error_label); set_hide_on_ok(false); }
void ButtonArray::_notification(int p_what) { switch (p_what) { case NOTIFICATION_MOUSE_EXIT: { hover = -1; update(); } break; case NOTIFICATION_READY: { MethodInfo mi; mi.name = "mouse_sub_enter"; add_user_signal(mi); } break; case NOTIFICATION_DRAW: { Size2 size = get_size(); Size2 minsize = get_combined_minimum_size(); Ref<StyleBox> style_normal = get_stylebox("normal"); Ref<StyleBox> style_selected = get_stylebox("selected"); Ref<StyleBox> style_focus = get_stylebox("focus"); Ref<StyleBox> style_hover = get_stylebox("hover"); Ref<Font> font_normal = get_font("font"); Ref<Font> font_selected = get_font("font_selected"); int icon_sep = get_constant("icon_separator"); int button_sep = get_constant("button_separator"); Color color_normal = get_color("font_color"); Color color_selected = get_color("font_color_selected"); int sep = button_sep; int ofs = 0; int expand = 0; switch (align) { case ALIGN_BEGIN: { ofs = 0; } break; case ALIGN_CENTER: { ofs = Math::floor((size[orientation] - minsize[orientation]) / 2); } break; case ALIGN_END: { ofs = Math::floor((size[orientation] - minsize[orientation])); } break; case ALIGN_FILL: { if (buttons.size() > 1) sep += Math::floor((size[orientation] - minsize[orientation]) / (buttons.size() - 1.0)); ofs = 0; } break; case ALIGN_EXPAND_FILL: { ofs = 0; expand = size[orientation] - minsize[orientation]; } break; } int op_size = orientation == VERTICAL ? size.width : size.height; for (int i = 0; i < buttons.size(); i++) { int ms = buttons[i]._ms_cache; int s = ms; if (expand > 0) { s += expand / buttons.size(); } if (min_button_size != -1 && s < min_button_size) { s = min_button_size; } Rect2 r; r.pos[orientation] = ofs; r.pos[!orientation] = 0; r.size[orientation] = s; r.size[!orientation] = op_size; Ref<Font> f; Color c; Point2 sbsize; Point2 sbofs; if (i == selected) { draw_style_box(style_selected, r); sbsize = style_selected->get_minimum_size(); sbofs = style_selected->get_offset(); f = font_selected; c = color_selected; if (has_focus()) draw_style_box(style_focus, r); } else { if (hover == i) draw_style_box(style_hover, r); else if (!flat) draw_style_box(style_normal, r); sbsize = style_normal->get_minimum_size(); sbofs = style_normal->get_offset(); f = font_normal; c = color_normal; } Size2 ssize = f->get_string_size(buttons[i].xl_text); if (buttons[i].icon.is_valid()) { ssize.x += buttons[i].icon->get_width(); } Point2 text_ofs = ((r.size - ssize - sbsize) / 2.0 + Point2(0, f->get_ascent())).floor() + sbofs; if (buttons[i].icon.is_valid()) { draw_texture(buttons[i].icon, r.pos + Point2(text_ofs.x, Math::floor((r.size.height - buttons[i].icon->get_height()) / 2.0))); text_ofs.x += buttons[i].icon->get_width() + icon_sep; } draw_string(f, text_ofs + r.pos, buttons[i].xl_text, c); buttons[i]._pos_cache = ofs; buttons[i]._size_cache = s; ofs += s; ofs += sep; } } break; } }
void TouchScreenButton::_input(const InputEvent& p_event) { if (!get_scene()) return; if (p_event.device != 0) return; if (passby_press) { if (p_event.type==InputEvent::SCREEN_TOUCH && !p_event.screen_touch.pressed && finger_pressed==p_event.screen_touch.index) { emit_signal("released"); if (action_id!=-1) { Input::get_singleton()->action_release(action); InputEvent ie; ie.type=InputEvent::ACTION; ie.ID=0; ie.action.action=action_id; ie.action.pressed=false; get_scene()->input_event(ie); } finger_pressed=-1; update(); } if ((p_event.type==InputEvent::SCREEN_TOUCH && p_event.screen_touch.pressed)|| p_event.type==InputEvent::SCREEN_DRAG) { if (finger_pressed==-1 || p_event.screen_touch.index==finger_pressed) { Point2 coord = (get_global_transform()).affine_inverse().xform(Point2(p_event.screen_touch.x,p_event.screen_touch.y)); bool touched=false; if (bitmask.is_valid()) { if (Rect2(Point2(),bitmask->get_size()).has_point(coord)) { if (bitmask->get_bit(coord)) touched=true; } } else { if (texture.is_valid()) touched=Rect2(Point2(),texture->get_size()).has_point(coord); } if (touched) { if (finger_pressed==-1) { finger_pressed=p_event.screen_touch.index; //emit change stuff emit_signal("pressed"); if (action_id!=-1) { Input::get_singleton()->action_press(action); InputEvent ie; ie.type=InputEvent::ACTION; ie.ID=0; ie.action.action=action_id; ie.action.pressed=true; get_scene()->input_event(ie); } update(); } } else { if (finger_pressed!=-1) { emit_signal("released"); if (action_id!=-1) { Input::get_singleton()->action_release(action); InputEvent ie; ie.type=InputEvent::ACTION; ie.ID=0; ie.action.action=action_id; ie.action.pressed=false; get_scene()->input_event(ie); } finger_pressed=-1; update(); } } } } } else { if (p_event.type==InputEvent::SCREEN_TOUCH) { if (p_event.screen_touch.pressed) { if (!is_visible()) return; if (finger_pressed!=-1) return; //already fingering Point2 coord = (get_global_transform()).affine_inverse().xform(Point2(p_event.screen_touch.x,p_event.screen_touch.y)); bool touched=false; if (bitmask.is_valid()) { if (Rect2(Point2(),bitmask->get_size()).has_point(coord)) { if (bitmask->get_bit(coord)) touched=true; } } else { if (!texture.is_null()) touched=Rect2(Point2(),texture->get_size()).has_point(coord); } if (touched) { finger_pressed=p_event.screen_touch.index; //emit change stuff emit_signal("pressed"); if (action_id!=-1) { Input::get_singleton()->action_press(action); InputEvent ie; ie.type=InputEvent::ACTION; ie.ID=0; ie.action.action=action_id; ie.action.pressed=true; get_scene()->input_event(ie); } update(); } } else { if (p_event.screen_touch.index==finger_pressed) { //untouch emit_signal("released"); if (action_id!=-1) { Input::get_singleton()->action_release(action); InputEvent ie; ie.type=InputEvent::ACTION; ie.ID=0; ie.action.action=action_id; ie.action.pressed=false; get_scene()->input_event(ie); } finger_pressed=-1; update(); } } } } }
ShaderEditor::ShaderEditor() { tab_container = memnew( TabContainer ); add_child(tab_container); tab_container->set_area_as_parent_rect(); tab_container->set_begin(Point2(0,0)); //tab_container->set_begin(Point2(0,0)); close = memnew( TextureButton ); close->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,20); close->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,4); close->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,2); add_child(close); edit_menu = memnew( MenuButton ); add_child(edit_menu); edit_menu->set_pos(Point2(5,-1)); edit_menu->set_text(TTR("Edit")); edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/undo", TTR("Undo"), KEY_MASK_CMD|KEY_Z), EDIT_UNDO); edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/redo", TTR("Redo"), KEY_MASK_CMD|KEY_Y), EDIT_REDO); edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/cut", TTR("Cut"), KEY_MASK_CMD|KEY_X), EDIT_CUT); edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy", TTR("Copy"), KEY_MASK_CMD|KEY_C), EDIT_COPY); edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/paste", TTR("Paste"), KEY_MASK_CMD|KEY_V), EDIT_PASTE); edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/select_all", TTR("Select All"), KEY_MASK_CMD|KEY_A), EDIT_SELECT_ALL); edit_menu->get_popup()->connect("item_pressed", this,"_menu_option"); search_menu = memnew( MenuButton ); add_child(search_menu); search_menu->set_pos(Point2(38,-1)); search_menu->set_text(TTR("Search")); search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD|KEY_F), SEARCH_FIND); search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_next", TTR("Find Next"), KEY_F3), SEARCH_FIND_NEXT); search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT|KEY_F3), SEARCH_FIND_PREV); search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/replace", TTR("Replace.."), KEY_MASK_CMD|KEY_R), SEARCH_REPLACE); search_menu->get_popup()->add_separator(); // search_menu->get_popup()->add_item("Locate Symbol..",SEARCH_LOCATE_SYMBOL,KEY_MASK_CMD|KEY_K); search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD|KEY_L), SEARCH_GOTO_LINE); search_menu->get_popup()->connect("item_pressed", this,"_menu_option"); tab_container->connect("tab_changed", this,"_tab_changed"); erase_tab_confirm = memnew( ConfirmationDialog ); add_child(erase_tab_confirm); erase_tab_confirm->connect("confirmed", this,"_close_current_tab"); goto_line_dialog = memnew(GotoLineDialog); add_child(goto_line_dialog); vertex_editor = memnew( ShaderTextEditor ); tab_container->add_child(vertex_editor); vertex_editor->set_name(TTR("Vertex")); fragment_editor = memnew( ShaderTextEditor ); tab_container->add_child(fragment_editor); fragment_editor->set_name(TTR("Fragment")); light_editor = memnew( ShaderTextEditor ); tab_container->add_child(light_editor); light_editor->set_name(TTR("Lighting")); tab_container->set_current_tab(1); vertex_editor->connect("script_changed", this,"apply_shaders"); fragment_editor->connect("script_changed", this,"apply_shaders"); light_editor->connect("script_changed", this,"apply_shaders"); EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed"); _editor_settings_changed(); }
bool CollisionShape2DEditor::forward_input_event(const InputEvent& p_event) { if (!node) { return false; } if (!node->get_shape().is_valid()) { return false; } if (shape_type == -1) { return false; } switch( p_event.type ) { case InputEvent::MOUSE_BUTTON: { const InputEventMouseButton& mb = p_event.mouse_button; Matrix32 gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Point2 gpoint(mb.x,mb.y); if (mb.button_index == BUTTON_LEFT) { if (mb.pressed) { for (int i = 0; i < handles.size(); i++) { if (gt.xform(handles[i]).distance_to(gpoint) < 8) { edit_handle = i; break; } } if (edit_handle==-1) { pressed = false; return false; } original = get_handle_value(edit_handle); pressed = true; return true; } else { if (pressed) { commit_handle(edit_handle, original); edit_handle = -1; pressed = false; return true; } } } return false; } break; case InputEvent::MOUSE_MOTION: { const InputEventMouseMotion& mm = p_event.mouse_motion; if (edit_handle == -1 || !pressed) { return false; } Point2 gpoint = Point2(mm.x,mm.y); Point2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); set_handle(edit_handle, cpoint); return true; } break; } return false; }
Vertex1P1T::Vertex1P1T(): Vertex1P1T(Point3(), Point2()) { }
void ScriptEditorDebugger::_performance_draw() { Vector<int> which; for(int i=0;i<perf_items.size();i++) { if (perf_items[i]->is_selected(0)) which.push_back(i); } if(which.empty()) return; Ref<StyleBox> graph_sb = get_stylebox("normal","TextEdit"); Ref<Font> graph_font = get_font("font","TextEdit"); int cols = Math::ceil(Math::sqrt(which.size())); int rows = (which.size()+1)/cols; if (which.size()==1) rows=1; int margin =3; int point_sep=5; Size2i s = Size2i(perf_draw->get_size())/Size2i(cols,rows); for(int i=0;i<which.size();i++) { Point2i p(i%cols,i/cols); Rect2i r(p*s,s); r.pos+=Point2(margin,margin); r.size-=Point2(margin,margin)*2.0; perf_draw->draw_style_box(graph_sb,r); r.pos+=graph_sb->get_offset(); r.size-=graph_sb->get_minimum_size(); int pi=which[i]; Color c = Color(0.7,0.9,0.5); c.set_hsv(Math::fmod(c.get_h()+pi*0.7654,1),c.get_s(),c.get_v()); c.a=0.8; perf_draw->draw_string(graph_font,r.pos+Point2(0,graph_font->get_ascent()),perf_items[pi]->get_text(0),c,r.size.x); c.a=0.6; perf_draw->draw_string(graph_font,r.pos+Point2(graph_font->get_char_size('X').width,graph_font->get_ascent()+graph_font->get_height()),perf_items[pi]->get_text(1),c,r.size.y); float spacing=point_sep/float(cols); float from = r.size.width; List<Vector<float> >::Element *E=perf_history.front(); float prev=-1; while(from>=0 && E) { float m = perf_max[pi]; if (m==0) m=0.00001; float h = E->get()[pi]/m; h=(1.0-h)*r.size.y; c.a=0.7; if (E!=perf_history.front()) perf_draw->draw_line(r.pos+Point2(from,h),r.pos+Point2(from+spacing,prev),c,2.0); prev=h; E=E->next(); from-=spacing; } } }
void SFApp::OnUpdateWorld() { if(gameover){ }else{ // Handles Player movement if(up){ if(ups < 5.0f){ ups += 0.05; }else{ups = 5.0f;} }else if(ups > 0){ ups -= 0.05; }else{ups = 0;} if(down){ if(downs < 5.0f){ downs += 0.05; }else{downs = 5.0f;} }else if(downs > 0){ downs -= 0.05; }else{downs = 0;} if(left){ if(lefts < 5.0f){ lefts += 0.05; }else{lefts = 5.0f;} }else if(lefts > 0){ lefts -= 0.05; }else{lefts = 0;} if(right){ if(rights < 5.0f){ rights += 0.05; }else{rights = 5.0f;} }else if(rights > 0){ rights -= 0.05; }else{rights = 0;} player->GoNorth(ups); for(auto w: walls){ if(w->CollidesWith(player)){ player->GoSouth(ups); ups = 0; } } player->GoSouth(downs); for(auto w: walls){ if(w->CollidesWith(player)){ player->GoNorth(downs); downs = 0; } } player->GoWest(lefts); for(auto w: walls){ if(w->CollidesWith(player)){ player->GoEast(lefts); lefts = 0; } } player->GoEast(rights); for(auto w: walls){ if(w->CollidesWith(player)){ player->GoWest(rights); rights = 0; } } //Handles adding projectiles and moving them if(fired){ if(fire % firespeed == 0){ FireProjectile(); } fire ++; } for(auto p: projectiles) { p->GoNorth(projectilespeed); } //collect coin pick ups for(auto c: coins) { if(c->CollidesWith(player)){ c->HandleCollision(); switch(c->getCode()){ case FASTSHOOT: cout << "FAST SHOOT" << endl; // firespeed = 5; fastshoot = 300; break; case HEALTH: cout << "HEALTH" << endl; health += 10; if(health > 100){ health = 100; } healthgreenpos.h = (444/100)*health; healthgreenpos.y = healthpos.y + 3 + (444-healthgreenpos.h); break; case SLOWALIENS: cout << "SLOW ALIENS" << endl; slowaliens = 300; // alienspeed /= 2; break; case CLEARALIENS: cout << "CLEAR ALIENS" << endl; for(auto a: aliens){ a->HandleCollision(); score ++; if(score % 100 == 0 && score > 0){ maxAliens++; alienspeed += 0.01f; } if(score % 5 == 0 && score > 0){ auto coin = make_shared<SFAsset>(SFASSET_COIN, sf_window); auto pos = a->GetPosition(); coin->SetPosition(pos); coins.push_back(coin); } } break; } } } if(fastshoot > 0){ firespeed = 5; fastshoot --; }else{firespeed = 20;} if(slowaliens > 0){ alienspeed = alientempspeed / 2; slowaliens --; }else{alienspeed = alientempspeed; alientempspeed = alienspeed;} //remove picked up coins list<shared_ptr<SFAsset>> tmp1; for(auto c : coins) { if(c->IsAlive()) { tmp1.push_back(c); } } coins.clear(); coins = list<shared_ptr<SFAsset>>(tmp1); // Update enemy positions for(auto a : aliens) { a->GoSouth(alienspeed); } // Detect collisions for(auto a : aliens) { for(auto p : projectiles) { if(p->CollidesWith(a)) { p->HandleCollision(); a->HandleCollision(); score ++; if(score % 100 == 0 && score > 0){ maxAliens++; alienspeed += 0.01f; } if(score % 5 == 0 && score > 0){ auto coin = make_shared<SFAsset>(SFASSET_COIN, sf_window); auto pos = a->GetPosition(); coin->SetPosition(pos); coins.push_back(coin); } } } for(auto w: walls){ if(w->CollidesWith(a)){ a->HandleCollision(); alienspeed += 0.01f; score ++; if(score % 100 == 0 && score > 0){ alienspeed += 0.01f; maxAliens++; } } } if(a->GetPosition().getY() < 0){ health -= 10; healthgreenpos.h = (444/100)*health; healthgreenpos.y = healthpos.y + 3 + (444-healthgreenpos.h); a->HandleCollision(); } } if(currentAliens < maxAliens){ auto alien = make_shared<SFAsset>(SFASSET_ALIEN, sf_window); auto pos = Point2(rand()% 640, 480 + (rand()%600)); alien->SetPosition(pos); aliens.push_back(alien); currentAliens ++; } // remove dead aliens (the long way) list<shared_ptr<SFAsset>> tmp; for(auto a : aliens) { if(a->IsAlive()) { tmp.push_back(a); }else{ auto explosion = make_shared<SFAsset>(SFASSET_EXPLOSION, sf_window); auto pos = a->GetPosition(); explosion->SetPosition(pos); explosions.push_back(explosion); currentAliens--;} } aliens.clear(); aliens = list<shared_ptr<SFAsset>>(tmp); //remove projectiles list<shared_ptr<SFAsset>> tmp2; for(auto p : projectiles) { if(p->GetPosition().getY() > 480){ p->HandleCollision(); } if(p->IsAlive()) { tmp2.push_back(p); } } projectiles.clear(); projectiles = list<shared_ptr<SFAsset>>(tmp2); back.y +=8; back2.y +=8; if(back.y > 800){ back.y = back2.y - 800; } if(back2.y > 800){ back2.y = back.y - 800; } list<shared_ptr<SFAsset>> tmp3; for(auto e: explosions){ e->addtoCounter(); if(e->getCounter() > 20){ e->HandleCollision(); } if(e->IsAlive()){ tmp3.push_back(e); } } explosions.clear(); explosions = list<shared_ptr<SFAsset>>(tmp3); if(health <= 0){ gameover = true; } } }