Esempio n. 1
0
/*
 * Scroll the screen up a line.
 */
void scroll(){
	uint16_t blankCell = get_text_value(' ', WHITE, BLACK);

	// If we are not at the end number of rows, then all we must do is move down by one
	if (main_console.y >= SCREEN_ROWS){
		// Find the new line 1
		uint16_t offset = main_console.y - SCREEN_ROWS + 1;
		memcpy(u8video_memory, u8video_memory + (offset * SCREEN_COLUMNS * 2), (SCREEN_ROWS - offset) * SCREEN_COLUMNS * 2);

		// Clear the last row
		memsetw(video_memory + ((SCREEN_ROWS - offset) * SCREEN_COLUMNS), blankCell, SCREEN_COLUMNS);
		main_console.y = SCREEN_ROWS - 1;
	}
}
Esempio n. 2
0
void console_clear(){
	// Note that we must use short for the pointer so that we can
	// use memsetw.
	uint32_t i=0;

	 // empty text with white text.
	uint16_t blankCell = get_text_value(' ', WHITE, BLACK);

	for (i = 0; i < SCREEN_ROWS; i++)
		memsetw(video_memory + (i * SCREEN_COLUMNS), blankCell, SCREEN_COLUMNS);

	// Clear current console options
	main_console.attributes = get_text_attribute(WHITE, BLACK);
	main_console.x = 0;
	main_console.y = 0;
	update_cursor();
}
Esempio n. 3
0
void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) {

	if (read_only)
		return;

	Ref<InputEventMouseButton> mb = p_event;
	if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) {

		if (mb->is_pressed()) {

			if (updown_offset != -1 && mb->get_position().x > updown_offset) {
				//there is an updown, so use it.
				if (mb->get_position().y < get_size().height / 2) {
					set_value(get_value() + get_step());
				} else {
					set_value(get_value() - get_step());
				}
				return;
			} else {

				grabbing_spinner_attempt = true;
				grabbing_spinner = false;
				grabbing_spinner_mouse_pos = Input::get_singleton()->get_mouse_position();
			}
		} else {

			if (grabbing_spinner_attempt) {

				if (grabbing_spinner) {

					Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
					Input::get_singleton()->warp_mouse_position(grabbing_spinner_mouse_pos);
					update();
				} else {
					Rect2 gr = get_global_rect();
					value_input->set_text(get_text_value());
					value_input->set_position(gr.position);
					value_input->set_size(gr.size);
					value_input->call_deferred("show_modal");
					value_input->call_deferred("grab_focus");
					value_input->call_deferred("select_all");
				}

				grabbing_spinner = false;
				grabbing_spinner_attempt = false;
			}
		}
	}

	Ref<InputEventMouseMotion> mm = p_event;
	if (mm.is_valid()) {

		if (grabbing_spinner_attempt) {

			if (!grabbing_spinner) {
				Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
				grabbing_spinner = true;
			}

			double v = get_value();

			double diff_x = mm->get_relative().x;
			diff_x = Math::pow(ABS(diff_x), 1.8) * SGN(diff_x);
			diff_x *= 0.1;

			v += diff_x * get_step();

			set_value(v);

		} else if (updown_offset != -1) {
			bool new_hover = (mm->get_position().x > updown_offset);
			if (new_hover != hover_updown) {
				hover_updown = new_hover;
				update();
			}
		}
	}

	Ref<InputEventKey> k = p_event;
	if (k.is_valid() && k->is_pressed() && k->is_action("ui_accept")) {
		Rect2 gr = get_global_rect();
		value_input->set_text(get_text_value());
		value_input->set_position(gr.position);
		value_input->set_size(gr.size);
		value_input->call_deferred("show_modal");
		value_input->call_deferred("grab_focus");
		value_input->call_deferred("select_all");
	}
}
Esempio n. 4
0
void EditorSpinSlider::_notification(int p_what) {

	if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_OUT || p_what == MainLoop::NOTIFICATION_WM_FOCUS_OUT) {
		if (grabbing_spinner) {
			Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
			grabbing_spinner = false;
			grabbing_spinner_attempt = false;
		}
	}

	if (p_what == NOTIFICATION_DRAW) {

		updown_offset = -1;

		Ref<StyleBox> sb = get_stylebox("normal", "LineEdit");
		draw_style_box(sb, Rect2(Vector2(), get_size()));
		Ref<Font> font = get_font("font", "LineEdit");

		int avail_width = get_size().width - sb->get_minimum_size().width - sb->get_minimum_size().width;
		avail_width -= font->get_string_size(label).width;
		Ref<Texture> updown = get_icon("updown", "SpinBox");

		if (get_step() == 1) {
			avail_width -= updown->get_width();
		}

		if (has_focus()) {
			Ref<StyleBox> focus = get_stylebox("focus", "LineEdit");
			draw_style_box(focus, Rect2(Vector2(), get_size()));
		}

		String numstr = get_text_value();

		int vofs = (get_size().height - font->get_height()) / 2 + font->get_ascent();

		Color fc = get_color("font_color", "LineEdit");

		int label_ofs = sb->get_offset().x + avail_width;
		draw_string(font, Vector2(label_ofs, vofs), label, fc * Color(1, 1, 1, 0.5));
		draw_string(font, Vector2(sb->get_offset().x, vofs), numstr, fc, avail_width);

		if (get_step() == 1) {
			Ref<Texture> updown = get_icon("updown", "SpinBox");
			int updown_vofs = (get_size().height - updown->get_height()) / 2;
			updown_offset = get_size().width - sb->get_margin(MARGIN_RIGHT) - updown->get_width();
			Color c(1, 1, 1);
			if (hover_updown) {
				c *= Color(1.2, 1.2, 1.2);
			}
			draw_texture(updown, Vector2(updown_offset, updown_vofs), c);
			if (grabber->is_visible()) {
				grabber->hide();
			}
		} else if (!hide_slider) {
			int grabber_w = 4 * EDSCALE;
			int width = get_size().width - sb->get_minimum_size().width - grabber_w;
			int ofs = sb->get_offset().x;
			int svofs = (get_size().height + vofs) / 2 - 1;
			Color c = fc;
			c.a = 0.2;

			draw_rect(Rect2(ofs, svofs + 1, width, 2 * EDSCALE), c);
			int gofs = get_as_ratio() * width;
			c.a = 0.9;
			Rect2 grabber_rect = Rect2(ofs + gofs, svofs + 1, grabber_w, 2 * EDSCALE);
			draw_rect(grabber_rect, c);

			bool display_grabber = (mouse_over_spin || mouse_over_grabber) && !grabbing_spinner;
			if (grabber->is_visible() != display_grabber) {
				if (display_grabber) {
					grabber->show();
				} else {
					grabber->hide();
				}
			}

			if (display_grabber) {
				Ref<Texture> grabber_tex;
				if (mouse_over_grabber) {
					grabber_tex = get_icon("grabber_highlight", "HSlider");
				} else {
					grabber_tex = get_icon("grabber", "HSlider");
				}

				if (grabber->get_texture() != grabber_tex) {
					grabber->set_texture(grabber_tex);
				}

				grabber->set_size(Size2(0, 0));
				grabber->set_position(get_global_position() + grabber_rect.position + grabber_rect.size * 0.5 - grabber->get_size() * 0.5);
				grabber_range = width;
			}
		}
	}

	if (p_what == NOTIFICATION_MOUSE_ENTER) {

		mouse_over_spin = true;
		update();
	}
	if (p_what == NOTIFICATION_MOUSE_EXIT) {

		mouse_over_spin = false;
		update();
	}
}