Beispiel #1
0
/// Находит элемент на котором находится заданная точка
size_t VPlanElemList::Find(double in_abscoord) const
{
	class has_point
	{
	private:
		double abscoord;
	public:
		has_point(double in_abscoord){abscoord=in_abscoord;};
		bool operator() (const VPlanElement& in_slope){return in_slope.HasPoint(abscoord);};
	};	
	std::vector<VPlanElement>::const_iterator i=std::find_if(records.begin(), records.end(), has_point(in_abscoord));
	return i!=records.end() ? i-records.begin() : BAD_INDEX;
}
Beispiel #2
0
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) {

					emit_signal("button_down");

					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 {

					emit_signal("button_up");

					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;
				emit_signal("button_down");

			} else {

				emit_signal("button_up");

				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;
					emit_signal("button_down");

				} 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;

					emit_signal("button_up");

					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();

			}
		}

	}
}
Beispiel #3
0
void BaseButton::_gui_input(Ref<InputEvent> p_event) {

	if (status.disabled) // no interaction with disabled button
		return;

	Ref<InputEventMouseButton> b = p_event;

	if (b.is_valid()) {
		if (status.disabled || b->get_button_index() != 1)
			return;

		if (status.pressing_button)
			return;

		if (action_mode == ACTION_MODE_BUTTON_PRESS) {

			if (b->is_pressed()) {

				emit_signal("button_down");

				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");
					_unpress_group();

				} else {

					status.pressed = !status.pressed;
					pressed();

					emit_signal("pressed");
					_unpress_group();

					toggled(status.pressed);
					if (get_script_instance()) {
						get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, status.pressed);
					}
					emit_signal("toggled", status.pressed);
				}

			} else {

				emit_signal("button_up");

				/* this is pointless		if (status.press_attempt && status.pressing_inside) {
					//released();
					emit_signal("released");
				}
*/
				status.press_attempt = false;
			}
			update();
			return;
		}

		if (b->is_pressed()) {

			status.press_attempt = true;
			status.pressing_inside = true;
			emit_signal("button_down");

		} else {

			emit_signal("button_up");

			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);
					if (get_script_instance()) {
						get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, status.pressed);
					}
					emit_signal("toggled", status.pressed);
				}

				_unpress_group();
			}

			status.press_attempt = false;
		}

		update();
	}

	Ref<InputEventMouseMotion> mm = p_event;

	if (mm.is_valid()) {
		if (status.press_attempt && status.pressing_button == 0) {
			bool last_press_inside = status.pressing_inside;
			status.pressing_inside = has_point(mm->get_position());
			if (last_press_inside != status.pressing_inside)
				update();
		}
	}

	if (!mm.is_valid() && !b.is_valid()) {

		if (p_event->is_echo()) {
			return;
		}

		if (status.disabled) {
			return;
		}

		if (status.press_attempt && status.pressing_button == 0) {
			return;
		}

		if (p_event->is_action("ui_accept")) {

			if (p_event->is_pressed()) {

				status.pressing_button++;
				status.press_attempt = true;
				status.pressing_inside = true;
				emit_signal("button_down");

			} else if (status.press_attempt) {

				if (status.pressing_button)
					status.pressing_button--;

				if (status.pressing_button)
					return;

				status.press_attempt = false;
				status.pressing_inside = false;

				emit_signal("button_up");

				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);
					if (get_script_instance()) {
						get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, status.pressed);
					}
					emit_signal("toggled", status.pressed);
				}

				_unpress_group();
			}

			accept_event();
			update();
		}
	}
}