Esempio n. 1
0
int BEE::draw_line(int x1, int y1, int x2, int y2, rgba_t color, bool is_hud) {
	return draw_line(x1, y1, x2, y2, get_enum_color(color), is_hud);
}
Esempio n. 2
0
File: main.c Progetto: stuydw/line
int main() {

  screen s;
  color c;
 
  
  c.red = 0;
  c.green = 0;
  c.blue = 0;
  
  clear_screen(s);

  int i, j;

  for (i=0; i < YRES; i++)
    for (j=0; j < XRES; j++ )
      plot(s, c, i, j);
  
  c.green = MAX_COLOR;
  c.blue = MAX_COLOR;
  c.red = MAX_COLOR;

  //too lazy to finish the 2 of hearts

  draw_line(90, 1, 410, 1, s, c);
  draw_line(90, 499, 410, 499, s, c);
  draw_line(90, 1, 90, 499, s, c);
  draw_line(410, 1, 410, 499, s, c);
  draw_line(110, 480, 140, 480, s, c);
  draw_line(140, 480, 140, 460, s, c);
  draw_line(140, 460, 110, 445, s, c);
  draw_line(110, 445, 110, 425, s, c);
  draw_line(110, 425, 140, 425, s, c);

  draw_line(360, 20, 390, 20, s, c);
  draw_line(360, 20, 360, 40, s, c);
  draw_line(360, 40, 390, 55, s, c);
  draw_line(390, 55, 390, 75, s, c);
  draw_line(360, 75, 390, 75, s, c);

  //Note: Display may not work on your system
  //save_ppm and save_extension should be fine
  display(s);
  save_ppm(s, "pic.ppm");
  save_extension(s, "whatevs.png");
}  
Esempio n. 3
0
void draw_default_fixed_cockpit_clock_hands (cockpit_panels panel)
{
	float
		hour_hand_value,
		minute_hand_value,
		second_hand_value,
		x_centre,
		y_centre;

	scale_data
		*hour_hand_scale,
		*minute_hand_scale,
		*second_hand_scale,
		*p;

	if (draw_virtual_cockpit_needles_on_fixed_cockpits)
	{
		return;
	}

	get_clock_hand_values (&hour_hand_value, &minute_hand_value, &second_hand_value);

	switch (panel)
	{
		////////////////////////////////////////
		case COCKPIT_PANEL_DOWN20_AHEAD:
		////////////////////////////////////////
		{
			x_centre = 45.0;

			y_centre = 388.0;

			hour_hand_scale = clock_small_hand_scale_down_20_ahead;

			minute_hand_scale = clock_large_hand_scale_down_20_ahead;

			second_hand_scale = clock_large_hand_scale_down_20_ahead;

			break;
		}
		////////////////////////////////////////
		case COCKPIT_PANEL_DOWN20_LEFT30:
		////////////////////////////////////////
		{
			x_centre = 317.0;

			y_centre = 349.0;

			hour_hand_scale = clock_small_hand_scale_down_20_left_30;

			minute_hand_scale = clock_large_hand_scale_down_20_left_30;

			second_hand_scale = clock_large_hand_scale_down_20_left_30;

			break;
		}
		////////////////////////////////////////
		case COCKPIT_PANEL_DOWN20_LEFT60:
		////////////////////////////////////////
		{
			x_centre = 589.0;

			y_centre = 386.0;

			hour_hand_scale = clock_small_hand_scale_down_20_left_60;

			minute_hand_scale = clock_large_hand_scale_down_20_left_60;

			second_hand_scale = clock_large_hand_scale_down_20_left_60;

			break;
		}
		////////////////////////////////////////
		default:
		////////////////////////////////////////
		{
			debug_fatal (instrument_error);

			break;
		}
	}

	//
	// draw second hand over minute hand over hour hand
	//

	p = find_scale_value (hour_hand_scale, hour_hand_value);

	draw_line (fx_640_480 + x_centre, fy_640_480 + y_centre, fx_640_480 + p->x, fy_640_480 + p->y, white_needle_colour);

	p = find_scale_value (minute_hand_scale, minute_hand_value);

	draw_line (fx_640_480 + x_centre, fy_640_480 + y_centre, fx_640_480 + p->x, fy_640_480 + p->y, white_needle_colour);

	p = find_scale_value (second_hand_scale, second_hand_value);

	draw_line (fx_640_480 + x_centre, fy_640_480 + y_centre, fx_640_480 + p->x, fy_640_480 + p->y, red_needle_colour);

	if (test_cockpit_instruments && DEBUG_MODULE)
	{
		test_scale (minute_hand_scale, 0.0, 55.0, 5.0);

		test_scale (hour_hand_scale, 0.0, 11.0, 1.0);

		set_pixel (ix_640_480 + x_centre, iy_640_480 + y_centre, sys_col_red);
	}
}
/*Hough space

180x120 x-y space to -->

angle
180
| OOOOOOOOOOOOOOOOOOOOOO
| OOOOOOOOOOOOOOOOOOOOOO
| OOOOOOOOOOOOOOOOOOOOOO
| OOOOOOOOOOOOOOOOOOOOOO
--------(diag)--------(diag*2)----->

*/
void hough_lines(U16* buf, U16 threshold_value,
                double resolution, U16 num_line, S16* p_radius, U16* p_theta,d_YUV* d_pixel_value){
	int width = 180, height = 120, r, c, i, j, k;
	U16 diagH = (U16)(sqrt((double)(180*180 + 120*120)));
	U16 diag = diagH*2;
	U16 res_step = (U16)(180/resolution); // In resolution 1, each step has 1 degree.
	U16 num_trans = diag*res_step;
	U16 hough_space[num_trans];
	U16 theta;
	memset(hough_space, 0, num_trans*sizeof(U16));

	for(r = 5; r < height - 5; r++){
	for(c = 5; c < width - 5; c++){

		int distance;
		// At each edge pixels
		if(BLUE_VALUE_IN565(buf[180*r + c]) > threshold_value){
			//printf("selected pixel : y=%d, x=%d\n", r, c);
			for(theta = 0; theta < 180; theta += (U16)resolution){
				distance = (int)(c*mysin(theta) + r*mycos(theta) + diagH + 0.5);
				hough_space[distance*res_step + (U16)(theta/resolution)]++;
			}
		}

	}
	}

	int highest_voted_pixel[6] = {0, 0, 0, 0, 0, 0};
	int highest_voted_pixel_index[6] = {0, 0, 0, 0, 0, 0};

	for(i = 0; i < num_trans; i++){
		if(hough_space[i] >= highest_voted_pixel[0]){
			// push highest_voted_pixel, index array
			for(j = 5; (j >= 0) && (hough_space[i] >= highest_voted_pixel[j]); j--){
				for(k = 1; k < j + 1; k++){
					highest_voted_pixel[k-1] = highest_voted_pixel[k];
					highest_voted_pixel_index[k-1] = highest_voted_pixel_index[k];
				}
				highest_voted_pixel[j] = hough_space[i];
				highest_voted_pixel_index[j] = i;
				break;
			}
		}
	}

	for(i = 0; i < 6; i++){
		p_radius[i] = (S16)(highest_voted_pixel_index[i]/res_step);
		p_theta[i] = (highest_voted_pixel_index[i] - p_radius[i]*res_step)*resolution;
		p_radius[i] -= diagH;
		//printf("line detected. voted : %d, index : %d,  r : %d / theta : %d\n", highest_voted_pixel[i], highest_voted_pixel_index[i], p_radius[i], p_theta[i]);
		//printf("\n");
	}
	float d_Usum=0,d_Vsum=0;
	for(i = 0; i < 6; i++){
		draw_line(buf, p_radius[i], p_theta[i],d_pixel_value);
		printf("each direct%d U_value : %0.3f, V_value : %0.3f\n",i+1,d_pixel_value->u_value,d_pixel_value->v_value);
	}

	/*for(line_count = 0; line_count < num_line; line_count++){
		printf("line no. %d  p_r : %d / p_t : %d\n", line_count, p_radius[line_count], p_theta[line_count]);
	}*/



}
Esempio n. 5
0
int main()
{
	// 8位3通道图像
	image = cvCreateImage( cvSize( IMG_WIDTH, IMG_HEIGHT ), 
		IPL_DEPTH_8U, 3 );
	// 置零
	cvZero(image);
	
	temp = cvCloneImage( image );

	// 创建窗口并设置鼠标事件回调函数
	cvNamedWindow("Drawing");
	cvSetMouseCallback("Drawing", my_mouse_callback, (void*) image );

	while(1)
	{
		cvCopyImage( image, temp );

		switch(g_draw_mode)
		{
			// 画线模式
		case MODE_LINE:
			if(drawing_line)
				draw_line( temp );
			break;
			// 画圆模式
		case MODE_CIRCLE:
			if(drawing_circle)
				draw_circle( temp );
			break;
			// 画椭圆模式
		case MODE_ELLIPSE:
			if(drawing_ellipse)
				draw_ellipse( temp );
			break;
			// 画多边形模式
		case MODE_POLYGON:
			if(drawing_polygon)
				draw_polygon( temp );
			break;
		}
		cvShowImage("Drawing", temp);

		// Esc键退出
		// 对于不同的按键,画不同的图形(线、圆、椭圆、多边形)
		int choose = cvWaitKey(15);
		switch(choose)
		{
			// l-108 L-76
		case 76:
		case 108:
			printf("当前处于画线模式.\n");
			g_draw_mode = MODE_LINE;
			break;
			// c-99 C-67
		case 67:
		case 99:
			printf("当前处于画圆模式.\n");
			g_draw_mode = MODE_CIRCLE;
			break;
			// e-101 E-69
		case 69:
		case 101:
			printf("当前处于画椭圆模式.\n");
			g_draw_mode = MODE_ELLIPSE;
			break;
			// p-112 P-80
		case 80:
		case 112:
			printf("当前处于画多边形模式.\n");
			g_draw_mode = MODE_POLYGON;
			break;
			// Esc 退出
		case 27:
			goto end;
		}
	}

	end:
	// 释放资源
	cvReleaseImage( &image );
	cvReleaseImage( &temp );
	cvDestroyAllWindows();

	return 0;
}
void TextureProgress::_notification(int p_what){
	const float corners[12]={-0.125,-0.375,-0.625,-0.875,0.125,0.375,0.625,0.875,1.125,1.375,1.625,1.875};
	switch(p_what) {

		case NOTIFICATION_DRAW: {


			if (under.is_valid())
				draw_texture(under,Point2());
			if (progress.is_valid()) {
				Size2 s = progress->get_size();
				switch (mode) {
				case FILL_LEFT_TO_RIGHT: {
					Rect2 region=Rect2(Point2(),Size2(s.x*get_unit_value(),s.y));
					draw_texture_rect_region(progress,region,region);
				} break;
				case FILL_RIGHT_TO_LEFT: {
					Rect2 region=Rect2(Point2(s.x-s.x*get_unit_value(),0),Size2(s.x*get_unit_value(),s.y));
					draw_texture_rect_region(progress,region,region);
				} break;
				case FILL_TOP_TO_BOTTOM: {
					Rect2 region=Rect2(Point2(),Size2(s.x,s.y*get_unit_value()));
					draw_texture_rect_region(progress,region,region);
				} break;
				case FILL_BOTTOM_TO_TOP: {
					Rect2 region=Rect2(Point2(0,s.y-s.y*get_unit_value()),Size2(s.x,s.y*get_unit_value()));
					draw_texture_rect_region(progress,region,region);
				} break;
				case FILL_CLOCKWISE:
				case FILL_COUNTER_CLOCKWISE: {
					float val=get_unit_value()*rad_max_degrees/360;
					if (val==1) {
						Rect2 region=Rect2(Point2(),s);
						draw_texture_rect_region(progress,region,region);
					} else if (val!=0) {
						Array pts;
						float direction=mode==FILL_CLOCKWISE?1:-1;
						float start=rad_init_angle/360;
						float end=start+direction*val;
						pts.append(start);
						pts.append(end);
						float from=MIN(start,end);
						float to=MAX(start,end);
						for (int i=0;i<12;i++)
							if (corners[i]>from&&corners[i]<to)
								pts.append(corners[i]);
						pts.sort();
						Vector<Point2> uvs;
						Vector<Point2> points;
						uvs.push_back(get_relative_center());
						points.push_back(Point2(s.x*get_relative_center().x,s.y*get_relative_center().y));
						for (int i=0;i<pts.size();i++) {
							Point2 uv=unit_val_to_uv(pts[i]);
							if (uvs.find(uv)>=0)
								continue;
							uvs.push_back(uv);
							points.push_back(Point2(uv.x*s.x,uv.y*s.y));
						}
						draw_polygon(points,Vector<Color>(),uvs,progress);
					}
					if (get_tree()->is_editor_hint()) {
						Point2 p=progress->get_size();
						p.x*=get_relative_center().x;
						p.y*=get_relative_center().y;
						p=p.floor();
						draw_line(p-Point2(8,0),p+Point2(8,0),Color(0.9,0.5,0.5),2);
						draw_line(p-Point2(0,8),p+Point2(0,8),Color(0.9,0.5,0.5),2);
					}
				} break;
				default:
					draw_texture_rect_region(progress,Rect2(Point2(),Size2(s.x*get_unit_value(),s.y)),Rect2(Point2(),Size2(s.x*get_unit_value(),s.y)));
				}

				
			}
			if (over.is_valid())
				draw_texture(over,Point2());

		} break;
	}
}
 void draw_line (const Vector2d& pos1, const Vector2d& pos2, Color color, int wide = 0)
 {
   draw_line (pos1.x, pos1.y, pos2.x, pos2.y, color, wide);
 }
