Project

General

Profile

Revision 978

added a draw_funcs.c/h, functions need to draw stuff should go there.
added a basic function used to draw robot with x, y, orientation.

View differences:

branches/simulator/projects/simulator/simulator/gui/draw_funcs.h
1
#ifndef __DRAW_FUNCS_H
2
#define __DRAW_FUNCS_H
3

  
4
#include <gtk/gtk.h>
5

  
6
#define PI						3.14159
7
#define ROBOT_DIAMETER			50
8
#define FULL_CIR				23040
9

  
10
void draw_robot(GdkDrawable* drawable, GdkGC* gc, int x, int y, int angle);
11

  
12
#endif
branches/simulator/projects/simulator/simulator/gui/gtk_environment_view.c
8 8
#include <gtk/gtksignal.h>
9 9

  
10 10
#include "gtk_environment_view.h"
11
#include "draw_funcs.h"
11 12

  
12 13
#define ENVIRONMENT_VIEW_MIN_WIDTH		100
13 14
#define ENVIRONMENT_VIEW_MIN_HEIGHT		50
......
183 184
	
184 185
	view = GTK_ENVIRONMENT_VIEW(widget);
185 186
	
186
	gdk_draw_rectangle(widget->window, widget->style->fg_gc[
187
			GTK_WIDGET_STATE(widget)], 0, 100, 100, 100, 100);
187
//	gdk_draw_rectangle(widget->window, widget->style->fg_gc[
188
//			GTK_WIDGET_STATE(widget)], 0, 100, 100, 100, 100);
188 189

  
189
	gdk_draw_arc(widget->window, 
190
		widget->style->fg_gc[GTK_WIDGET_STATE(widget)], FALSE, 0, 0,
191
		100, 100, 0, 360*64);
190
//	gdk_draw_arc(widget->window, 
191
//		widget->style->fg_gc[GTK_WIDGET_STATE(widget)], FALSE, 0, 0,
192
//		100, 100, 0, 360*64);
193
	draw_robot(widget->window, 
194
		widget->style->fg_gc[GTK_WIDGET_STATE(widget)], 10, 10, 370);
192 195

  
193 196
	return FALSE;
194 197
}
branches/simulator/projects/simulator/simulator/gui/draw_funcs.c
1
#include "draw_funcs.h"
2
#include <stdio.h>
3
#include <math.h>
4

  
5
void draw_robot(GdkDrawable* drawable, GdkGC* gc, int x, int y, int angle) 
6
{
7
	if (!drawable || !gc)
8
		return;
9
	double ang_rad = angle * PI / 180;
10
	int x_c = x - ROBOT_DIAMETER / 2;
11
	int y_c = y - ROBOT_DIAMETER / 2;
12

  
13
	gdk_draw_arc(drawable, gc, FALSE, x_c, y_c, 
14
	  	ROBOT_DIAMETER, ROBOT_DIAMETER, 0, FULL_CIR);
15

  
16
	gdk_draw_line(drawable, gc, x, y, 
17
		x + (ROBOT_DIAMETER - 10) * cos(ang_rad),
18
		y - (ROBOT_DIAMETER - 10) * sin(ang_rad));
19
}
20

  
branches/simulator/projects/simulator/simulator/Makefile
1 1
# Add new files here
2 2
COMMON_SRCS :=
3 3
CORE_SRCS := main.c
4
GUI_SRCS := gtk_gui.c gtk_environment_view.c
4
GUI_SRCS := gtk_gui.c gtk_environment_view.c draw_funcs.c
5 5

  
6 6
CORE_DIR := core
7 7
GUI_DIR := gui

Also available in: Unified diff