void snis_strip_chart_draw(struct strip_chart *sc)
{
	int i, index;
	float x1, y1, x2, y2, w, h, ox, oy;

	sng_set_foreground(sc->color);
	w = sc->width;
	h = sc->height;
	ox = sc->x;
	oy = sc->y;
	sng_current_draw_rectangle(0, ox, oy, w, h);

	x2 = ox;
	y2 = oy;

	for (i = 0; i < sc->history_size; i++) {
		index = (sc->needle + i) % sc->history_size;
		x1 = x2;
		y1 = y2;
		x2 = (w * i) / sc->history_size + ox;
		y2 = oy + h * (255.0 - sc->history[index]) / 255.0;
		sng_current_draw_line(x1, y1, x2, y2);
		sng_abs_xy_draw_string(sc->label, sc->font, ox, oy + h + snis_font_lineheight(sc->font));
	}
	if (sc->warning_on) {
		sng_set_foreground(sc->warn_color);
		sng_abs_xy_draw_string(sc->warning_msg, sc->font, ox + 10, oy + 0.5 * h);
	}
}
Example #2
0
static void draw_help_text(const char *text)
{
	int line = 0;
	int i, y = 70;
	char buffer[256];
	int buflen = 0;
	int helpmodeline = 0;

	strcpy(buffer, "");

	i = 0;
	do {
		if (text[i] == '\n' || text[i] == '\0') {
			if (line >= helpmodeline && line < helpmodeline + 20) {
				buffer[buflen] = '\0';
				sng_abs_xy_draw_string(buffer, TINY_FONT, 60, y);
				y += 19;
				strcpy(buffer, "");
				buflen = 0;
				line++;
				if (text[i] == '\0')
					break;
				i++;
				continue;
			} else {
				if (line >= helpmodeline + 20)
					break;
			}
		}
		buffer[buflen++] = text[i++];
	} while (1);
}
void snis_slider_draw(struct slider *s)
{
	double v;
	float width, tx1;
	int bar_color = DARKGREEN;
	float ptr_height = s->height / 2.0;
	float ptr_width = s->height / 3.0;

	s->timer++;
	if (s->vertical) {
		snis_slider_draw_vertical(s);
		return;
	}
	float f;

	if (s->fuzz) {
		f = (float) ((snis_randn(1000) - 500.0f) * s->fuzz) / 100000.0f;
		f = f * s->length;
	} else {
		f = 0.0f;
	}

	v = s->sample();
	s->value = (v - s->r1) / (s->r2 - s->r1);
	if (s->value == 0)
		f = 0.0f; /* no fuzz if no power */
	v = s->sample();
	bar_color = choose_barcolor(s, v);
	sng_set_foreground(s->color);
	sng_current_draw_rectangle(0, s->x, s->y, s->length, s->height);
	width = s->value * (s->length - 2.0);
	width = width + f;
	if (width < 0.0)
		width = 0;
	if (width > s->length - 2.0)
		width = s->length - 2.0;
	if (!s->clicked)
		sng_set_foreground(bar_color);
	sng_current_draw_rectangle(1, s->x + 1.0, s->y + 1.0, width, s->height - 2.0);
	if (!s->clicked)
		sng_set_foreground(s->color);

	tx1 = (s->input * s->length) + s->x;

	if (s->clicked) {
		sng_current_draw_line(tx1, s->y, tx1 - ptr_width, s->y - ptr_height);
		sng_current_draw_line(tx1, s->y, tx1 + ptr_width, s->y - ptr_height);
		sng_current_draw_line(tx1 - ptr_width, s->y - ptr_height,
						tx1 + ptr_width, s->y - ptr_height); 
		sng_current_draw_line(tx1, s->y + s->height,
				tx1 - ptr_width, s->y + s->height + ptr_height); 
		sng_current_draw_line(tx1, s->y + s->height,
				tx1 + ptr_width, s->y + s->height + ptr_height); 
		sng_current_draw_line(tx1 - ptr_width, s->y + s->height + ptr_height,
				tx1 + ptr_width, s->y + s->height + ptr_height); 
	}
	sng_abs_xy_draw_string(s->label, s->font,
				s->x + s->length + 5.0, s->y + 2.0 * s->height / 3.0);
}
void snis_scaling_strip_chart_draw(struct scaling_strip_chart *sc)
{
	int i, index;
	float x1, y1, x2, y2, w, h, ox, oy;
	char toplabel[20], bottomlabel[20];

	sng_set_foreground(sc->color);
	w = sc->width;
	h = sc->height;
	ox = sc->x;
	oy = sc->y;
	sng_current_draw_rectangle(0, ox, oy, w, h);

	x2 = ox;
	y2 = oy;

	sprintf(toplabel, format_string(sc->top), sc->top);
	sprintf(bottomlabel, format_string(sc->bottom), sc->bottom);

	for (i = 0; i < sc->history_size; i++) {
		index = (sc->needle + i) % sc->history_size;
		if (sc->history[index] > sc->top)
			sc->top = sc->history[index];
		if (sc->history[index] < sc->bottom)
			sc->bottom = sc->history[index];
		x1 = x2;
		y1 = y2;
		x2 = (w * i) / sc->history_size + ox;
		y2 = oy + h * (sc->top - sc->history[index] + sc->bottom) / (sc->top - sc->bottom);
		sng_current_draw_line(x1, y1, x2, y2);
		sng_abs_xy_draw_string(sc->label, sc->font, ox, oy + h + snis_font_lineheight(sc->font));
	}
	sng_abs_xy_draw_string(toplabel, sc->font, ox + w, oy);
	sng_abs_xy_draw_string(bottomlabel, sc->font, ox + w, oy + h);
	if (sc->warning_on) {
		sng_set_foreground(sc->warn_color);
		sng_abs_xy_draw_string(sc->warning_msg, sc->font, ox + 10, oy + 0.5 * h);
	}
}
void sng_abs_xy_draw_string_with_cursor(char *s, int font, float x, float y, int cursor_pos, int cursor_on)
{

	int i;
	float dx;	
	float deltax = 0;

	if (!cursor_on) {
		sng_abs_xy_draw_string(s, font, x, y);
		return;
	}

	for (i = 0; s[i]; i++) {
		if (i == cursor_pos)
			sng_abs_xy_draw_letter(gamefont[font], '_', x + deltax, y);
		dx = (letter_spacing[font]) + sng_abs_xy_draw_letter(gamefont[font], s[i], x + deltax, y);
		deltax += dx;
	}
	if (i == cursor_pos)
		sng_abs_xy_draw_letter(gamefont[font], '_', x + deltax, y);
}
Example #6
0
static void draw_screen()
{
	static double last_frame_time;
	static int frame_index;
	static float frame_rates[FRAME_INDEX_MAX];
	static float frame_times[FRAME_INDEX_MAX];

	double start_time = time_now_double();

	glClearColor(0.0, 0.0, 0.0, 0.0);

	graph_dev_start_frame();

	sng_set_foreground(WHITE);
	sng_abs_xy_draw_string("F1 FOR HELP", NANO_FONT, SCREEN_WIDTH - 100, 10);

	static struct entity_context *cx;
	if (!cx)
		cx = entity_context_new(50, 50);

	if (wireframe != oldwireframe) {
		oldwireframe = wireframe;
		if (wireframe)
			set_renderer(cx, WIREFRAME_RENDERER | BLACK_TRIS);
		else
			set_renderer(cx, FLATSHADING_RENDERER);
	}

	float r = target_mesh->radius / tan(FOV / 3.0); /* 50% size for middle zoom */
	float r_cam = r * lobby_zoom / 255.0;
	
	camera_set_parameters(cx, 0.1f, r * 2.2, SCREEN_WIDTH, SCREEN_HEIGHT, FOV);
	camera_set_pos(cx, r_cam, 0, 0);
	camera_look_at(cx, 0, 0, 0);
	camera_assign_up_direction(cx, 0, 1, 0);

	union vec3 light_pos = { { 1.01 * r, 0, 0 } };
	quat_rot_vec_self(&light_pos, &light_orientation);
	set_lighting(cx, light_pos.v.x, light_pos.v.y, light_pos.v.z);

	calculate_camera_transform(cx);

	struct entity *e = add_entity(cx, target_mesh, 0, 0, 0, WHITE);
	struct entity *ae = NULL;
	if (planet_mode) {
		update_entity_material(e, &planet_material);
		if (draw_atmosphere) {
			ae = add_entity(cx, atmosphere_mesh, 0, 0, 0, WHITE);
			update_entity_scale(ae, 1.03);
			update_entity_material(ae, &atmosphere_material);
		}
	}
	update_entity_orientation(e, &lobby_orientation);

	if (isDraggingLight) {
		union vec3 light_dir = { { 10.75 * r_cam, 0, 0 } };
		quat_rot_vec_self(&light_dir, &light_orientation);
		sng_set_foreground(WHITE);
		render_line(cx, light_dir.v.x, light_dir.v.y, light_dir.v.z, 0, 0, 0);

		e = add_entity(cx, light_mesh, light_dir.v.x, light_dir.v.y, light_dir.v.z, WHITE);
	} else {
		e = add_entity(cx, light_mesh, light_pos.v.x, light_pos.v.y, light_pos.v.z, WHITE);
	}

	render_entities(cx);

	remove_all_entity(cx);

	if (helpmode)
		draw_help_screen(0);

	if (display_frame_stats > 0) {
		float avg_frame_rate = 0;
		float avg_frame_time = 0;
		int i;
		for (i = 0; i < FRAME_INDEX_MAX; i++) {
			avg_frame_rate += frame_rates[i];
			avg_frame_time += frame_times[i];
		}
		avg_frame_rate /= (float)FRAME_INDEX_MAX;
		avg_frame_time /= (float)FRAME_INDEX_MAX;

		sng_set_foreground(WHITE);
		char stat_buffer[30];
		sprintf(stat_buffer, "fps %5.2f", 1.0/avg_frame_rate);
		sng_abs_xy_draw_string(stat_buffer, NANO_FONT, 2, 10);
		sprintf(stat_buffer, "t %0.2f ms", avg_frame_time * 1000.0);
		sng_abs_xy_draw_string(stat_buffer, NANO_FONT, 92, 10);
	}
	if (display_frame_stats > 1)
		graph_dev_display_debug_menu_show();

	graph_dev_end_frame();

	glFinish();

	/*
	 * Swap the buffers. This this tells the driver to
	 * render the next frame from the contents of the
	 * back-buffer, and to set all rendering operations
	 * to occur on what was the front-buffer.
	 *
	 * Double buffering prevents nasty visual tearing
	 * from the application drawing on areas of the
	 * screen that are being updated at the same time.
	 */
	SDL_GL_SwapBuffers();

	if (display_frame_stats > 0) {
		double end_time = time_now_double();

		frame_rates[frame_index] = start_time - last_frame_time;
		frame_times[frame_index] = end_time - start_time;
		frame_index = (frame_index + 1) % FRAME_INDEX_MAX;
		last_frame_time = start_time;
	}
}