Esempio n. 8
0
    void rasterizer::draw_triangle(int x0, int y0, int x1, int y1, int x2, int y2,
                                   const color_rgba8& c0, const color_rgba8& c1, const color_rgba8& c2)
    {
        
        int w = surface_->get_width();
        int h = surface_->get_height();
        if ((x0 < 0 || x0 > w) &&
            (y0 < 0 || y0 > h) &&
            (x1 < 0 || x1 > w) &&
            (y1 < 0 || y1 > h) &&
            (x2 < 0 || x2 > w) &&
            (y2 < 0 || y2 > h)) {
            // out of screen space...
            return;
        }
		// 退化为直线的情况
		if (((x0 == x1) && (x1 == x2)) || ((y0 == y1) && (y1 == y2))) {
			draw_line(x0, y0, x1, y1, c0, c1);
			draw_line(x0, y0, x2, y2, c0, c2);
			draw_line(x2, y2, x1, y1, c2, c1);
			return;
		}

		// ensure y0 < y1 < y2
		color_rgba8 tc0 = c0, tc1 = c1, tc2 = c2;
		if (y1 < y0) {// ensure y0 < y1
			std::swap(x0, x1);
			std::swap(y0, y1);
			std::swap(tc0, tc1);
		}
		if (y2 < y0) {// ensure y0 < y2
			std::swap(x0, x2);
			std::swap(y0, y2);
			std::swap(tc0, tc2);
		}
		if (y2 < y1) {// ensure y1 < y2
			std::swap(x1, x2);
			std::swap(y1, y2);
			std::swap(tc1, tc2);
		}

		enum trinagle_type
		{
			general = 0,
			flat_top = 1,
			flat_botton = 2
		};
		trinagle_type tt = general;
		if (y0 == y1) {
			tt = flat_top;
			if (x1 < x0) {
				std::swap(x0, x1);
				std::swap(y0, y1);
				std::swap(tc0, tc1);
			}
		}
		else if (y1 == y2) {
			tt = flat_botton;
			if (x2 < x1) {
				std::swap(x1, x2);
				std::swap(y1, y2);
				std::swap(tc1, tc2);
			}
		} else {
			tt = general;
		}

		float dxdy_left = 0.f;
		float dxdy_right = 0.f;
		float x_left = 0.f, x_right = 0.f;
		int y_start = 0, y_end = 0;
		int x_start = 0, x_end = 0;
		color_rgba8 c_start, c_end;
		color_rgba8 dc_left, dc_right;
		if (tt == general) {
			y_end = y2;
			if (y_end > h) y_end = h;
			int side = 0;
			int ys = y1; //转折点
			float dy_left = 0.f, dy_right = 0.f;
			if (y1 < 0) { //退化为平顶三角形
				//左右边斜率倒数
				dy_left = 1.f / (y2 - y1);
				dxdy_left = (x2 - x1) * dy_left;
				dy_right = 1.f / (y2 - y0);
				dxdy_right = (x2 - x0) * dy_right;
				//左右斜边初始值
				dy_right = -y0;
				dy_left = -y1;
				x_left = dxdy_left * dy_left + x1;
				x_right = dxdy_right * dy_right + x0;
				y_start = 0;
				if (dxdy_right > dxdy_left) {//交换
					std::swap(dxdy_left, dxdy_right);
					std::swap(x_left, x_right);
					std::swap(x1, x2);
					std::swap(y1, y2);
					std::swap(tc1, tc2);
					side = 1;
				}
			} else if (y0 < 0) {
				dy_left = 1.f / (y1 - y0);
				dxdy_left = (x1 - x0) * dy_left;
				dy_right = 1.f / (y2 - y0);
				dxdy_right = (x2 - x0) * dy_right;
				float dy = -y0;
				x_left = dxdy_left * dy + x0;
				x_right = dxdy_right * dy + x0;
				y_start = 0;
				if (dxdy_right < dxdy_left) {
					std::swap(dxdy_left, dxdy_right);
					std::swap(x_left, x_right);
					std::swap(x1, x2);
					std::swap(y1, y2);
					std::swap(tc1, tc2);
					side = 1;
				}
			} else { // y都大于0
				dy_left = 1.f / (y1 - y0);
				dxdy_left = (x1 - x0) * dy_left;
				dc_left = (tc1 - tc0) * dy_left;
				dy_right = 1.f / (y2 - y0);
				dxdy_right = (x2 - x0) * dy_right;
				dc_right = (tc2 - tc0) * dy_right;
				x_left = x0;
				x_right = x0;
				y_start = y0;
				c_start = tc0;
				c_end = tc0;
				if (dxdy_right < dxdy_left) {
					std::swap(dxdy_left, dxdy_right);
					std::swap(x_left, x_right);
					std::swap(x1, x2);
					std::swap(y1, y2);
					std::swap(tc1, tc2);
					//std::swap(c_start, c_end);
					side = 1;
				}
			}
			size_t step_left = 0; size_t step_right = 0;
			float dist_left = 1.f / (ys - y_start);
			float dist_right = 1.f / (y_end - ys);
			float dist_total = 1.f / (y_end - y_start);
			color_rgba8 cs = tc1;
			auto lerp_color = [=, &c_start, &c_end, &cs](size_t& sl, size_t& sr,int yi)
			{
				if (side == 0) {
					if (yi <= ys) {
						c_start = lerp(tc0, tc1, (float)sl * dist_left);
						c_end = lerp(tc0, tc2, (float)sl * dist_total);
						++sl;
					}
					else {
						c_start = lerp(tc1, tc2, (float)sr * dist_right);
						c_end = lerp(cs, tc2, (float)sr * dist_right);
						++sr;
					}
				}
				else {
					if (yi <= ys) {
						c_start = lerp(tc0, tc1, (float)sl * dist_total);
						c_end = lerp(tc0, tc2, (float)sl * dist_left);
						++sl;
					}
					else {
						c_start = lerp(cs, tc1, (float)sr * dist_right);
						c_end = lerp(tc2, tc1, (float)sr * dist_right);
						++sr;
					}
				}
			};
			auto scan_line = [&](bool need_clip_x)
			{
				for (int yi = y_start; yi <= y_end; ++yi) {
					x_start = x_left; x_end = x_right;
					lerp_color(step_left, step_right, yi);
					if (need_clip_x) {
						if (x_start < 0) x_start = 0;
						if (x_end > w) x_end = w;
					}
					draw_line(x_start, yi, x_end, yi, c_start, c_end);
					x_left += dxdy_left;
					x_right += dxdy_right;
					if (yi == ys) { //开始转折
						if (side == 0) {
							dy_left = 1 / (y2 - y1);
							dxdy_left = (x2 - x1) * dy_left;
							x_left = x1;
							x_left += dxdy_left;
							cs = c_end;
						}
						else {
							dy_right = 1.f / (y1 - y2);
							dxdy_right = (x1 - x2) * dy_right;
							x_right = x2;
							x_right += dxdy_right;
							cs = c_start;
						}
					}
				}
			};
			// need clip x
			bool need_clip_x = false;
			if ((x0 < 0) || (x0 > w) ||
				(x1 < 0) || (x1 > w) ||
				(x2 < 0) || (x2 > w)) {
				need_clip_x = true;
			}
			scan_line(need_clip_x);
		} else {
			float dy = 0.f;
			if (tt == flat_top) {
				dy = 1.f / (y2 - y0);
				dxdy_left = (x2 - x0) * dy;
				dxdy_right = (x2 - x1) * dy;
				// clip min y
				if (y0 < 0) {
					dy = -y0;
					x_left = dxdy_left * dy + x0;
					x_right = dxdy_right * dy + x1;
					y_start = 0;
				} else {
					x_left = x0;
					x_right = x1;
					y_start = y0;
					c_start = tc0;
				}
			} else { // flat bottom
				dy = 1.f / (y1 - y0);
				dxdy_left = (x1 - x0) * dy;
				dxdy_right = (x2 - x0) * dy;
				// clip min y
				if (y0 < 0) {
					dy = -y0;
					x_left = dxdy_left * dy + x0;
					x_right = dxdy_right * dy + x1;
					y_start = 0;
				} else {
					x_left = x0;
					x_right = x0;
					y_start = y0;
					c_start = tc0;
				}
			}
			// clip max y
			y_end = y2;
			if (y_end > h) y_end = h;
			int y_index = 0;
			auto scan_line = [&](bool need_clip_x)
			{
				for (y_index = y_start; y_index <= y_end; ++y_index) {
					x_start = x_left;
					x_end = x_right;
					if (need_clip_x) {
						if (x_start < 0) x_start = 0;
						if (x_end > w) x_end = w;
					}
					draw_line(x_start, y_index, x_end, y_index, color_rgba8::black, color_rgba8::black);
					x_left += dxdy_left;
					x_right += dxdy_right;
				}
			};
			bool need_clip_x = false;
			if ((x0 < 0) || (x0 > w) ||
				(x1 < 0) || (x1 > w) ||
				(x2 < 0) || (x2 > w)) { // clip x
				need_clip_x = true;
			}
			scan_line(need_clip_x);
		}
    }
Esempio n. 9
0
File: main.c Progetto: stuydw/line
int main() {

  screen s;
  color c;
 
  
  c.red = 50;
  c.green = 200;
  c.blue = 54;
  
  clear_screen(s);

  int i, j;

  for (i=0; i < YRES; i++)
    for (j=0; j < XRES; j++ )
      plot(s, c, i, j);
  
  c.green = 0;
  c.red = 0;
  c.blue=0;
  //  draw_line(20, 350, 300, 350, s, c); //oct 6
 i = 0;
 for(i;i<100;i++){
    draw_line(i,0,i,500,s,c);
    c.red = c.red +1;
 }
 c.red=0;
 i = 100;
 for(i;i<200;i++){
    draw_line(i,0,i,500,s,c);
    c.red = c.red +1;
 }
c.red=0;
 i = 200;
 for(i;i<300;i++){
    draw_line(i,0,i,500,s,c);
    c.red = c.red +1;
 }
c.red=0;
 i = 300;
 for(i;i<400;i++){
    draw_line(i,0,i,500,s,c);
    c.red = c.red +1;
 }
c.red=0;
 i = 400;
 for(i;i<500;i++){
    draw_line(i,0,i,500,s,c);
    c.red = c.red +1;
 }

 c.red = 255;
 c.green = 255;
 c.blue = 0;

 i = 0;

 for(i;i<100;i++){
    draw_line(i,0,500,500,s,c);
    draw_line(0,i,500,500,s,c);
    draw_line(500-i,0,0,500,s,c);
    draw_line(500,i,0,500,s,c);
 }
 c.red = 0;
 c.green = 0;
    draw_line(0,100,500,500,s,c);
    draw_line(100,0,500,500,s,c);

//Note: Display may not work on your system
  //save_ppm and save_extension should be fine
  //display(s);
  save_ppm(s, "pic.ppm");
  save_extension(s, "whatevs.png");
}  
Esempio n. 10
0
void
setup_screen(const C_SCREEN *scp)
{
	static char	buffer[BUFSIZ];
	int	i, j;
	char	str[3];
	const char *airstr;

	initscr();
	/* size of screen depends on chosen game, but we need at least 80
	 * columns for "Information area" to work. */
	if (LINES < (INPUT_LINES + scp->height) ||
	    COLS < (PLANE_COLS + 2 * scp->width) ||
	    COLS < 80) {
		endwin();
		errx(1, "screen too small.");
	}
	setvbuf(stdout, buffer, _IOFBF, sizeof buffer);
	input = newwin(INPUT_LINES, COLS - PLANE_COLS, LINES - INPUT_LINES, 0);
	credit = newwin(INPUT_LINES, PLANE_COLS, LINES - INPUT_LINES, 
		COLS - PLANE_COLS);
	planes = newwin(LINES - INPUT_LINES, PLANE_COLS, 0, COLS - PLANE_COLS);

	str[2] = '\0';

	if (radar != NULL)
		delwin(radar);
	radar = newwin(scp->height, scp->width * 2, 0, 0);

	if (cleanradar != NULL)
		delwin(cleanradar);
	cleanradar = newwin(scp->height, scp->width * 2, 0, 0);

	/* minus one here to prevent a scroll */
	for (i = 0; i < PLANE_COLS - 1; i++) {
		wmove(credit, 0, i);
		waddch(credit, C_CREDIT);
		wmove(credit, INPUT_LINES - 1, i);
		waddch(credit, C_CREDIT);
	}
	wmove(credit, INPUT_LINES / 2, 1);
	waddstr(credit, AUTHOR_STR);

	for (i = 1; i < scp->height - 1; i++) {
		for (j = 1; j < scp->width - 1; j++) {
			wmove(radar, i, j * 2);
			waddch(radar, C_BACKROUND);
		}
	}

	/*
	 * Draw the lines first, since people like to draw lines
	 * through beacons and exit points.
	 */
	str[0] = C_LINE;
	for (i = 0; i < scp->num_lines; i++) {
		str[1] = ' ';
		draw_line(radar, scp->line[i].p1.x, scp->line[i].p1.y,
			scp->line[i].p2.x, scp->line[i].p2.y, str);
	}

	str[0] = C_TOPBOTTOM;
	str[1] = C_TOPBOTTOM;
	wmove(radar, 0, 0);
	for (i = 0; i < scp->width - 1; i++)
		waddstr(radar, str);
	waddch(radar, C_TOPBOTTOM);

	str[0] = C_TOPBOTTOM;
	str[1] = C_TOPBOTTOM;
	wmove(radar, scp->height - 1, 0);
	for (i = 0; i < scp->width - 1; i++)
		waddstr(radar, str);
	waddch(radar, C_TOPBOTTOM);

	for (i = 1; i < scp->height - 1; i++) {
		wmove(radar, i, 0);
		waddch(radar, C_LEFTRIGHT);
		wmove(radar, i, (scp->width - 1) * 2);
		waddch(radar, C_LEFTRIGHT);
	}

	str[0] = C_BEACON;
	for (i = 0; i < scp->num_beacons; i++) {
		str[1] = '0' + i;
		wmove(radar, scp->beacon[i].y, scp->beacon[i].x * 2);
		waddstr(radar, str);
	}

	for (i = 0; i < scp->num_exits; i++) {
		wmove(radar, scp->exit[i].y, scp->exit[i].x * 2);
		waddch(radar, '0' + i);
	}

	airstr = "^?>?v?<?";
	for (i = 0; i < scp->num_airports; i++) {
		str[0] = airstr[scp->airport[i].dir];
		str[1] = '0' + i;
		wmove(radar, scp->airport[i].y, scp->airport[i].x * 2);
		waddstr(radar, str);
	}
	
	overwrite(radar, cleanradar);
	wrefresh(radar);
	wrefresh(credit);
	fflush(stdout);
}
Esempio n. 11
0
int wiki_trans_line( section_def *section, int alloc_size )
/*********************************************************/
{
    char                *ptr;
    char                *end;
    int                 ch;
    char                *ctx_name;
    char                *ctx_text;
    char                buf[500];
    int                 font_idx;
    int                 line_len;
    bool                term_fix;
    int                 ch_len;
    int                 len;
    char                *file_name;

    /* check for special column 0 stuff first */
    ptr = Line_buf;
    ch = *(unsigned char *)ptr;
    ch_len = 0;
    line_len = 0;

    switch( ch ) {

    case CH_TABXMP:
        if( *skip_blank( ptr + 1 ) == '\0' ) {
            Tab_xmp = FALSE;
            trans_add_str( "</pre>\n", section, &alloc_size );
            Blank_line_sfx = FALSE;     // remove following blanks
        } else {
            read_tabs( ptr + 1 );
            trans_add_str( "<pre>\n", section, &alloc_size );
            Tab_xmp = TRUE;
            Blank_line_pfx = FALSE;     // remove preceding blanks
        }
        return( alloc_size );

    case CH_BOX_ON:
        /* Table support is the closest thing to boxing in IPF, but it
           doesn't work well with changing fonts on items in the tables
           (the edges don't line up). So we draw long lines at the
           top and bottom instead */
        draw_line( section, &alloc_size );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_BOX_OFF:
        draw_line( section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_OLIST_START:
        trans_add_list( "# ", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_LIST_START:
        trans_add_list( "* ", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_DLIST_START:
        trans_add_str( "; ", section, &alloc_size );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_SLIST_START:
        trans_add_list( "* ", section, &alloc_size, ptr );
        Blank_line_pfx = FALSE;
        return( alloc_size );

    case CH_SLIST_END:
        trans_add_str( "\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_OLIST_END:
        trans_add_str( "\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_LIST_END:
        trans_add_str( "\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_DLIST_END:
        trans_add_str( "\n", section, &alloc_size );
        Blank_line_sfx = FALSE;
        return( alloc_size );

    case CH_LIST_ITEM:
    case CH_DLIST_TERM:
        /* eat blank lines before list items and terms */
        Blank_line_pfx = FALSE;
        break;

    case CH_CTX_KW:
        ptr = whole_keyword_line( ptr );
        if( ptr == NULL ) {
            return( alloc_size );
        }
        break;
    }

    if( *skip_blank( ptr ) == '\0' ) {
        /* ignore blanks lines before the topic starts */
        if( !Curr_ctx->empty ) {
            /* the line is completely blank. This tells us to output
               a blank line. BUT, all lists and things automatically
               generate blank lines before they display, so we
               must pend the line */
            Blank_line_pfx = TRUE;
        }
        return( alloc_size );
    }

    /* An explanation of 'Blank_line_pfx': when we hit a blank line,
       we set Blank_line_pfx to TRUE. On the non-tag next line, the
       blank line is generated.
       Some tags automatically generate a blank line, so they
       turn this flag off. This causes the next non-tag line to NOT
       put out the blank line */

    if( Blank_line_pfx || Blank_line_sfx ) {
        line_len += trans_add_str( "\n", section, &alloc_size );
        Blank_line_pfx = FALSE;
    }
    Blank_line_sfx = TRUE;

    /* An explanation of 'Blank_line_sfx': some ending tags automatically
       generate a blank line, so no blank line after them should get
       generated. Normally, this flag is set to TRUE, but ending
       tags and Defn list term tags set this FALSE, so no extra '<P>'
       is generated.
       But, this rule only applies if a blank line immediately
       follows the tag, so its reset here regardless */
#if 0

   if( *ptr != CH_LIST_ITEM && *ptr != CH_DLIST_TERM &&
                                    *ptr != CH_DLIST_DESC && !Tab_xmp ) {
        /* a .br in front of li and dt would generate extra spaces */
        if( ! done_blank )
           line_len += trans_add_str( "<P>", section, &alloc_size );
    }
#endif

    term_fix = FALSE;
    for( ;; ) {
        ch = *(unsigned char *)ptr;
        if( ch == '\0' ) {
            if( term_fix ) {
//              trans_add_str( "</hp2>", section, &alloc_size );
                term_fix = FALSE;
            }
            trans_add_char( '\n', section, &alloc_size );
            break;
        } else if( ch == CH_HLINK || ch == CH_DFN ) {
            Curr_ctx->empty = FALSE;
            /* there are no popups in IPF, so treat them as links */
            ctx_name = ptr + 1;
            ptr = strchr( ptr + 1, ch );
            if( ptr == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ptr = '\0';
            ctx_text = ptr + 1;
            ptr = strchr( ctx_text + 1, ch );
            if( ptr == NULL ) {
              error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ptr = '\0';
            add_link( ctx_name );
            sprintf( buf, "<A HREF=\"#%s\">", ctx_name );
            line_len += trans_add_str( buf, section, &alloc_size );
            line_len += trans_add_str_wiki( ctx_text, section, &alloc_size );
            ch_len += strlen( ctx_text );
            line_len += trans_add_str( "</A>", section, &alloc_size );
            ++ptr;
        } else if( ch == CH_FLINK ) {
            Curr_ctx->empty = FALSE;
            file_name = strchr( ptr + 1, ch );
            if( file_name == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            ctx_name = strchr( file_name + 1, ch );
            if( ctx_name == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            ctx_text = strchr( ctx_name + 1, ch );
            if( ctx_text == NULL ) {
                error( ERR_BAD_LINK_DFN, TRUE );
            }
            *ctx_text = '\0';
            ctx_text = ctx_name + 1;
            *ctx_name = '\0';
            ctx_name = file_name + 1;
            *file_name = '\0';
            file_name = ptr + 1;
            sprintf( buf, "<A HREF=\"#%s\">", ctx_name );
            line_len += trans_add_str( buf, section, &alloc_size );
            line_len += trans_add_str_wiki( ctx_text, section, &alloc_size );
            ch_len += strlen( ctx_text );
            line_len += trans_add_str( "</A>", section, &alloc_size );
            ptr = ctx_text + strlen( ctx_text ) + 1;
        } else if( ch == CH_LIST_ITEM ) {
            /* list item */
            line_len += trans_add_str( "*", section, &alloc_size );
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_DESC ) {
            trans_add_str( ":", section, &alloc_size );
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_TERM ) {
            /* definition list term */
            line_len += trans_add_str( ";", section, &alloc_size );
            term_fix = TRUE;
            ptr = skip_blank( ptr + 1 );
            Blank_line_sfx = FALSE;
        } else if( ch == CH_CTX_KW ) {
            end = strchr( ptr + 1, CH_CTX_KW );
            memcpy( buf, ptr + 1, end - ptr - 1 );
            buf[end - ptr - 1] = '\0';
            add_ctx_keyword( Curr_ctx, buf );
            ptr = end + 1;
            if( *ptr == ' ' ) {
                /* kludge fix cuz of GML: GML thinks that keywords
                   are real words, so it puts a space after them.
                   This should fix that */
                ++ptr;
            }
        } else if( ch == CH_PAR_RESET ) {
            /* this can be ignored for IPF */
            ++ptr;
        } else if( ch == CH_BMP ) {
            Curr_ctx->empty = FALSE;
            ++ptr;
            ch = *(unsigned char *)ptr;
            ptr += 2;
            end = strchr( ptr, CH_BMP );
            *end = '\0';
           // convert filenames to lower case
           strlwr( ptr );
           switch( ch ) {
            case 'i':
                sprintf( buf, "<IMG SRC=\"%s\">", ptr );
                break;

            case 'l':
                sprintf( buf, "<IMG SRC=\"%s\" ALIGN=TOP>", ptr );
                break;

            case 'r':
                sprintf( buf, "<IMG SRC=\"%s\" ALIGN=BOTTOM>", ptr );
                break;

            case 'c':
                sprintf( buf, "<IMG SRC=\"%s\" ALIGN=MIDDLE>", ptr );
                break;
            }
            line_len += trans_add_str( buf, section, &alloc_size );
            ptr = end + 1;
        } else if( ch == CH_FONTSTYLE_START ) {
            ++ptr;
            end = strchr( ptr, CH_FONTSTYLE_START );
            font_idx = 0;
            for( ; ptr != end; ++ptr ) {
                switch( *ptr ) {

                case 'b':
                    font_idx |= FONT_STYLE_BOLD;
                    break;

                case 'i':
                    font_idx |= FONT_STYLE_ITALIC;
                    break;

                case 'u':
                case 's':
                    font_idx |= FONT_STYLE_UNDERLINE;
                    break;
                }
            }
            line_len += trans_add_str( Font_match[ font_idx ], section, &alloc_size );
            Font_list[ Font_list_curr ] = font_idx;
            ++Font_list_curr;
            ++ptr;
        } else if( ch == CH_FONTSTYLE_END ) {
            --Font_list_curr;
            line_len += trans_add_str( Font_end[ Font_list[ Font_list_curr ] ], section, &alloc_size );
            ++ptr;
        } else if( ch == CH_FONTTYPE ) {
            ++ptr;
            end = strchr( ptr, CH_FONTTYPE );
            *end = '\0';

            if( stricmp( ptr, Fonttype_courier ) == 0 ) {
               strcpy( buf, "<tt>" );
            } else {
               /* default system font */
               strcpy( buf, "</tt>" );
            }
            ptr = end + 1;
            end = strchr( ptr, CH_FONTTYPE );
            line_len += trans_add_str( buf, section, &alloc_size );
            ptr = end + 1;
        } else {
            ++ptr;
            Curr_ctx->empty = FALSE;
            if( Tab_xmp && ch == Tab_xmp_char ) {
                len = tab_align( ch_len, section, &alloc_size );
                ch_len += len;
                line_len += len * sizeof( WIKI_SPACE );
                ptr = skip_blank( ptr );
            }
            if( line_len > 120 && ch == ' ' && !Tab_xmp ) {
                /* break onto the next line */
                line_len = 0;
                trans_add_char( '\n', section, &alloc_size );
                if( *ptr == ' ' ) {
                    line_len += trans_add_str( WIKI_SPACE, section, &alloc_size );
                    ++ch_len;
                    ptr++;
                }
            } else {
                line_len += trans_add_char_wiki( ch, *(unsigned char *)ptr, section, &alloc_size );
                ++ch_len;
            }
        }
    }

    return( alloc_size );
}
Esempio n. 12
0
void update_timer(int cycles_gone)
{
    static int collected = 0, vsync_collect = 0, div_collect = 0, redrawed = 0;
    #ifdef ENABLE_LINK
    static int serial_poll_collect = 0;
    #endif
    int hblank_start = 0;

    div_collect += cycles_gone;
    while (div_collect >= 64)
    {
        io_regs->div++;
        div_collect -= cycles_gone;
    }

    if (lcd_on)
    {
        vsync_collect += cycles_gone;

        io_regs->stat &= ~3;
        if (io_regs->ly >= 144)
            io_regs->stat |= 1;
        else
        {
            if (vsync_collect < 51)
                redrawed = 0;
            else if (vsync_collect < 71)
                io_regs->stat |= 2;
            else
            {
                io_regs->stat |= 3;
                if (!redrawed)
                {
                    draw_line(io_regs->ly);
                    redrawed = 1;
                }
            }
        }

        while (vsync_collect >= 114) // Eine Zeile wäre jetzt fertig
        {
            vsync_collect -= 114;

            #ifdef ENABLE_LINK
            if (!link_countdown && (++serial_poll_collect >= 10))
            {
                serial_poll_collect = 0;
                if (server != INVALID_CONN_VALUE)
                    tcp_server_poll(server);
                if (current_connection != INVALID_CONN_VALUE)
                    tcp_conn_poll(current_connection);
            }
            #endif

            hblank_start = 1;
            if (hdma_on)
                hdma_copy_16b();

            if (++io_regs->ly > 153)
                io_regs->ly = 0;
            if (io_regs->ly == 144)
            {
                io_regs->stat &= ~3;
                io_regs->stat |= 1;
                io_regs->int_flag |= INT_VBLANK;
            }

            if (io_regs->lyc == io_regs->ly)
            {
                io_regs->stat |= (1 << 2);
                if (io_regs->stat & (1 << 6))
                    io_regs->int_flag |= INT_LCDC_STAT;
            }
            else
                io_regs->stat &= ~(1 << 2);
        }

        if ((io_regs->stat & (1 << 5)) && ((io_regs->stat & 3) == 2))
            io_regs->int_flag |= INT_LCDC_STAT;
        else if ((io_regs->stat & (1 << 4)) && ((io_regs->stat & 3) == 1))
            io_regs->int_flag |= INT_LCDC_STAT;
        else if ((io_regs->stat & (1 << 3)) && hblank_start)
            io_regs->int_flag |= INT_LCDC_STAT;
    }

    #ifdef ENABLE_LINK
    if (link_countdown)
    {
        link_countdown -= cycles_gone;
        if (link_countdown <= 0)
            link_clock();
    }
    #endif

    if (!(io_regs->tac & (1 << 2)))
        return;

    collected += cycles_gone;
    while (collected >= collect_overflow[io_regs->tac & 3])
    {
        collected -= collect_overflow[io_regs->tac & 3];
        if (!++io_regs->tima)
        {
            io_regs->tima = io_regs->tma;
            io_regs->int_flag |= INT_TIMER;
        }
    }
}
Esempio n. 13
0
void RayCast2D::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			if (enabled && !get_tree()->is_editor_hint())
				set_fixed_process(true);
			else
				set_fixed_process(false);

			if (get_parent()->cast_to<PhysicsBody2D>()) {
				if (exclude_parent_body)
					exclude.insert( get_parent()->cast_to<PhysicsBody2D>()->get_rid() );
				else
					exclude.erase( get_parent()->cast_to<PhysicsBody2D>()->get_rid() );
			}
		} break;
		case NOTIFICATION_EXIT_TREE: {

			if (enabled)
				set_fixed_process(false);

		} break;

		case NOTIFICATION_DRAW: {

			if (!get_tree()->is_editor_hint()  && !get_tree()->is_debugging_collisions_hint())
				break;
			Matrix32 xf;
			xf.rotate(cast_to.angle());
			xf.translate(Vector2(0,cast_to.length()));

			//Vector2 tip = Vector2(0,s->get_length());
			Color dcol=get_tree()->get_debug_collisions_color();//0.9,0.2,0.2,0.4);
			draw_line(Vector2(),cast_to,dcol,3);
			Vector<Vector2> pts;
			float tsize=4;
			pts.push_back(xf.xform(Vector2(0,tsize)));
			pts.push_back(xf.xform(Vector2(0.707*tsize,0)));
			pts.push_back(xf.xform(Vector2(-0.707*tsize,0)));
			Vector<Color> cols;
			for(int i=0;i<3;i++)
				cols.push_back(dcol);

			draw_primitive(pts,cols,Vector<Vector2>()); //small arrow

		} break;


		case NOTIFICATION_FIXED_PROCESS: {

			if (!enabled)
				break;



			Ref<World2D> w2d = get_world_2d();
			ERR_BREAK( w2d.is_null() );

			Physics2DDirectSpaceState *dss = Physics2DServer::get_singleton()->space_get_direct_state(w2d->get_space());
			ERR_BREAK( !dss );

			Matrix32 gt = get_global_transform();

			Vector2 to = cast_to;
			if (to==Vector2())
				to=Vector2(0,0.01);

			Physics2DDirectSpaceState::RayResult rr;

			if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude,layer_mask,type_mask)) {

				collided=true;
				against=rr.collider_id;
				collision_point=rr.position;
				collision_normal=rr.normal;
				against_shape=rr.shape;
			} else {
				collided=false;
			}



		} break;
	}
}
Esempio n. 14
0
int BEE::draw_line(Line l, RGBA color, bool is_hud) {
	return draw_line(l.x1, l.y1, l.x2, l.y2, color, is_hud);
}
Esempio n. 15
0
/*======== void draw_lines() ==========
Inputs:   struct matrix * points
         screen s
         color c 
Returns: 
Go through points 2 at a time and call draw_line to add that line
to the screen
====================*/
void draw_lines( struct matrix * points, screen s, color c) {
  int i;
  for (i = 0; i < points->lastcol - 1; i += 2) {
    draw_line(points->m[0][i], points->m[1][i], points->m[0][i+1], points->m[1][i+1], s, c);
  }
}
Esempio n. 16
0
void draw_tri(FBDev *dev, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t pixel) {
	draw_line(dev, x1, y1, x2, y2, pixel);
	draw_line(dev, x2, y2, x3, y3, pixel);
	draw_line(dev, x3, y3, x1, y1, pixel);
}
Esempio n. 17
0
void CollisionShape2D::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {
			unparenting=false;
		} break;
		case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {

			if (!is_inside_tree())
				break;
			_update_parent();

		} break;
		/*
		case NOTIFICATION_TRANSFORM_CHANGED: {

			if (!is_inside_scene())
				break;
			_update_parent();

		} break;*/
		case NOTIFICATION_DRAW: {

			rect=Rect2();

			Color draw_col=Color(0,0.6,0.7,0.5);

			if (shape->cast_to<LineShape2D>()) {

				LineShape2D *l = shape->cast_to<LineShape2D>();
				Vector2 point = l->get_d() * l->get_normal();

				Vector2 l1[2]={point-l->get_normal().tangent()*100,point+l->get_normal().tangent()*100};
				draw_line(l1[0],l1[1],draw_col,3);
				Vector2 l2[2]={point,point+l->get_normal()*30};
				draw_line(l2[0],l2[1],draw_col,3);
				rect.pos=l1[0];
				rect.expand_to(l1[1]);
				rect.expand_to(l2[0]);
				rect.expand_to(l2[1]);

			} else if (shape->cast_to<SegmentShape2D>()) {

				SegmentShape2D *s = shape->cast_to<SegmentShape2D>();
				draw_line(s->get_a(),s->get_b(),draw_col,3);
				rect.pos=s->get_a();
				rect.expand_to(s->get_b());

			} else if (shape->cast_to<RayShape2D>()) {

				RayShape2D *s = shape->cast_to<RayShape2D>();

				Vector2 tip = Vector2(0,s->get_length());
				draw_line(Vector2(),tip,draw_col,3);
				Vector<Vector2> pts;
				float tsize=4;
				pts.push_back(tip+Vector2(0,tsize));
				pts.push_back(tip+Vector2(0.707*tsize,0));
				pts.push_back(tip+Vector2(-0.707*tsize,0));
				Vector<Color> cols;
				for(int i=0;i<3;i++)
					cols.push_back(draw_col);

				draw_primitive(pts,cols,Vector<Vector2>()); //small arrow

				rect.pos=Vector2();
				rect.expand_to(tip);
				rect=rect.grow(0.707*tsize);

			} else if (shape->cast_to<CircleShape2D>()) {

				CircleShape2D *s = shape->cast_to<CircleShape2D>();
				Vector<Vector2> points;
				for(int i=0;i<24;i++) {

					points.push_back(Vector2(Math::cos(i*Math_PI*2/24.0),Math::sin(i*Math_PI*2/24.0))*s->get_radius());
				}

				draw_colored_polygon(points,draw_col);
				rect.pos=-Point2(s->get_radius(),s->get_radius());
				rect.size=Point2(s->get_radius(),s->get_radius())*2.0;

			} else if (shape->cast_to<RectangleShape2D>()) {

				RectangleShape2D *s = shape->cast_to<RectangleShape2D>();
				Vector2 he = s->get_extents();
				rect=Rect2(-he,he*2.0);
				draw_rect(rect,draw_col);;

			} else if (shape->cast_to<CapsuleShape2D>()) {

				CapsuleShape2D *s = shape->cast_to<CapsuleShape2D>();

				Vector<Vector2> points;
				for(int i=0;i<24;i++) {
					Vector2 ofs = Vector2(0,(i>6 && i<=18) ? -s->get_height()*0.5 : s->get_height()*0.5);

					points.push_back(Vector2(Math::sin(i*Math_PI*2/24.0),Math::cos(i*Math_PI*2/24.0))*s->get_radius() + ofs);
					if (i==6 || i==18)
						points.push_back(Vector2(Math::sin(i*Math_PI*2/24.0),Math::cos(i*Math_PI*2/24.0))*s->get_radius() - ofs);
				}

				draw_colored_polygon(points,draw_col);
				Vector2 he=Point2(s->get_radius(),s->get_radius()+s->get_height()*0.5);
				rect.pos=-he;
				rect.size=he*2.0;

			} else if (shape->cast_to<ConvexPolygonShape2D>()) {

				ConvexPolygonShape2D *s = shape->cast_to<ConvexPolygonShape2D>();

				Vector<Vector2> points = s->get_points();
				for(int i=0;i<points.size();i++) {
					if (i==0)
						rect.pos=points[i];
					else
						rect.expand_to(points[i]);
				}

				draw_colored_polygon(points,draw_col);

			}

			rect=rect.grow(3);

		} break;
		case NOTIFICATION_UNPARENTED: {
			unparenting = true;
			_update_parent();
		} break;
	}

}
Esempio n. 18
0
void draw_polygon(FBDev *dev, int *vx, int *vy, int n, uint32_t pixel) {
	int i;
	for (i = 0; i < n; i++) {
		draw_line(dev, vx[i], vx[(i+1)%n], vy[i], vy[(i+1)%n], pixel);
	}
}
Esempio n. 19
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    int y, i, j;
    int x0, x1, y0, y1, offset, cx, cy;
    unsigned char size, gap;
    char buf[10];

    for (i = -RANGE/2; i <= RANGE/2; i++) {
        y = Y_CENTER - i;
        //j = priv->pitch_deg*SCALE + i;
        j = priv->pitch_deg + i;

        if (j % (MINOR_TICK*SCALE) == 0) {
            if (j == 0) {
                size = 40;
                gap = 10;
            } else {
                if (j % (MAJOR_TICK*SCALE) == 0)
                    size = 20;
                else
                    size = 10;
                gap = 10;
            }

            cx = X_CENTER + (int) (i * priv->sin_roll);
            cy = y + i - (int) (i * priv->cos_roll);

            if ((j != 0) && (j % (MAJOR_TICK*SCALE) == 0)) {
                sprintf(buf, "%d", j / SCALE);
                draw_jstr(buf, cx, cy, JUST_HCENTER | JUST_VCENTER, ca, 0);
            }
            
            offset = (int) gap * priv->cos_roll;
            x0 = cx + offset;
            offset = (int) size * priv->cos_roll;
            x1 = x0 + offset;

            
            offset = (int) gap * priv->sin_roll;
            y0 = cy + offset;
            offset = (int) size * priv->sin_roll;
            y1 = y0 + offset;
            
            if (j == 0) {
                draw_line(x0-1, y0-1, x1+1, y1-1, 3, ca);
                //draw_line(x0, y0-1, x1, y1-1, 1, ca);
            }
            draw_line(x0-1, y0+1, x1+1, y1+1, 3, ca);
            draw_line(x0, y0, x1, y1, 1, ca);

            offset = (int) gap * priv->cos_roll;
            x0 = cx - offset;
            offset = (int) size * priv->cos_roll;
            x1 = x0 - offset;


            offset = (int) gap * priv->sin_roll;
            y0 = cy - offset;
            offset = (int) size * priv->sin_roll;
            y1 = y0 - offset;

            if (j == 0) {
                draw_line(x0-1, y0-1, x1+1, y1-1, 3, ca);
                //draw_line(x0, y0-1, x1, y1-1, 1, ca);
            }
            draw_line(x0-1, y0+1, x1+1, y1+1, 3, ca);
            draw_line(x0, y0, x1, y1, 1, ca);

        }
    }


    draw_ohline(X_CENTER - 3, X_CENTER + 3, Y_CENTER, 1, 3, ca);
    draw_vline(X_CENTER, Y_CENTER - 3, Y_CENTER + 3, 1, ca);

    
    float cos_i, sin_i;

    for (i = -ROLL_RANGE/2; i <= ROLL_RANGE/2; i++) {
        y = Y_CENTER - i;
        //j = priv->pitch_deg*SCALE + i;
        //j = priv->roll_deg + i;

        if (i % (MINOR_ROLL_TICK) == 0) {
            gap = 70;
            if (i == 0) {
                size = 10;
            } else {
                if (i % (MAJOR_ROLL_TICK) == 0)
                    size = 10;
                else
                    size = 5;
            }

            cos_i = cos(DEG2RAD(i));
            sin_i = sin(DEG2RAD(i));
            
            cx = X_CENTER;// + (int) (gap * cos_i);
            cy = Y_CENTER;// - (int) (gap * sin_i);


            offset = (int) gap * cos_i;
            x0 = cx + offset;
            offset = (int) size * cos_i;
            x1 = x0 + offset;


            offset = (int) gap * sin_i;
            y0 = cy - offset;
            offset = (int) size * sin_i;
            y1 = y0 - offset;

            draw_line(x0, y0, x1, y1, 1, ca);

            if ((i != 0) && (i % (MAJOR_ROLL_TICK) == 0)) {
                sprintf(buf, "%d", i);
                draw_jstr(buf, x1, y1, JUST_VCENTER, ca, 0);
            }
        }
    }

    cx = X_CENTER; // + (int) (gap * priv->sin_roll);
    cy = Y_CENTER ; //- (int) (gap * priv->cos_roll);
    size = 10;

    offset = (int) (gap-size) * priv->cos_roll;
    x0 = cx + offset;
    offset = (int) size * priv->cos_roll;
    x1 = x0 + offset;


    offset = (int) (gap-size) * priv->sin_roll;
    y0 = cy + offset;
    offset = (int) size * priv->sin_roll;
    y1 = y0 + offset;


    draw_line(x0-1, y0-1, x1+1, y1-1, 3, ca);
    draw_line(x0-1, y0+1, x1+1, y1+1, 3, ca);
    draw_line(x0, y0, x1, y1, 1, ca);
}
Esempio n. 20
0
void DebugProcessor::draw_line(const Mat4f &transform, const Vec3f &start, const Vec3f &end, const Vec3f &color)
{
  draw_line(transform_point(transform, start), transform_point(transform, end), color);
}
Esempio n. 21
0
void GradientEdit::_notification(int p_what) {

	if (p_what == NOTIFICATION_ENTER_TREE) {
		if (!picker->is_connected("color_changed", this, "_color_changed")) {
			picker->connect("color_changed", this, "_color_changed");
		}
	}
	if (p_what == NOTIFICATION_DRAW) {

		int w = get_size().x;
		int h = get_size().y;

		if (w == 0 || h == 0)
			return; //Safety check. We have division by 'h'. And in any case there is nothing to draw with such size

		int total_w = get_size().width - get_size().height - 3;

		//Draw checker pattern for ramp
		_draw_checker(0, 0, total_w, h);

		//Draw color ramp
		Gradient::Point prev;
		prev.offset = 0;
		if (points.size() == 0)
			prev.color = Color(0, 0, 0); //Draw black rectangle if we have no points
		else
			prev.color = points[0].color; //Extend color of first point to the beginning.

		for (int i = -1; i < points.size(); i++) {

			Gradient::Point next;
			//If there is no next point
			if (i + 1 == points.size()) {
				if (points.size() == 0)
					next.color = Color(0, 0, 0); //Draw black rectangle if we have no points
				else
					next.color = points[i].color; //Extend color of last point to the end.
				next.offset = 1;
			} else {
				next = points[i + 1];
			}

			if (prev.offset == next.offset) {
				prev = next;
				continue;
			}

			Vector<Vector2> points;
			Vector<Color> colors;
			points.push_back(Vector2(prev.offset * total_w, h));
			points.push_back(Vector2(prev.offset * total_w, 0));
			points.push_back(Vector2(next.offset * total_w, 0));
			points.push_back(Vector2(next.offset * total_w, h));
			colors.push_back(prev.color);
			colors.push_back(prev.color);
			colors.push_back(next.color);
			colors.push_back(next.color);
			draw_primitive(points, colors, Vector<Point2>());
			prev = next;
		}

		//Draw point markers
		for (int i = 0; i < points.size(); i++) {

			Color col = i == grabbed ? Color(1, 0.0, 0.0, 0.9) : points[i].color.contrasted();
			col.a = 0.9;

			draw_line(Vector2(points[i].offset * total_w, 0), Vector2(points[i].offset * total_w, h / 2), col);
			draw_rect(Rect2(points[i].offset * total_w - POINT_WIDTH / 2, h / 2, POINT_WIDTH, h / 2), Color(0.6, 0.6, 0.6, i == grabbed ? 0.9 : 0.4));
			draw_line(Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h / 2), Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h - 1), col);
			draw_line(Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h / 2), Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h - 1), col);
			draw_line(Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h / 2), Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h / 2), col);
			draw_line(Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h - 1), Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h - 1), col);
		}

		//Draw "button" for color selector
		_draw_checker(total_w + 3, 0, h, h);
		if (grabbed != -1) {
			//Draw with selection color
			draw_rect(Rect2(total_w + 3, 0, h, h), points[grabbed].color);
		} else {
			//if no color selected draw grey color with 'X' on top.
			draw_rect(Rect2(total_w + 3, 0, h, h), Color(0.5, 0.5, 0.5, 1));
			draw_line(Vector2(total_w + 3, 0), Vector2(total_w + 3 + h, h), Color(1, 1, 1, 0.6));
			draw_line(Vector2(total_w + 3, h), Vector2(total_w + 3 + h, 0), Color(1, 1, 1, 0.6));
		}

		//Draw borders around color ramp if in focus
		if (has_focus()) {

			draw_line(Vector2(-1, -1), Vector2(total_w + 1, -1), Color(1, 1, 1, 0.6));
			draw_line(Vector2(total_w + 1, -1), Vector2(total_w + 1, h + 1), Color(1, 1, 1, 0.6));
			draw_line(Vector2(total_w + 1, h + 1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
			draw_line(Vector2(-1, -1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
		}
	}
}
Esempio n. 22
0
void DebugProcessor::gather_aabb()
{
  auto entities = world().all_entities();
  std::vector<Vec3f> lines;
  lines.reserve(entities.size() * 24);
  const Vec3f color(rgb_to_vec3f(0xdf5a44));

  for (const sptr<Entity> &entity : world().all_entities()) {
    const BoundingBox &box = entity->aabb();
    const Mat4f &t = entity->transform();

    const Vec3f v[] = {
      transform_point(t, Vec3f(box.xmin, box.ymin, box.zmin)),
      transform_point(t, Vec3f(box.xmax, box.ymin, box.zmin)),
      transform_point(t, Vec3f(box.xmax, box.ymax, box.zmin)),
      transform_point(t, Vec3f(box.xmin, box.ymax, box.zmin)),
      transform_point(t, Vec3f(box.xmin, box.ymin, box.zmax)),
      transform_point(t, Vec3f(box.xmax, box.ymin, box.zmax)),
      transform_point(t, Vec3f(box.xmax, box.ymax, box.zmax)),
      transform_point(t, Vec3f(box.xmin, box.ymax, box.zmax)),
    };

    draw_line(v[0], v[1], color);
    draw_line(v[1], v[2], color);
    draw_line(v[2], v[3], color);
    draw_line(v[3], v[0], color);

    draw_line(v[4], v[5], color);
    draw_line(v[5], v[6], color);
    draw_line(v[6], v[7], color);
    draw_line(v[7], v[4], color);

    draw_line(v[0], v[4], color);
    draw_line(v[1], v[5], color);
    draw_line(v[2], v[6], color);
    draw_line(v[3], v[7], color);
  }
}
Esempio n. 23
0
// 鼠标事件回调函数
void my_mouse_callback(int event, int x, int y, int flags, void* param )
{
	IplImage * image = (IplImage * )param;

	switch(event)
	{
		// 鼠标左键按下
	case CV_EVENT_LBUTTONDOWN:
		// 不同模式的选择
		switch(g_draw_mode)
		{
			// 画线模式
		case MODE_LINE:
			drawing_line = true;
			g_Line_startpoint = cvPoint( x, y );
			break;
			// 画圆模式
		case MODE_CIRCLE:
			drawing_circle = true;
			g_Circle_center = cvPoint(x, y);
			break;
			// 画椭圆模式
		case MODE_ELLIPSE:
			drawing_ellipse = true;
			g_ellipse_center = cvPoint(x, y);
			break;
			// 画多边形模式
		case MODE_POLYGON:
			drawing_polygon = true;

			// 构造当前点
			myPoints* pNew;
			pNew = (myPoints*)malloc(sizeof(myPoints));
			pNew->point = cvPoint(x, y);
			pNew->next = NULL;
			// 链表为空
			if( pHead == NULL )
			{
				pHead = pNew;
				pTail = pNew;
			}
			// 链表不空
			else
			{
				pTail->next = pNew;
				pTail = pNew;
			}
			iNumofPoints++;
			break;
		}

		// 鼠标移动
	case CV_EVENT_MOUSEMOVE:
		switch(g_draw_mode)
		{
			// 画线模式
		case MODE_LINE:
			if(drawing_line)
			{
				g_Line_endpoint = cvPoint(x, y);
			}
			break;
			// 画圆模式
		case  MODE_CIRCLE:
			if(drawing_circle)
			{
				g_Circle_radius = getDistanceof2Points( 
					g_Circle_center, cvPoint( x, y ) );
			}
			break;			
			// 画椭圆模式
		case MODE_ELLIPSE:
			if(drawing_ellipse)
			{
				g_ellipse_axes = cvSize( 
					abs( x - g_ellipse_center.x ), 
					abs( y - g_ellipse_center.y ) );
			}
			break;
		}
		break;
	case CV_EVENT_LBUTTONUP:
		switch(g_draw_mode)
		{
			// 画线模式
		case MODE_LINE:
			drawing_line = false;
			draw_line( image );
			g_Line_endpoint = cvPoint(-1, -1);
			break;
			// 画圆模式
		case MODE_CIRCLE:
			drawing_circle = false;
			draw_circle( image );
			g_Circle_radius = -1;
			break;
			// 画椭圆模式
		case MODE_ELLIPSE:
			drawing_ellipse = false;
			draw_ellipse( image );
			g_ellipse_center = cvPoint(-1, -1);
			break;
		}
		break;
		// 右键按下,清除所有图像
	case CV_EVENT_RBUTTONDOWN:
		{
			printf("清除所有图像.\n");
			cvZero( image );

			// 画多边形模式,额外的处理
			if(g_draw_mode == MODE_POLYGON)
			{
				g_polygon_pts[0] = NULL;
				iNumofPoints = 0;
				pHead = pTail = NULL;
				g_polygon_npts = NULL;
			}
		}
		break;
	}
}
Esempio n. 24
0
void ItemList::_notification(int p_what) {

	if (p_what==NOTIFICATION_RESIZED) {
		shape_changed=true;
		update();
	}

	if (p_what==NOTIFICATION_DRAW) {

		VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
		Ref<StyleBox> bg = get_stylebox("bg");

		int mw = scroll_bar->get_minimum_size().x;
		scroll_bar->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,mw+bg->get_margin(MARGIN_RIGHT));
		scroll_bar->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,bg->get_margin(MARGIN_RIGHT));
		scroll_bar->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,bg->get_margin(MARGIN_TOP));
		scroll_bar->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,bg->get_margin(MARGIN_BOTTOM));


		Size2 size = get_size();

		float page = size.height-bg->get_minimum_size().height;
		int width = size.width - mw - bg->get_minimum_size().width;
		scroll_bar->set_page(page);

		draw_style_box(bg,Rect2(Point2(),size));

		int hseparation = get_constant("hseparation");
		int vseparation = get_constant("vseparation");
		int icon_margin = get_constant("icon_margin");
		int line_separation = get_constant("line_separation");

		Ref<StyleBox> sbsel = has_focus()?get_stylebox("selected_focus"):get_stylebox("selected");
		Ref<StyleBox> cursor = has_focus()?get_stylebox("cursor"):get_stylebox("cursor_unfocused");

		Ref<Font> font = get_font("font");
		Color guide_color = get_color("guide_color");
		Color font_color = get_color("font_color");
		Color font_color_selected = get_color("font_color_selected");
		int font_height = font->get_height();
		Vector<int> line_size_cache;
		Vector<int> line_limit_cache;

		if (max_text_lines) {
			line_size_cache.resize(max_text_lines);
			line_limit_cache.resize(max_text_lines);
		}

		if (has_focus()) {
			VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(),true);
			draw_style_box(get_stylebox("bg_focus"),Rect2(Point2(),size));
			VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(),false);
		}

		if (shape_changed) {

			//1- compute item minimum sizes
			for(int i=0;i<items.size();i++) {

				Size2 minsize;
				if (items[i].icon.is_valid()) {

					minsize=items[i].get_icon_size();

					if (min_icon_size.x!=0)
						minsize.x = MAX(minsize.x,min_icon_size.x);
					if (min_icon_size.y!=0)
						minsize.y = MAX(minsize.y,min_icon_size.y);

					if (items[i].text!="") {
						if (icon_mode==ICON_MODE_TOP) {
							minsize.y+=icon_margin;
						} else {
							minsize.x+=icon_margin;
						}
					}
				}

				if (items[i].text!="") {

					Size2 s = font->get_string_size(items[i].text);
					//s.width=MIN(s.width,fixed_column_width);



					if (icon_mode==ICON_MODE_TOP) {
						minsize.x=MAX(minsize.x,s.width);
						if (max_text_lines>0) {
							minsize.y+=(font_height+line_separation)*max_text_lines;
						} else {
							minsize.y+=s.height;
						}

					} else {
						minsize.y=MAX(minsize.y,s.height);
						minsize.x+=s.width;
					}
				}



				items[i].rect_cache.size=minsize;
				if (fixed_column_width>0)
					items[i].rect_cache.size.x=fixed_column_width;

			}

			int fit_size = size.x - bg->get_minimum_size().width - mw;

			//2-attempt best fit
			current_columns = 0x7FFFFFFF;
			if (max_columns>0)
				current_columns=max_columns;


			while(true) {
				//repeat util all fits
				//print_line("try with "+itos(current_columns));
				bool all_fit=true;
				Vector2 ofs;
				int col=0;
				int max_h=0;
				separators.clear();;
				for(int i=0;i<items.size();i++) {

					if (current_columns>1 && items[i].rect_cache.size.width+ofs.x > fit_size) {
						//went past
						current_columns=MAX(col,1);
						all_fit=false;
						break;
					}

					items[i].rect_cache.pos=ofs;
					max_h=MAX(max_h,items[i].rect_cache.size.y);
					ofs.x+=items[i].rect_cache.size.x;
					//print_line("item "+itos(i)+" ofs "+rtos(items[i].rect_cache.size.x));
					if (col>0)
						ofs.x+=hseparation;
					col++;
					if (col==current_columns) {

						if (i<items.size()-1)
							separators.push_back(ofs.y+max_h+vseparation/2);
						ofs.x=0;
						ofs.y+=max_h+vseparation;
						col=0;
						max_h=0;
					}
				}

				if (all_fit) {
					float max = MAX(page,ofs.y+max_h);
					scroll_bar->set_max(max);
					//print_line("max: "+rtos(max)+" page "+rtos(page));
					if (max<=page) {
						scroll_bar->set_val(0);
						scroll_bar->hide();
					} else {
						scroll_bar->show();
					}
					break;
				}
			}


			shape_changed=false;
		}



		Vector2 base_ofs = bg->get_offset();
		base_ofs.y-=int(scroll_bar->get_val());

		Rect2 clip(Point2(),size-bg->get_minimum_size()+Vector2(0,scroll_bar->get_val()));

		for(int i=0;i<items.size();i++) {


			Rect2 rcache = items[i].rect_cache;

			if (!clip.intersects(rcache))
				continue;


			if (current_columns==1) {
				rcache.size.width = width-rcache.pos.x;
			}

			Rect2 r=rcache;
			r.pos+=base_ofs;

			// Use stylebox to dimension potential bg color, even if not selected
			r.pos.x-=sbsel->get_margin(MARGIN_LEFT);
			r.size.x+=sbsel->get_margin(MARGIN_LEFT)+sbsel->get_margin(MARGIN_RIGHT);
			r.pos.y-=sbsel->get_margin(MARGIN_TOP);
			r.size.y+=sbsel->get_margin(MARGIN_TOP)+sbsel->get_margin(MARGIN_BOTTOM);

			if (items[i].selected) {
				draw_style_box(sbsel,r);
			}
			if (items[i].custom_bg.a>0.001) {
				r.pos.x+=2;
				r.size.x-=4;
				r.pos.y+=2;
				r.size.y-=4;
				draw_rect(r,items[i].custom_bg);
			}


			Vector2 text_ofs;
			if (items[i].icon.is_valid()) {

				Size2 icon_size = items[i].get_icon_size();

				Vector2 icon_ofs;
				if (min_icon_size!=Vector2()) {
					icon_ofs = (min_icon_size - icon_size)/2;
				}

				Point2 pos = items[i].rect_cache.pos + icon_ofs + base_ofs;

				if (icon_mode==ICON_MODE_TOP) {

					pos.x += Math::floor((items[i].rect_cache.size.width - icon_size.width)/2);
					text_ofs.y = MAX(icon_size.height, min_icon_size.y) + icon_margin;
				} else {

					pos.y += Math::floor((items[i].rect_cache.size.height - icon_size.height)/2);
					text_ofs.x = MAX(icon_size.width, min_icon_size.x) + icon_margin;
				}

				if (items[i].icon_region.has_no_area())
					draw_texture(items[i].icon, pos);
				else
					draw_texture_rect_region(items[i].icon, Rect2(pos, icon_size), items[i].icon_region);

			}

			if (items[i].tag_icon.is_valid()) {

				draw_texture(items[i].tag_icon,items[i].rect_cache.pos+base_ofs);
			}

			if (items[i].text!="") {

				int max_len=-1;

				Vector2 size = font->get_string_size(items[i].text);
				if (fixed_column_width)
					max_len=fixed_column_width;
				else
					max_len=size.x;

				if (icon_mode==ICON_MODE_TOP && max_text_lines>0) {

					int ss = items[i].text.length();
					float ofs=0;
					int line=0;
					for(int j=0;j<=ss;j++) {

						int cs = j<ss?font->get_char_size(items[i].text[j],items[i].text[j+1]).x:0;
						if (ofs+cs>max_len || j==ss) {
							line_limit_cache[line]=j;
							line_size_cache[line]=ofs;
							line++;
							ofs=0;
							if (line>=max_text_lines)
								break;
						} else {
							ofs+=cs;
						}

					}

					line=0;
					ofs=0;

					text_ofs.y+=font->get_ascent();
					text_ofs=text_ofs.floor();
					text_ofs+=base_ofs;
					text_ofs+=items[i].rect_cache.pos;

					for(int j=0;j<ss;j++) {

						if (j==line_limit_cache[line]) {
							line++;
							ofs=0;
							if (line>=max_text_lines)
								break;
						}
						ofs+=font->draw_char(get_canvas_item(),text_ofs+Vector2(ofs+(max_len-line_size_cache[line])/2,line*(font_height+line_separation)).floor(),items[i].text[j],items[i].text[j+1],items[i].selected?font_color_selected:font_color);
					}

					//special multiline mode
				} else {

					if (fixed_column_width>0)
						size.x=MIN(size.x,fixed_column_width);

					if (icon_mode==ICON_MODE_TOP) {
						text_ofs.x+=(items[i].rect_cache.size.width-size.x)/2;
					} else {
						text_ofs.y+=(items[i].rect_cache.size.height-size.y)/2;
					}

					text_ofs.y+=font->get_ascent();
					text_ofs=text_ofs.floor();
					text_ofs+=base_ofs;
					text_ofs+=items[i].rect_cache.pos;

					draw_string(font,text_ofs,items[i].text,items[i].selected?font_color_selected:font_color,max_len+1);
				}


			}

			if (select_mode==SELECT_MULTI && i==current) {

				Rect2 r=rcache;
				r.pos+=base_ofs;
				draw_style_box(cursor,r);

			}
		}

		for(int i=0;i<separators.size();i++) {
			draw_line(Vector2(bg->get_margin(MARGIN_LEFT),base_ofs.y+separators[i]),Vector2(size.width-bg->get_margin(MARGIN_LEFT),base_ofs.y+separators[i]),guide_color);
		}


		if (ensure_selected_visible && current>=0 && current <=items.size()) {

			Rect2 r = items[current].rect_cache;
			int from = scroll_bar->get_val();
			int to = from + scroll_bar->get_page();

			if (r.pos.y < from) {
				scroll_bar->set_val(r.pos.y);
			} else if (r.pos.y+r.size.y > to) {
				scroll_bar->set_val(r.pos.y+r.size.y - (to-from));
			}


		}

		ensure_selected_visible=false;

	}
}
Esempio n. 25
0
void draw_v_disparity_lines(const BaseGroundPlaneEstimator &ground_plane_estimator,
                            const StereoCameraCalibration &stereo_calibration,
                            const boost::gil::rgb8_view_t &screen_subview)
{


    // draw image center horizontal line --
    {
        const int image_center_y =
                stereo_calibration.get_left_camera_calibration().get_image_center_y();
        draw_line(screen_subview, rgb8_colors::gray,
                  0, image_center_y, screen_subview.width() -1, image_center_y);
    }


    // draw bounds on expected ground plane --
    {
        // plus line -
        draw_v_disparity_line(screen_subview, rgb8_colors::pink,
                              ground_plane_estimator.get_prior_max_v_disparity_line());

        // minus line -
        draw_v_disparity_line(screen_subview, rgb8_colors::pink,
                              ground_plane_estimator.get_prior_min_v_disparity_line());

        { // prior line -
            const GroundPlane &ground_plane_prior = ground_plane_estimator.get_ground_plane_prior();
            const GroundPlaneEstimator::line_t prior_v_disparity_line =
                    ground_plane_estimator.ground_plane_to_v_disparity_line(ground_plane_prior);
            draw_v_disparity_line(screen_subview, rgb8_colors::violet, prior_v_disparity_line);
        }

        if(false)
        {
            const GroundPlane &ground_plane_prior = ground_plane_estimator.get_ground_plane_prior();
            log_debug() << "draw_ground_plane_estimator ground_plane_prior height == "
                        << ground_plane_prior.offset() << " [meters]" << std::endl;
            const float theta = -std::asin(ground_plane_prior.normal()(i_z));
            log_debug() << "draw_ground_plane_estimator ground_plane_prior theta == "
                        << theta << " [radians] == " << (180/M_PI)*theta << " [degrees]" << std::endl;
        }
    }

    // draw estimated ground --
    {
        const GroundPlane &ground_plane_estimate = ground_plane_estimator.get_ground_plane();

        const GroundPlaneEstimator::line_t v_disparity_line =
                ground_plane_estimator.ground_plane_to_v_disparity_line(ground_plane_estimate);

        draw_v_disparity_line(screen_subview, rgb8_colors::yellow, v_disparity_line);

        if(false)
        {
            log_debug() << "ground plane estimate v_disparity_line has " <<
                           "origin == " << v_disparity_line.origin()(0) << " [pixels]"
                           " and direction == " << v_disparity_line.direction()(0) << " [-]" <<
                           std::endl;
        }

    }

    return;
}
Esempio n. 26
0
allocsize ipf_trans_line( section_def *section, allocsize alloc_size )
/********************************************************************/
{
    char                *ptr;
    char                *end;
    int                 ch;
    char                *ctx_name;
    char                *ctx_text;
    char                buf[500];
    int                 font_idx;
    size_t              line_len;
    bool                term_fix;
    size_t              ch_len;
    size_t              len;
    char                *file_name;

    /* check for special column 0 stuff first */
    ptr = Line_buf;
    ch = *(unsigned char *)ptr;
    ch_len = 0;
    line_len = 0;

    switch( ch ) {
    case CH_TABXMP:
        if( *skip_blank( ptr + 1 ) == '\0' ) {
            Tab_xmp = false;
            trans_add_str( ":exmp.\n", section, &alloc_size );
            Blank_line_sfx = false;     // remove following blanks
        } else {
            read_tabs( ptr + 1 );
            trans_add_str( ":xmp.\n", section, &alloc_size );
            Tab_xmp = true;
            Blank_line_pfx = false;     // remove preceding blanks
        }
        return( alloc_size );
    case CH_BOX_ON:
        /* Table support is the closest thing to boxing in IPF, but it
           doesn't work well with changing fonts on items in the tables
           (the edges don't line up). So we draw long lines at the
           top and bottom instead */
        draw_line( section, &alloc_size );
        Blank_line_pfx = false;
        return( alloc_size );
    case CH_BOX_OFF:
        draw_line( section, &alloc_size );
        Blank_line_sfx = false;
        return( alloc_size );
    case CH_OLIST_START:
        trans_add_list( ":ol", section, &alloc_size, ptr );
        Blank_line_pfx = false;
        return( alloc_size );
    case CH_LIST_START:
        trans_add_list( ":ul", section, &alloc_size, ptr );
        Blank_line_pfx = false;
        return( alloc_size );
    case CH_DLIST_START:
        trans_add_str( ":dl break=all tsize=5.\n", section, &alloc_size );
        Blank_line_pfx = false;
        return( alloc_size );
    case CH_SLIST_START:
        trans_add_list( ":sl", section, &alloc_size, ptr );
        Blank_line_pfx = false;
        return( alloc_size );
    case CH_SLIST_END:
        trans_add_str( ":esl.\n", section, &alloc_size );
        Blank_line_sfx = false;
        return( alloc_size );
    case CH_OLIST_END:
        trans_add_str( ":eol.\n", section, &alloc_size );
        Blank_line_sfx = false;
        return( alloc_size );
    case CH_LIST_END:
        trans_add_str( ":eul.\n", section, &alloc_size );
        Blank_line_sfx = false;
        return( alloc_size );
    case CH_DLIST_END:
        trans_add_str( ":edl.\n", section, &alloc_size );
        Blank_line_sfx = false;
        return( alloc_size );
    case CH_LIST_ITEM:
    case CH_DLIST_TERM:
        /* eat blank lines before list items and terms */
        Blank_line_pfx = false;
        break;
    case CH_CTX_KW:
        ptr = whole_keyword_line( ptr );
        if( ptr == NULL ) {
            return( alloc_size );
        }
        break;
    }

    if( *skip_blank( ptr ) == '\0' ) {
        /* ignore blanks lines before the topic starts */
        if( !Curr_ctx->empty ) {
            /* the line is completely blank. This tells us to output
               a blank line. BUT, all lists and things automatically
               generate blank lines before they display, so we
               must pend the line */
            Blank_line_pfx = true;
        }
        return( alloc_size );
    }

    /* An explanation of 'Blank_line_pfx': when we hit a blank line,
       we set Blank_line_pfx to true. On the non-tag next line, the
       blank line is generated.
       Some tags automatically generate a blank line, so they
       turn this flag off. This causes the next non-tag line to NOT
       put out the blank line */

    if( Blank_line_pfx ) {
        if( Blank_line_sfx ) {
            line_len += trans_add_str( ".br\n", section, &alloc_size );
        }
        Blank_line_pfx = false;
    }

    /* An explanation of 'Blank_line_sfx': some ending tags automatically
       generate a blank line, so no blank line after them should get
       generated. Normally, this flag is set to true, but ending
       tags and Defn list term tags set this false, so no extra '.br'
       is generated.
       But, this rule only applies if a blank line immediately
       follows the tag, so its reset here regardless */

    Blank_line_sfx = true;

    ch = *(unsigned char *)ptr;
    if( ch != CH_LIST_ITEM && ch != CH_DLIST_TERM && ch != CH_DLIST_DESC && !Tab_xmp ) {
        /* a .br in front of li and dt would generate extra spaces */
        line_len += trans_add_str( ".br\n", section, &alloc_size );
    }

    term_fix = false;
    for( ;; ) {
        ch = *(unsigned char *)ptr;
        if( ch == '\0' ) {
            if( term_fix ) {
                trans_add_str( ":ehp2.", section, &alloc_size );
                term_fix = false;
            }
            trans_add_char( '\n', section, &alloc_size );
            break;
        } else if( ch == CH_HLINK || ch == CH_DFN ) {
            Curr_ctx->empty = false;
            /* there are no popups in IPF, so treat them as links */
            ctx_name = ptr + 1;
            ptr = strchr( ptr + 1, ch );
            if( ptr == NULL ) {
                error( ERR_BAD_LINK_DFN, true );
            }
            *ptr = '\0';
            ctx_text = ptr + 1;
            ptr = strchr( ctx_text + 1, ch );
            if( ptr == NULL ) {
                error( ERR_BAD_LINK_DFN, true );
            }
            *ptr = '\0';
            add_link( ctx_name );
            sprintf( buf, ":link reftype=hd refid=%s.", ctx_name );
            line_len += trans_add_str( buf, section, &alloc_size );
            line_len += trans_add_str_ipf( ctx_text, section, &alloc_size );
            ch_len += strlen( ctx_text );
            line_len += trans_add_str( ":elink.", section, &alloc_size );
            ++ptr;
        } else if( ch == CH_FLINK ) {
            Curr_ctx->empty = false;
            file_name = strchr( ptr + 1, ch );
            if( file_name == NULL ) {
                error( ERR_BAD_LINK_DFN, true );
            }
            ctx_name = strchr( file_name + 1, ch );
            if( ctx_name == NULL ) {
                error( ERR_BAD_LINK_DFN, true );
            }
            ctx_text = strchr( ctx_name + 1, ch );
            if( ctx_text == NULL ) {
                error( ERR_BAD_LINK_DFN, true );
            }
            *ctx_text = '\0';
            ctx_text = ctx_name + 1;
            *ctx_name = '\0';
            ctx_name = file_name + 1;
            *file_name = '\0';
            file_name = ptr + 1;
            sprintf( buf, ":link reftype=launch object='view.exe' "
                          "data='%s %s'.", file_name, ctx_name );
            line_len += trans_add_str( buf, section, &alloc_size );
            line_len += trans_add_str_ipf( ctx_text, section, &alloc_size );
            ch_len += strlen( ctx_text );
            line_len += trans_add_str( ":elink.", section, &alloc_size );
            ptr = ctx_text + strlen( ctx_text ) + 1;
        } else if( ch == CH_LIST_ITEM ) {
            /* list item */
            line_len += trans_add_str( ":li.", section, &alloc_size );
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_DESC ) {
            trans_add_str( ":dd.", section, &alloc_size );
            ptr = skip_blank( ptr + 1 );
        } else if( ch == CH_DLIST_TERM ) {
            /* definition list term */
            ptr = skip_blank( ptr + 1 );
            if( *(unsigned char *)ptr == CH_FONTSTYLE_START ) {  /* avoid nesting */
                line_len += trans_add_str( ":dt.", section, &alloc_size );
                Blank_line_sfx = false;
            } else {
                line_len += trans_add_str( ":dt.:hp2.", section, &alloc_size );
                term_fix = true;
                Blank_line_sfx = false;
            }
        } else if( ch == CH_CTX_KW ) {
            end = strchr( ptr + 1, CH_CTX_KW );
            memcpy( buf, ptr + 1, end - ptr - 1 );
            buf[end - ptr - 1] = '\0';
            add_ctx_keyword( Curr_ctx, buf );
            ptr = end + 1;
            if( *ptr == ' ' ) {
                /* kludge fix cuz of GML: GML thinks that keywords are
                   are real words, so it puts a space after them.
                   This should fix that */
                ++ptr;
            }
        } else if( ch == CH_PAR_RESET ) {
            /* this can be ignored for IPF */
            ++ptr;
        } else if( ch == CH_BMP ) {
            Curr_ctx->empty = false;
            ++ptr;
            ch = *(unsigned char *)ptr;
            ptr += 2;
            end = strchr( ptr, CH_BMP );
            *end = '\0';
            switch( ch ) {
            case 'i':
                sprintf( buf, ":artwork runin name='%s'.", ptr );
                break;
            case 'l':
                sprintf( buf, ":artwork align=left name='%s'.", ptr );
                break;
            case 'r':
                sprintf( buf, ":artwork align=right name='%s'.", ptr );
                break;
            case 'c':
                sprintf( buf, ":artwork align=center name='%s'.", ptr );
                break;
            }
            line_len += trans_add_str( buf, section, &alloc_size );
            ptr = end + 1;
        } else if( ch == CH_FONTSTYLE_START ) {
            ++ptr;
            end = strchr( ptr, CH_FONTSTYLE_START );
            font_idx = 0;
            for( ; ptr != end; ++ptr ) {
                switch( *ptr ) {
                case 'b':
                    font_idx |= FONT_STYLE_BOLD;
                    break;
                case 'i':
                    font_idx |= FONT_STYLE_ITALIC;
                    break;
                case 'u':
                case 's':
                    font_idx |= FONT_STYLE_UNDERLINE;
                    break;
                }
            }
            line_len += trans_add_str( Font_match[font_idx],
                                                section, &alloc_size );
            Font_list[Font_list_curr] = font_idx;
            ++Font_list_curr;
            ++ptr;
        } else if( ch == CH_FONTSTYLE_END ) {
            --Font_list_curr;
            line_len += trans_add_str( Font_end[Font_list[Font_list_curr]],
                                                section, &alloc_size );
            ++ptr;
        } else if( ch == CH_FONTTYPE ) {
            ++ptr;
            end = strchr( ptr, CH_FONTTYPE );
            *end = '\0';
            strcpy( buf, ":font facename=" );

            if( Real_ipf_font ) {
                /* This code supports fonts in the expected
                   manor, but not in the usual IPF way. In IPF, font switching
                   (including sizing) is NEVER done, except to Courier for
                   examples. So, this code is inappropriate */

                if( stricmp( ptr, Fonttype_roman ) == 0 ) {
                    strcat( buf, "'Tms Rmn'" );
                } else if( stricmp( ptr, Fonttype_helv ) == 0 ) {
                    strcat( buf, "Helv" );
                } else {
                    /* Symbol doesn't work,so use courier instead */
                    strcat( buf, "Courier" );
                }
                line_len += trans_add_str( buf, section, &alloc_size );
                ptr = end + 1;
                end = strchr( ptr, CH_FONTTYPE );
                *end = '\0';
                sprintf( buf, " size=%dx10.", atoi( ptr ) );
            } else {
                /* this code turns all font changes to the default system
                   font, except for Courier. This is the normal IPF way */

                strcat( buf, "Courier" );
                if( stricmp( ptr, Fonttype_courier ) == 0 ) {
                    strcat( buf, " size=12x10." );
                } else {
                    /* default system font */
                    strcat( buf, " size=0x0." );
                }
                ptr = end + 1;
                end = strchr( ptr, CH_FONTTYPE );
            }

            line_len += trans_add_str( buf, section, &alloc_size );
            ptr = end + 1;
        } else {
            ++ptr;
            Curr_ctx->empty = false;
            if( Tab_xmp && ch == Tab_xmp_char ) {
                len = tab_align( ch_len, section, &alloc_size );
                ch_len += len;
                line_len += len;
                ptr = skip_blank( ptr );
            } else {
                line_len += trans_add_char_ipf( ch, section, &alloc_size );
                ++ch_len;
            }
            if( line_len > 120 && ch == ' ' && !Tab_xmp ) {
                /* break onto the next line */
                line_len = 0;
                trans_add_char( '\n', section, &alloc_size );
            }
        }
    }

    return( alloc_size );
}
Esempio n. 27
0
void draw_default_fixed_cockpit_barometric_altimeter_needle (cockpit_panels panel)
{
	float
		altimeter_needle_value,
		x_centre,
		y_centre;

	scale_data
		*altimeter_needle_scale,
		*p;

	if (draw_virtual_cockpit_needles_on_fixed_cockpits)
	{
		return;
	}

	altimeter_needle_value = get_barometric_altimeter_needle_value ();

	switch (panel)
	{
		////////////////////////////////////////
		case COCKPIT_PANEL_DOWN20_AHEAD:
		////////////////////////////////////////
		{
			x_centre = 599.0;

			y_centre = 440.0;

			altimeter_needle_scale = barometric_altimeter_needle_scale_down_20_ahead;

			break;
		}
		////////////////////////////////////////
		case COCKPIT_PANEL_DOWN20_RIGHT30:
		////////////////////////////////////////
		{
			x_centre = 333.0;

			y_centre = 393.0;

			altimeter_needle_scale = barometric_altimeter_needle_scale_down_20_right_30;

			break;
		}
		////////////////////////////////////////
		case COCKPIT_PANEL_DOWN20_RIGHT60:
		////////////////////////////////////////
		{
			x_centre = 73.0;

			y_centre = 430.0;

			altimeter_needle_scale = barometric_altimeter_needle_scale_down_20_right_60;

			break;
		}
		////////////////////////////////////////
		default:
		////////////////////////////////////////
		{
			debug_fatal (instrument_error);

			break;
		}
	}

	p = find_scale_value (altimeter_needle_scale, altimeter_needle_value);

	draw_line (fx_640_480 + x_centre, fy_640_480 + y_centre, fx_640_480 + p->x, fy_640_480 + p->y, white_needle_colour);

	if (test_cockpit_instruments && DEBUG_MODULE)
	{
		test_scale (altimeter_needle_scale, 0.0, 900.0, 100.0);

		set_pixel (ix_640_480 + x_centre, iy_640_480 + y_centre, sys_col_red);
	}
}
Esempio n. 28
0
int main() {
    json_t *root;
    json_error_t error;
    root = json_load_file("../test.json", 0, &error);
    if(root == 0){
        printf("ERRO AO LER ARQUIVO, linha %d!\n", error.line);
        return error.line;
    }
    const char * fileName = JSON_getString(root, "fileName");
    printf("O nome do arquivo é: %s\n", fileName); 
    const char * format = JSON_getString(root, "format");
    if(strcmp(format, "png") != 0 && strcmp(format, "pdf") != 0 ){
        printf("Formato: o formato %s não é  suportado!\n", format);
        return 0;
    }
    printf("O formato é: %s\n", JSON_getString(root, "format"));
    const char * name = JSON_getString(root, "name");
    printf("O titulo do grafico é: %s\n", name);
    int width = JSON_getInt(root, "width");
    if(width < 200 || width > 1000){
        printf("Width: medida não suportada!\n");
        return 0;
    }
    printf("Width: %d\n", width);
    int height = JSON_getInt(root, "height");
    if(height < 200 || height > 1000){
        printf("Height: medida não suportada!\n");
        return 0;
    }
    printf("Height: %d\n", height);
    int type = JSON_getInt(root, "type");
    printf("Type: %d\n", type);
    double aux;
    //aux = height/width;
    if(height>width) aux = (width/200);
    else aux = (height/200);   
            
    cairo_surface_t *surface; 
    if(strcmp(format, "png") == 0){
 	    surface =   	
	    cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
    }
    else{
        surface =
        cairo_pdf_surface_create(fileName, width, height);
    }
    cairo_t *context = cairo_create(surface);

    cairo_set_source_rgba(context, 1, 1, 1, 1);
    cairo_rectangle(context, 0, 0, width, height);
    cairo_fill(context);        

    Color pointColor = JSON_getColor(root);
    Point *points = JSON_getPoints(root);
    if(type == 0 || type == 1) create_point(context, points, width, height, type, aux, pointColor); 
    
    if (type==2) {
        draw_area(context, points, width, height, aux, pointColor);
        create_point(context, points, width, height, type, aux, pointColor);
    }
    
    draw_line(context, points, width, height, type, aux, pointColor);
    
    write_text(context, name, width, height, aux, pointColor);

    if(strcmp(JSON_getString(root, "format"), "png") == 0)	cairo_surface_write_to_png(surface, fileName);
    else cairo_show_page(context); 
    	
    cairo_destroy(context);
    cairo_surface_destroy(surface);
    
        
    return 0;
}
Esempio n. 29
0
void trectangle::draw(surface& canvas
		, const game_logic::map_formula_callable& variables)
{
	/**
	 * @todo formulas are now recalculated every draw cycle which is a  bit
	 * silly unless there has been a resize. So to optimize we should use an
	 * extra flag or do the calculation in a separate routine.
	 */
	const unsigned x = x_(variables);
	const unsigned y = y_(variables);
	const unsigned w = w_(variables);
	const unsigned h = h_(variables);

	DBG_GUI_D << "Rectangle: draw from " << x << ',' << y
			<< " width " << w << " height " << h
			<< " canvas size " << canvas->w << ',' << canvas->h << ".\n";

	VALIDATE(
			  static_cast<int>(x) < canvas->w
				&& static_cast<int>(x + w) <= canvas->w
				&& static_cast<int>(y) < canvas->h
				&& static_cast<int>(y + h) <= canvas->h
			, _("Rectangle doesn't fit on canvas."));


	surface_lock locker(canvas);

	// draw the border
	for(unsigned i = 0; i < border_thickness_; ++i) {

		const unsigned left = x + i;
		const unsigned right = left + w - (i * 2) - 1;
		const unsigned top = y + i;
		const unsigned bottom = top + h - (i * 2) - 1;

		// top horizontal (left -> right)
		draw_line(canvas, border_color_, left, top, right, top);

		// right vertical (top -> bottom)
		draw_line(canvas, border_color_, right, top, right, bottom);

		// bottom horizontal (left -> right)
		draw_line(canvas, border_color_, left, bottom, right, bottom);

		// left vertical (top -> bottom)
		draw_line(canvas, border_color_, left, top, left, bottom);
	}

	// The fill_rect_alpha code below fails, can't remember the exact cause
	// so use the slow line drawing method to fill the rect.
	if(fill_color_) {

		const unsigned left = x + border_thickness_;
		const unsigned right = left + w - (2 * border_thickness_) - 1;
		const unsigned top = y + border_thickness_;
		const unsigned bottom = top + h - (2 * border_thickness_);

		for(unsigned i = top; i < bottom; ++i) {

			draw_line(canvas, fill_color_, left, i, right, i);
		}
	}
}
Esempio n. 30
0
int BEE::draw_line(int x1, int y1, int x2, int y2, rgba_t color) {
	return draw_line(x1, y1, x2, y2, get_enum_color(color), false);
}