Example #1
0
static void draw_tile(drawing *dr, game_drawstate *ds, game_state *state,
                      int x, int y, int tile, int flash_colour)
{
    if (tile == 0) {
        draw_rect(dr, x, y, TILE_SIZE, TILE_SIZE,
                  flash_colour);
    } else {
        int coords[6];
        char str[40];

        coords[0] = x + TILE_SIZE - 1;
        coords[1] = y + TILE_SIZE - 1;
        coords[2] = x + TILE_SIZE - 1;
        coords[3] = y;
        coords[4] = x;
        coords[5] = y + TILE_SIZE - 1;
        draw_polygon(dr, coords, 3, COL_LOWLIGHT, COL_LOWLIGHT);

        coords[0] = x;
        coords[1] = y;
        draw_polygon(dr, coords, 3, COL_HIGHLIGHT, COL_HIGHLIGHT);

        draw_rect(dr, x + HIGHLIGHT_WIDTH, y + HIGHLIGHT_WIDTH,
                  TILE_SIZE - 2*HIGHLIGHT_WIDTH, TILE_SIZE - 2*HIGHLIGHT_WIDTH,
                  flash_colour);

        sprintf(str, "%d", tile);
        draw_text(dr, x + TILE_SIZE/2, y + TILE_SIZE/2,
                  FONT_VARIABLE, TILE_SIZE/3, ALIGN_VCENTRE | ALIGN_HCENTRE,
                  COL_TEXT, str);
    }
    draw_update(dr, x, y, TILE_SIZE, TILE_SIZE);
}
Example #2
0
void display()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  if(display_state == clipping)
  {
    glColor3f(1, 0, 0);
    draw_polygon(pol);
    if(rect_visible)
    {
      glColor4f(0, 1, 0, 0.5);
      glRecti(rect_corner_from_x, rect_corner_from_y, rect_corner_to_x, rect_corner_to_y);
    }
    glutSwapBuffers();
  }
  else if(display_state == clipped)
  {
    glColor3f(1, 0, 0);
    draw_polygon(clipped_pol_bottom);
  }
  else if(display_state == drawing_polygon)
  {
    glColor3f(1, 0, 0);
    draw_polygon(pol);
  }
  else
  {
  }
}
Example #3
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[10];
    struct point uav_points[4] = { {0, 0}, {6, 8}, {0, -8}, {-6, 8} };
    struct polygon uav = {
        .len = 4,
        .points = uav_points,
    };
    struct point arrow_points[7] = { {1, -10}, {1, -3}, {4, -4}, {0, 0},
                                     {-4, -4}, {-1, -3}, {-1, -10} };
    struct polygon arrow = {
        .len = 7,
        .points = arrow_points,
    };

    move_polygon(&uav, ca->width >> 1, ca->height >> 1);
    draw_polygon(&uav, 3, ca);
    move_polygon(&uav, -1, -1);
    draw_polygon(&uav, 1, ca);


    move_polygon(&arrow, 0, -11);
    transform_polygon(&arrow, ca->width >> 1, ca->height >> 1, priv->direction - priv->heading);
    draw_polygon(&arrow, 3, ca);
    move_polygon(&arrow, -1, -1);
    draw_polygon(&arrow, 1, ca);

    switch (get_units(w->cfg)) {
        case UNITS_METRIC:
        default:
            sprintf(buf, "%dkm/h", (int) ((priv->speed * 3600) / 1000));
            break;
        case UNITS_IMPERIAL:
            sprintf(buf, "%dmph", (int) ((priv->speed * 3600) * M2MILE));
            break;
        case UNITS_CUSTOM_1:
            sprintf(buf, "%dm/s", (int) (priv->speed));
            break;
        case UNITS_CUSTOM_2:
            sprintf(buf, "%df/s", (int) (priv->speed * M2FEET));
            break;
        case UNITS_CUSTOM_3:
            sprintf(buf, "%dkn", (int) ((priv->speed * 3600 * 1.852) / 1000));
            break;
    }
    draw_str(buf, 0, 0, ca, 0);
}


const struct widget_ops wind_widget_ops = {
    .name = "Wind information",
    .mavname = "WINDINF",
    .id = WIDGET_WIND_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};
Example #4
0
static void render(struct widget *w)
{
    struct home_data *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[50];
    float d, a;
    struct point arrow_points[7] = { {-3, 0}, {-3, -6}, {3, -6}, {3, 0},
                                     {6, 0}, {0, 6}, {-6, 0} };
    struct polygon arrow = {
        .len = 7,
        .points = arrow_points,
    };

    if (priv->lock != HOME_LOCKED) {
        sprintf(buf, "No Home");
        draw_str(buf, 0, 0, ca, 2);
    } else {
        switch (get_units(w->cfg)) {
            case UNITS_METRIC:
            default:
                sprintf(buf, "Alt %dm\nDis %dm\n%d",
                        priv->altitude,
                        (unsigned int) priv->distance,
                        priv->direction);
                break;
            case UNITS_IMPERIAL:
                a = (float) priv->altitude * M2FEET;
                d = (float) priv->distance * M2FEET;
                sprintf(buf, "Alt %df\nDis %df\n%d",
                        (unsigned int) a,
                        (unsigned int) d,
                        priv->direction);
                break;
        }

        draw_str(buf, 0, 0, ca, 1);

        transform_polygon(&arrow, 50, 34, priv->direction + 180);
        draw_polygon(&arrow, 3, ca);
        move_polygon(&arrow, -1, -1);
        draw_polygon(&arrow, 1, ca);
    }
}


const struct widget_ops home_info_widget_ops = {
    .name = "Home info",
    .mavname = "HOMEINF",
    .id = WIDGET_HOME_INFO_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};
Example #5
0
    void SoftwareRendererImp::draw_element(SVGElement* element) {

        // Task 4 (part 1):
        // Modify this to implement the transformation stack

        switch (element->type) {
            case POINT:
                draw_point(static_cast<Point&>(*element));
                break;
            case LINE:
                draw_line(static_cast<Line&>(*element));
                break;
            case POLYLINE:
                draw_polyline(static_cast<Polyline&>(*element));
                break;
            case RECT:
                draw_rect(static_cast<Rect&>(*element));
                break;
            case POLYGON:
                draw_polygon(static_cast<Polygon&>(*element));
                break;
            case ELLIPSE:
                draw_ellipse(static_cast<Ellipse&>(*element));
                break;
            case IMAGE:
                draw_image(static_cast<Image&>(*element));
                break;
            case GROUP:
                draw_group(static_cast<Group&>(*element));
                break;
            default:
                break;
        }

    }
Example #6
0
int
main (void)
{
    display scr;
    polygon p;

    display_create(&scr, 80, 35);
    obj_pol_create(&p, 5);
    srand(time(NULL));

    for (;;)
    {
        obj_pol_add_vertex(&p, 1 + abs(rand() % scr.width-2), 1 + abs(rand() % scr.height-2));
        obj_pol_add_vertex(&p, 1 + abs(rand() % scr.width-2), 1 + abs(rand() % scr.height-2));
        obj_pol_add_vertex(&p, 1 + abs(rand() % scr.width-2), 1 + abs(rand() % scr.height-2));
        obj_pol_add_vertex(&p, 1 + abs(rand() % scr.width-2), 1 + abs(rand() % scr.height-2));
        obj_pol_add_vertex(&p, 1 + abs(rand() % scr.width-2), 1 + abs(rand() % scr.height-2));

        draw_polygon(&scr, &p);

        display_show(&scr);
        display_clear(&scr);
#ifdef _WIN32
        Sleep(150);
#else
        usleep(150000);
#endif
    }
}
Example #7
0
int main(void){
	//tests();
	POLYGON temp;
	assert(get_size(&temp.size_points)==TRUE);
	alloc_points(&temp.max_of_x,&temp.points,temp.size_points);
	temp.segments=create_segments(temp.size_points);
	add_segments(temp.points,temp.segments,temp.size_points);
	draw_polygon(temp);
	triangulal_polygol(temp); 
	printf("Potrzeba %d straznikow\n",coloring_sl(temp.points,temp.segments,temp.size_points));
	print_colors(temp.points,temp.size_points);
	draw_polygon(temp);
	free_segments(temp.segments,temp.size_points);
	free_points(temp.points);
	return EXIT_SUCCESS;
}
Example #8
0
static void set_foreground(GdkColor *color, int status)
{
    int num_app_shells = get_num_shells();
    int i, num;
    GdkPoint *p;

    num = numpoints[status];
    p = polyptr[status];

    for (i = 0; i < num_app_shells; i++) {
        tape_status_widget *ts = &app_shells[i].tape_status;
        if (ts) {
            cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(ts->control));
            if (cr) {
                gdk_cairo_set_source_color(cr, color);
                cairo_translate(cr, 0, (gtk_widget_get_allocated_height(ts->control) - CTRL_HEIGHT) / 2);
                if (num) {
                    draw_polygon(cr, p, num);
                } else {
                    cairo_arc(cr, CTRL_WIDTH / 2, CTRL_HEIGHT / 2, (CTRL_HEIGHT / 2) - 1, 0, 360.0f * (M_PI / 180.0f));
                }
                cairo_fill (cr);
                cairo_destroy(cr);
            }
        }
    }
}
Example #9
0
void draw_triangle(PFBDEV pFbdev, POINT p1, POINT p2, POINT p3, uint8_t r, uint8_t g, uint8_t b)
{
    POINT p[3];
    p[0] = p1;
    p[1] = p2;
    p[2] = p3;
    draw_polygon(pFbdev, 3, p, r, g, b);
}
void ShZshapeManager::draw_shape(const char* content)
{
	if (content == "cube")
	{
		draw_cube();
	}

	if (content == "cylinder")
	{
		draw_cylinder();
	}

	if (content == "pipe")
	{
		draw_pipe();
	}

	if (content == "cone")
	{
		draw_cone();
	}

	if (content == "circle")
	{
		draw_circle();
	}

	if (content == "ring")
	{
		draw_ring();
	}

	if (content == "pyramid")
	{
		draw_pyramid();
	}

	if (content == "triangle")
	{
		draw_triangle();
	}

	if (content == "rectangle")
	{
		draw_rectangle();
	}

	if (content == "polygon")
	{
		draw_polygon();
	}

	if (content == "multigonalStar")
	{
		draw_multigonalStar();
	}
}
Example #11
0
void display(void) {

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  draw_polygon();

  /* execute the drawing commands */
  glFlush();
}
Example #12
0
void ClockDraw::draw_simple_hand(double angle, double len)
{
	Vertex v[] =
	{
		Vertex(-2, 4),
		Vertex(-2, -len - 1),
		Vertex( 2, -len - 1),
		Vertex( 2, 4),

		Vertex(-1, 3),
		Vertex(-1, -len),
		Vertex( 1, -len),
		Vertex( 1, 3)
	};

	std::for_each(v, v+8, Vector_add_rotator(Vertex(30.5, 30.5), angle*M_PI/180));

	draw_polygon(ras, v,   v+4, Color(255, 255, 255));
	draw_polygon(ras, v+4, v+8, Color(255, 128, 128));
}
Example #13
0
void LightOccluder2D::_notification(int p_what) {

	if (p_what==NOTIFICATION_ENTER_CANVAS) {

		VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,get_canvas());
		VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform());
		VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible());

	}
	if (p_what==NOTIFICATION_TRANSFORM_CHANGED) {

		VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform());
	}
	if (p_what==NOTIFICATION_VISIBILITY_CHANGED) {

		VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible());
	}

	if (p_what==NOTIFICATION_DRAW) {

		if (get_tree()->is_editor_hint()) {

			if (occluder_polygon.is_valid()) {

				DVector<Vector2> poly = occluder_polygon->get_polygon();

				if (poly.size()) {
					if (occluder_polygon->is_closed()) {
						Vector<Color> color;
						color.push_back(Color(0,0,0,0.6));
						draw_polygon(Variant(poly),color);
					} else {

						int ps=poly.size();
						DVector<Vector2>::Read r = poly.read();
						for(int i=0;i<ps-1;i++) {

							draw_line(r[i],r[i+1],Color(0,0,0,0.6),3);
						}
					}
				}
			}
		}
	}


	if (p_what==NOTIFICATION_EXIT_CANVAS) {

		VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,RID());
	}


}
Example #14
0
File: draw.c Project: niksaak/dame
int draw_rectangle(Vec pos, double width, double height)
{
  GLdouble cw = width / 2.0;
  GLdouble ch = height / 2.0;
  Vec square[4] = {
    { pos.x + cw, pos.y + ch },
    { pos.x + cw, pos.y - ch },
    { pos.x - cw, pos.y - ch },
    { pos.x - cw, pos.y + ch }
  };

  return draw_polygon(square, 4);
}
Example #15
0
gint button_release_event(GtkWidget *widget,GdkEventButton *event )
{ 
  if (event->state & GDK_BUTTON1_MASK && pixmap != NULL)
    switch(tool)
    {
    case RECT_SEL: select_rectangular_region(widget,event->x,event->y,0);
                   selected++;
                   break;

    case ERASER:  eraser(widget,event->x,event->y);
                  break;

    case LINE:draw_line(widget,event->x,event->y,0);
                break; 


    case BRUSH: paintbrush(widget,event->x,event->y);
                break;

    case SPRAYCAN: spraycan(widget,event->x,event->y);
                break;

    case PENCIL:draw_using_pencil(widget,event->x,event->y);
                break;

    case BUCKET: break;
  


    case POLYLINE: draw_line(widget,event->x,event->y,0);
                   pre_x=last_x=event->x;
                   pre_y=last_y=event->y;
                    break;

    case ELLIPSE: draw_arc(widget,event->x,event->y,0);
                  break;
   
    case POLYGON:
                 draw_polygon(widget,event->x,event->y,0);
                 last_x=event->x;
                 last_y=event->y;
                 lineflag++;  
                 break;

    case RECTANGLE:draw_rectangle(widget,event->x,event->y,0);
                   break;
                   
   
    }
    return TRUE;
}
Example #16
0
File: draw.c Project: niksaak/dame
int draw_square(Vec pos, double side)
{
  GLdouble r = side / 2.0;
  GLdouble x = pos.x;
  GLdouble y = pos.y;
  Vec square[4] = {
    { x + r, y + r },
    { x + r, y - r },
    { x - r, y - r },
    { x - r, y + r }
  };

  return draw_polygon(square, 4);
}
Example #17
0
void GeomDrawBox::draw_geometry(cairo_t *cr, OGRGeometry *geom, double scale, double x, double y, double height)
{
  switch (geom->getGeometryType())
  {
    case wkbPolygon:
      draw_polygon(cr, dynamic_cast<OGRPolygon*>(geom), scale, x, y, height);
      break;
    case wkbMultiPolygon:
      {
        OGRGeometryCollection *geoCollection = dynamic_cast<OGRGeometryCollection*>(geom);
        for (int i = 0; i < geoCollection->getNumGeometries(); ++i)
          draw_geometry(cr, geoCollection->getGeometryRef(i), scale, x, y, height);
      }
      break;
    default:
      log_warning("Can't paint geometry type %s\n", geom->getGeometryName());
      break;
  }
}
Example #18
0
void ColorRampEdit::_draw_checker(int x, int y, int w, int h) {
	//Draw it with polygon to insert UVs for scale
	Vector<Vector2> backPoints;
	backPoints.push_back(Vector2(x, y));
	backPoints.push_back(Vector2(x, y+h));
	backPoints.push_back(Vector2(x+w, y+h));
	backPoints.push_back(Vector2(x+w, y));
	Vector<Color> colorPoints;
	colorPoints.push_back(Color(1, 1, 1, 1));
	colorPoints.push_back(Color(1, 1, 1, 1));
	colorPoints.push_back(Color(1, 1, 1, 1));
	colorPoints.push_back(Color(1, 1, 1, 1));
	Vector<Vector2> uvPoints;
	//Draw checker pattern pixel-perfect and scale it by 2.
	uvPoints.push_back(Vector2(x, y));
	uvPoints.push_back(Vector2(x, y+h*.5f/checker->get_height()));
	uvPoints.push_back(Vector2(x+w*.5f/checker->get_width(), y+h*.5f/checker->get_height()));
	uvPoints.push_back(Vector2(x+w*.5f/checker->get_width(), y));
	draw_polygon(backPoints, colorPoints, uvPoints, checker);
}
Example #19
0
// ディスプレイに変化があった時に呼び出されるコールバック関数。
// 「ディスプレイに変化があった時」は、glutPostRedisplay() で指示する。
void glut_display(){
    glClear(GL_COLOR_BUFFER_BIT); // 今まで画面に描かれていたものを消す
    
    switch(g_display_mode){
        case 1:
            draw_square1();
            break;
        case 2:
            draw_square2();
            break;
        case 3:
            draw_square3();
            break;
        case 4:
            draw_polygon();
            break;
    }
    
    glFlush();     // ここで画面に描画をする
}
Example #20
0
void ClockDraw::draw_floating_tick(double angle)
{
	Vertex tri[3];
	Vertex* v = tri;

	const double xc = 28.5;
	const double yc = 28.5;

	v->x = xc + sin((angle)*M_PI/180) * 25;
	v->y = yc - cos((angle)*M_PI/180) * 25;
	v++;

	v->x = xc + sin((angle+10)*M_PI/180) * 20;
	v->y = yc - cos((angle+10)*M_PI/180) * 20;
	v++;

	v->x = xc + sin((angle-10)*M_PI/180) * 20;
	v->y = yc - cos((angle-10)*M_PI/180) * 20;

	draw_polygon(ras, tri, tri+3, Color(255, 255, 255));
}
Example #21
0
File: draw.c Project: niksaak/dame
int draw_circle(Vec pos, double radius)
{ // drawing algorithm from here: http://slabode.exofire.net/circle_draw.shtml
  static Vec verts[360];
  static const size_t vertc = sizeof verts / sizeof (Vec);
  double theta = 2 * M_PI / vertc;
  double costh = cos(theta);
  double sinth = sin(theta);
  double t;
  double x = radius;
  double y = 0;

  for(int i = 0; i < vertc; i++) {
    verts[i].x = x + pos.x;
    verts[i].y = y + pos.y;

    t = x;
    x = costh * x - sinth * y;
    y = sinth * t + costh * y;
  }

  return draw_polygon(verts, vertc);
}
Example #22
0
static void
fill_polygon(DiaRenderer *self, 
	     Point *points, int num_points, 
	     Color *colour)
{
    WmfRenderer *renderer = WMF_RENDERER (self);

    W32::HBRUSH  hBrush, hBrOld;
    W32::COLORREF rgb = W32COLOR(colour);

    DIAG_NOTE(renderer, "fill_polygon n:%d %f,%f ...\n", 
              num_points, points->x, points->y);

    hBrush = W32::CreateSolidBrush(rgb);
    hBrOld = (W32::HBRUSH)W32::SelectObject(renderer->hFileDC, hBrush);

    draw_polygon(self, points, num_points, NULL);

    W32::SelectObject(renderer->hFileDC, 
                      W32::GetStockObject(HOLLOW_BRUSH) );
    W32::DeleteObject(hBrush);
}
Example #23
0
static void QuadTree_print_internal(FILE *fp, QuadTree q, int level){
  /* dump a quad tree in Mathematica format. */
  SingleLinkedList l, l0;
  real *coord;
  int i, dim;

  if (!q) return;

  draw_polygon(fp, q->dim, q->center, q->width);
  dim = q->dim;
  
  l0 = l = q->l;
  if (l){
    printf(",(*a*) {Red,");
    while (l){
      if (l != l0) printf(",");
      coord = node_data_get_coord(SingleLinkedList_get_data(l));
      fprintf(fp, "(*node %d*) Point[{",  node_data_get_id(SingleLinkedList_get_data(l)));
      for (i = 0; i < dim; i++){
	if (i != 0) printf(",");
	fprintf(fp, "%f",coord[i]);
      }
      fprintf(fp, "}]");
      l = SingleLinkedList_get_next(l);
    }
    fprintf(fp, "}");
  }

  if (q->qts){
    for (i = 0; i < 1<<dim; i++){
      fprintf(fp, ",(*b*){");
      QuadTree_print_internal(fp, q->qts[i], level + 1); 
      fprintf(fp, "}");
    }
  }


}
Example #24
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[10];
    unsigned long d = (unsigned long) priv->home->distance;
    unsigned int r = (w->ca.width/2)-2;
    int x, y;
    int min_increment;
    long i, scale;
    struct point ils_points[5] = { {-4, -6}, {-4, 6}, {0, 10}, {4, 6}, {4, -6} };
    struct polygon ils = {
        .len = 5,
        .points = ils_points,
    };
    struct point uav_points[4] = { {0, 0}, {6, 8}, {0, -8}, {-6, 8} };
    struct polygon uav = {
        .len = 4,
        .points = uav_points,
    };

    struct polygon *p;

    x = (w->ca.width/2)-1;
    y = (w->ca.height/2)-1;


    draw_vline(x, 0, r*2, 2, ca);
    draw_hline(0, r*2, y, 2, ca);

    //draw_circle(x, y, r+1, 3, ca);
    draw_circle(x, y, r  , 2, ca);


    /* auto scale */
    switch (get_units(w->cfg)) {
    default:
    case UNITS_METRIC:
        min_increment = 500;
        scale = ((d / min_increment) + 1) * min_increment;
        sprintf(buf, "%um", (unsigned int) scale);
        break;
    case UNITS_IMPERIAL:
        d *= M2FEET;
        min_increment = 1000;
        scale = ((d / min_increment) + 1) * min_increment;
        if (d > 5000) {
            d = (d * 1000) / MILE2FEET;
            scale /= 1000;
            sprintf(buf, "%umi", (unsigned int) scale);
        } else {
            sprintf(buf, "%uf", (unsigned int) scale);
        }
        break;
    }

    draw_str(buf, 0, 0, ca, 0);

    i = (long) d * r;
    i /= scale;

    switch (w->cfg->props.mode >> 1) {
    case 0:
    default:
        /* radar fixed at uav heading, home moves */
        x += sin(DEG2RAD(priv->home->direction)) * i;
        y -= cos(DEG2RAD(priv->home->direction)) * i;
        transform_polygon(&ils, x, y, priv->stats->launch_heading - priv->heading - 180);
        p = &ils;
        break;
    case 1:
        /* radar always facing north, uav moves */
        x += sin(DEG2RAD(priv->home->uav_bearing)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing)) * i;
        transform_polygon(&uav, x, y, priv->heading);
        p = &uav;
        break;
    case 2:
        /* radar always facing launch direction, uav moves */
        x += sin(DEG2RAD(priv->home->uav_bearing - priv->stats->launch_heading)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing - priv->stats->launch_heading)) * i;
        transform_polygon(&uav, x, y, priv->heading - priv->stats->launch_heading);
        p = &uav;
        break;
    case 3:
        /* testing waypoints */
        /* radar always facing north, uav moves with waypoints */
        if (priv->wp_seq > 0) {
            long i_wp = (long) priv->wp_distance * r;
            i_wp /= scale;
            int x_wp = x, y_wp = y;
            x_wp += sin(DEG2RAD(priv->wp_target_bearing - priv->heading)) * i_wp;
            y_wp -= cos(DEG2RAD(priv->wp_target_bearing - priv->heading)) * i_wp;
            sprintf(buf, "%d", priv->wp_seq);
            draw_str(buf, x_wp, y_wp, ca, 0);
        }
        x += sin(DEG2RAD(priv->home->uav_bearing)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing)) * i;
        transform_polygon(&uav, x, y, priv->heading);
        p = &uav;
        break;
    }

    draw_polygon(p, 3, ca);
    move_polygon(p, -1, -1);
    draw_polygon(p, 1, ca);
}


const struct widget_ops radar_widget_ops = {
    .name = "Radar",
    .mavname = "RADAR",
    .id = WIDGET_RADAR_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};
Example #25
0
static void game_redraw(drawing *dr, game_drawstate *ds,
                        const game_state *oldstate, const game_state *state,
                        int dir, const game_ui *ui,
                        float animtime, float flashtime)
{
    int i, j;
    struct bbox bb = find_bbox(&state->params);
    struct solid *poly;
    const int *pkey, *gkey;
    float t[3];
    float angle;
    int square;

    draw_rect(dr, 0, 0, XSIZE(GRID_SCALE, bb, state->solid),
	      YSIZE(GRID_SCALE, bb, state->solid), COL_BACKGROUND);

    if (dir < 0) {
        const game_state *t;

        /*
         * This is an Undo. So reverse the order of the states, and
         * run the roll timer backwards.
         */
	assert(oldstate);

        t = oldstate;
        oldstate = state;
        state = t;

        animtime = ROLLTIME - animtime;
    }

    if (!oldstate) {
        oldstate = state;
        angle = 0.0;
        square = state->current;
        pkey = state->dpkey;
        gkey = state->dgkey;
    } else {
        angle = state->angle * animtime / ROLLTIME;
        square = state->previous;
        pkey = state->spkey;
        gkey = state->sgkey;
    }
    state = oldstate;

    for (i = 0; i < state->grid->nsquares; i++) {
        int coords[8];

        for (j = 0; j < state->grid->squares[i].npoints; j++) {
            coords[2*j] = ((int)(state->grid->squares[i].points[2*j] * GRID_SCALE)
			   + ds->ox);
            coords[2*j+1] = ((int)(state->grid->squares[i].points[2*j+1]*GRID_SCALE)
			     + ds->oy);
        }

        draw_polygon(dr, coords, state->grid->squares[i].npoints,
                     GET_SQUARE(state, i) ? COL_BLUE : COL_BACKGROUND,
		     COL_BORDER);
    }

    /*
     * Now compute and draw the polyhedron.
     */
    poly = transform_poly(state->solid, state->grid->squares[square].flip,
                          pkey[0], pkey[1], angle);

    /*
     * Compute the translation required to align the two key points
     * on the polyhedron with the same key points on the current
     * face.
     */
    for (i = 0; i < 3; i++) {
        float tc = 0.0;

        for (j = 0; j < 2; j++) {
            float grid_coord;

            if (i < 2) {
                grid_coord =
                    state->grid->squares[square].points[gkey[j]*2+i];
            } else {
                grid_coord = 0.0;
            }

            tc += (grid_coord - poly->vertices[pkey[j]*3+i]);
        }

        t[i] = tc / 2;
    }
    for (i = 0; i < poly->nvertices; i++)
        for (j = 0; j < 3; j++)
            poly->vertices[i*3+j] += t[j];

    /*
     * Now actually draw each face.
     */
    for (i = 0; i < poly->nfaces; i++) {
        float points[8];
        int coords[8];

        for (j = 0; j < poly->order; j++) {
            int f = poly->faces[i*poly->order + j];
            points[j*2] = (poly->vertices[f*3+0] -
                           poly->vertices[f*3+2] * poly->shear);
            points[j*2+1] = (poly->vertices[f*3+1] -
                             poly->vertices[f*3+2] * poly->shear);
        }

        for (j = 0; j < poly->order; j++) {
            coords[j*2] = (int)floor(points[j*2] * GRID_SCALE) + ds->ox;
            coords[j*2+1] = (int)floor(points[j*2+1] * GRID_SCALE) + ds->oy;
        }

        /*
         * Find out whether these points are in a clockwise or
         * anticlockwise arrangement. If the latter, discard the
         * face because it's facing away from the viewer.
         *
         * This would involve fiddly winding-number stuff for a
         * general polygon, but for the simple parallelograms we'll
         * be seeing here, all we have to do is check whether the
         * corners turn right or left. So we'll take the vector
         * from point 0 to point 1, turn it right 90 degrees,
         * and check the sign of the dot product with that and the
         * next vector (point 1 to point 2).
         */
        {
            float v1x = points[2]-points[0];
            float v1y = points[3]-points[1];
            float v2x = points[4]-points[2];
            float v2y = points[5]-points[3];
            float dp = v1x * v2y - v1y * v2x;

            if (dp <= 0)
                continue;
        }

        draw_polygon(dr, coords, poly->order,
                     state->facecolours[i] ? COL_BLUE : COL_BACKGROUND,
		     COL_BORDER);
    }
    sfree(poly);

    draw_update(dr, 0, 0, XSIZE(GRID_SCALE, bb, state->solid),
		YSIZE(GRID_SCALE, bb, state->solid));

    /*
     * Update the status bar.
     */
    {
	char statusbuf[256];

	if (state->completed) {
		strcpy(statusbuf, _("COMPLETED!"));
		strcpy(statusbuf+strlen(statusbuf), " ");
	} else statusbuf[0] = '\0';
	sprintf(statusbuf+strlen(statusbuf), _("Moves: %d"),
		(state->completed ? state->completed : state->movecount));

	status_bar(dr, statusbuf);
    }
}
void SoftwareRendererImp::draw_element( SVGElement* element ) {

  // Task 4 (part 1):
  // Modify this to implement the transformation stack

  //std::cout << element->transform << endl;
  //transform svg elements

  switch(element->type) {
    case POINT:
      {
        transformation =  transformation * (element->transform);
        draw_point(static_cast<Point&>(*element));
        transformation =  transformation * (element->transform.inv());
        break;
      }
    case LINE:
      {
        transformation =  transformation * (element->transform);
        draw_line(static_cast<Line&>(*element));
        transformation =  transformation * (element->transform.inv());
        break;
      }
    case POLYLINE:
      {
        transformation =  transformation * (element->transform);
        draw_polyline(static_cast<Polyline&>(*element));
        transformation =  transformation * (element->transform.inv());
        break;
      }
    case RECT:
      {
        transformation =  transformation * (element->transform);
        draw_rect(static_cast<Rect&>(*element));
        transformation =  transformation * (element->transform.inv());
        break;
      }
    case POLYGON:
      {
        transformation =  transformation * (element->transform);
        draw_polygon(static_cast<Polygon&>(*element));
        transformation =  transformation * (element->transform.inv());
        break;
      }
    case ELLIPSE:
      {
        transformation =  transformation * (element->transform);
        draw_ellipse(static_cast<Ellipse&>(*element));
        transformation =  transformation * (element->transform.inv());
        break;
      }
    case IMAGE:
      {
        transformation =  transformation * (element->transform);
        draw_image(static_cast<Image&>(*element));
        transformation =  transformation * (element->transform.inv());
        break;
      }
    case GROUP:
      {
        transformation =  transformation * (element->transform);
        draw_group(static_cast<Group&>(*element));
        transformation =  transformation * (element->transform.inv());
        break;
      }
    default:
      break;
  }

}
Example #27
0
// Parse the next command.
BOOL WMFUpdateState::parse_next_command(BOOL *primitive)
{
	BOOL fPrimitive = FALSE;
	// Remember the start of the record.
	ST_DEV_POSITION lRecordOffset;
	file.tell(&lRecordOffset);

	// Read the next record.
	METARECORD Record;
	if ((error = file.read(&Record, sizeof(Record)-sizeof(Record.rdParm))) != ERRORCODE_None)
	{
		return FALSE;
	}

//	TRACE("Record %d function: %04x, size: %08lx\n", m_nRecord, Record.rdFunction, Record.rdSize);
	// Process the record.
	switch (Record.rdFunction)
	{
		case 0:
		{
			// End of records. All done.
			return FALSE;
		}
		case META_ESCAPE:
		{
//			short n;
//			file.read(&n, sizeof(n));
//			TRACE("Escape: %x\n", n);
			break;
		}
		case META_SETROP2:
		case META_SETRELABS:
		case META_SETMAPMODE:
		{
//			TRACE("IGNORED Record %d function: %04x, size: %08lx\n", m_nRecord, Record.rdFunction, Record.rdSize);
			break;
		}
		case META_SETTEXTALIGN:
		{
			short nAlign;
			file.read(&nAlign, sizeof(nAlign));
			SetTextAlign(nAlign);
			break;
		}
		case META_SETBKCOLOR:
		{
			COLORREF Color;
			file.read(&Color, sizeof(Color));
			SetBkColor(Color);
			break;
		}
		case META_SETBKMODE:
		{
			short nMode;
			file.read(&nMode, sizeof(nMode));
			SetBkMode(nMode);
			break;
		}
		case META_SETTEXTCOLOR:
		{
			COLORREF Color;
			file.read(&Color, sizeof(Color));
			SetTextColor(Color);
			break;
		}
		case META_SETWINDOWORG:
		{
			// Read the parameter.
			short Parms[2];
			ASSERT(Record.rdSize == 5);
			file.read(Parms, sizeof(Parms));
			m_DCState.m_cpWindowOrg.y = Parms[0];
			m_DCState.m_cpWindowOrg.x = Parms[1];
			NewSourceVars();
			break;
		}
		case META_SETWINDOWEXT:
		{
			// Read the parameter.
			short Parms[2];
			ASSERT(Record.rdSize == 5);
			file.read(Parms, sizeof(Parms));
			m_DCState.m_cpWindowExt.y = Parms[0];
			m_DCState.m_cpWindowExt.x = Parms[1];
			NewSourceVars();
			break;
		}
		case META_CREATEBRUSHINDIRECT:
		{
			CWMFBrushObject* pNewBrush = new CWMFBrushObject;
			file.read(&pNewBrush->m_LogBrush, sizeof(LOGBRUSH16));
			NewObject(pNewBrush);
			break;
		}
		case META_DIBCREATEPATTERNBRUSH:
		{
			CWMFBrushObject* pNewBrush = new CWMFBrushObject;
			pNewBrush->m_LogBrush.lbStyle = BS_SOLID;
			pNewBrush->m_LogBrush.lbColor = RGB(128, 0, 0);
			NewObject(pNewBrush);
			break;
		}
		case META_CREATEPENINDIRECT:
		{
			CWMFPenObject* pNewPen = new CWMFPenObject;
			file.read(&pNewPen->m_LogPen, sizeof(LOGPEN16));
			NewObject(pNewPen);
//			TRACE("New pen - s: %d; w: %d, %d; c: %08lx\n",
//					pNewPen->m_LogPen.lopnStyle,
//					pNewPen->m_LogPen.lopnWidth.x,
//					pNewPen->m_LogPen.lopnWidth.y,
//					pNewPen->m_LogPen.lopnColor);
			break;
		}
		case META_CREATEFONTINDIRECT:
		{
			CWMFFontObject* pNewFont = new CWMFFontObject;
			// Read the data.
			LOGFONT16 lf;
			file.read(&lf, sizeof(LOGFONT16));

			// Translate it over.
			pNewFont->m_LogFont.lfHeight = lf.lfHeight; 
			pNewFont->m_LogFont.lfWidth = lf.lfWidth; 
			pNewFont->m_LogFont.lfEscapement = lf.lfEscapement; 
			pNewFont->m_LogFont.lfOrientation = lf.lfOrientation; 
			pNewFont->m_LogFont.lfWeight = lf.lfWeight;
			// Warning: hard-coded size ahead.
			memcpy(&pNewFont->m_LogFont.lfItalic, &lf.lfItalic, 8 + LF_FACESIZE);

			NewObject(pNewFont);
			break;
		}
		case META_CREATEPALETTE:
		{
			// This is mostly here to make sure the object array stays in sync.
			CWMFPaletteObject* pNewPalette = new CWMFPaletteObject;
			struct
			{
				WORD palVersion;
				WORD palNumEntries;
			} Header;
			file.read(&Header, sizeof(Header));

			// Now we have the header. See how many entries we want.
			if (Header.palVersion == 0x0300)
			{
				int nPaletteSize = sizeof(PALETTEENTRY)*Header.palNumEntries;
				pNewPalette->m_pPalette = (LOGPALETTE*)new BYTE[sizeof(LOGPALETTE) + nPaletteSize - sizeof(PALETTEENTRY)];
				pNewPalette->m_pPalette->palVersion = Header.palVersion;
				pNewPalette->m_pPalette->palNumEntries = Header.palNumEntries;
				file.read(pNewPalette->m_pPalette->palPalEntry, nPaletteSize);
			}

			NewObject(pNewPalette);
			break;
		}
		case META_CREATEREGION:
		{
			// This is mostly here to make sure the object array stays in sync.
			// I don't think there's hope of determining the parms format for
			// this record.
			CWMFRegionObject* pNewRegion = new CWMFRegionObject;
			NewObject(pNewRegion);
			break;
		}
		case META_SELECTPALETTE:
		case META_SELECTOBJECT:
		{
			short nIndex;
			file.read(&nIndex, sizeof(nIndex));
			SelectObject(nIndex);
//			TRACE("SelectObject: %d\n", nIndex);
			break;
		}
		case META_DELETEOBJECT:
		{
			short nIndex;
			file.read(&nIndex, sizeof(nIndex));
			DeleteObject(nIndex);
//			TRACE("DeleteObject: %d\n", nIndex);
			break;
		}
		case META_SETPOLYFILLMODE:
		{
			short nFillMode;
			file.read(&nFillMode, sizeof(nFillMode));
			m_nFillMode = nFillMode;
			break;
		}
		case META_SETSTRETCHBLTMODE:
		{
			short nMode;
			file.read(&nMode, sizeof(nMode));
			SetBltMode(nMode);
			break;
		}
		case META_POLYPOLYGON:
		{
			// Read the number of polygons.
			short nPolygons;
			file.read(&nPolygons, sizeof(nPolygons));
			// Proceed to read counts and points (and draw).
			int* pCounts = NULL;
			POINT* pPoints = NULL;
			TRY
			{
				// Allocate the polygon counts.
				pCounts = new int[nPolygons];
				// Read the polygon counts.
				int nPoints = 0;
				for (int nPolygon = 0; nPolygon < nPolygons; nPolygon++)
				{
					short p;
					file.read(&p, sizeof(p));
					pCounts[nPolygon] = p;
					nPoints += p;
				}
				// Allocate the polygon points.
				pPoints = new POINT[nPoints];
				// Read the polygon points.
				for (int nPoint = 0; nPoint < nPoints; nPoint++)
				{
					short p[2];
					file.read(p, sizeof(p));
					pPoints[nPoint].x = p[0];
					pPoints[nPoint].y = p[1];
				}

				// Draw the polypolygon.
				DrawPolyPolygon(pPoints, pCounts, nPolygons);
			}
			END_TRY
			delete [] pPoints;
			delete [] pCounts;
			fPrimitive = TRUE;
			break;
		}
		case META_POLYGON:
		{
			WORD wCount;
			file.read(&wCount, sizeof(wCount));
			draw_polygon(wCount);
			fPrimitive = TRUE;
			break;
		}
		case META_POLYLINE:
		{
			WORD wCount;
			file.read(&wCount, sizeof(wCount));
			draw_polyline(wCount, TRUE);
			fPrimitive = TRUE;
			break;
		}
		case META_ELLIPSE:
		{
			short Parms[4];
			file.read(Parms, sizeof(Parms));

			// Compute parameters to pass.
			// Parms[3] = left
			// Parms[2] = top
			// Parms[1] = right
			// Parms[0] = bottom

			OUTLINE_POINT center;
			center.x = (short)((int)Parms[3] + (int)Parms[1])/2;
			center.y = (short)((int)Parms[2] + (int)Parms[0])/2;

			short rx = Parms[3] - center.x;
			if (rx < 0) rx = -rx;

			short ry = Parms[2] - center.y;
			if (ry < 0) ry = -ry;

			draw_ellipse(center, rx, ry);
			fPrimitive = TRUE;
			break;
		}
		case META_ROUNDRECT:
		{
			// Cheat for now. Just draw it as a rectangle.
			// Skip the corner radii.
			file.seek(2*sizeof(short), ST_DEV_SEEK_CUR);

			// Fall through to...
		}
		case META_RECTANGLE:
		{
			short Parms[4];
			file.read(Parms, sizeof(Parms));

			// Parms[3] = left
			// Parms[2] = top
			// Parms[1] = right
			// Parms[0] = bottom

			OUTLINE_POINT p0, p1;
			p0.x = Parms[3];
			p0.y = Parms[2];
			p1.x = Parms[1];
			p1.y = Parms[0];

			draw_rectangle(p0, p1);
			fPrimitive = TRUE;
			break;
		}
		case META_DIBSTRETCHBLT:
		{
			// Read the numeric parameters.
			short Parms[10];
			file.read(Parms, sizeof(Parms));

			// Parms[0] = low-order word of raster op
			// Parms[1] = high-order word of raster op
			// Parms[2] = source y extent
			// Parms[3] = source x extent
			// Parms[4] = source y coordinate
			// Parms[5] = source x coordinate
			// Parms[6] = destination y extent
			// Parms[7] = destination x extent
			// Parms[8] = destination y coordinate
			// Parms[9] = destination x coordinate
			CRect crSource(CPoint(Parms[5], Parms[4]), CSize(Parms[3], Parms[2]));
			CRect crDest(CPoint(Parms[9], Parms[8]), CSize(Parms[7], Parms[6]));
			DWORD dwROP = MAKELONG(Parms[0], Parms[1]);

			// Process the rest of the dib blt.
			DoDibBlt(crSource, crDest, dwROP);

			fPrimitive = TRUE;
			break;
		}
		case META_DIBBITBLT:
		{
			// Read the numeric parameters.
			short Parms[7];
			file.read(Parms, sizeof(Parms));

			// Parms[0] = high-order word of raster op
			// Parms[1] = source y coordinate
			// Parms[2] = source x coordinate
			// Parms[3] = destination y extent
			// Parms[4] = destination x extent
			// Parms[5] = destination y coordinate
			// Parms[6] = destination x coordinate
			CRect crSource(CPoint(Parms[5], Parms[4]), CSize(Parms[7], Parms[6]));
			CRect crDest(CPoint(Parms[9], Parms[8]), CSize(Parms[7], Parms[6]));
			DWORD dwROP = MAKELONG(0, Parms[1]);

			// Process the rest of the dib blt.
			DoDibBlt(crSource, crDest, dwROP);

			fPrimitive = TRUE;
			break;
		}
		case META_STRETCHDIB:
		{
			// Read the numeric parameters.
			short Parms[11];
			file.read(Parms, sizeof(Parms));

			// Parms[0]  = low-order word of raster op
			// Parms[1]  = high-order word of raster op
			// Parms[2]  = usage flag
			// Parms[3]  = source y extent
			// Parms[4]  = source x extent
			// Parms[5]  = source y coordinate
			// Parms[6]  = source x coordinate
			// Parms[7]  = destination y extent
			// Parms[8]  = destination x extent
			// Parms[9]  = destination y coordinate
			// Parms[10] = destination x coordinate
			CRect crSource(CPoint(Parms[6], Parms[5]), CSize(Parms[4], Parms[3]));
			CRect crDest(CPoint(Parms[10], Parms[9]), CSize(Parms[8], Parms[7]));
			DWORD dwROP = MAKELONG(Parms[0], Parms[1]);
			WORD wUsage = (WORD)Parms[2];

			// Process the rest of the dib blt.
			DoDibBlt(crSource, crDest, dwROP, wUsage);

			fPrimitive = TRUE;
			break;
		}
		case META_EXTTEXTOUT:
		{
			// Handle ExtTextOut call.

			// Read the numeric parameters.
			short Parms[4];
			file.read(Parms, sizeof(Parms));

			// Parms[0] = y
			// Parms[1] = x
			// Parms[2] = string length
			// Parms[3] = option flags

			RECTS rClip;
			if (Parms[3] != 0)
			{
				file.read(&rClip, sizeof(rClip));
			}

			// String data follows

			int nStrLength = Parms[2];
			int nStrSize = (nStrLength + 1) & ~1;
			LPBYTE pString = NULL;
			TRY
			{
				// Read the text.
				pString = new BYTE[nStrSize];
				file.huge_read(pString, nStrSize);

				// See if there are any widths.
				ST_DEV_POSITION Here;
				file.tell(&Here);
				ST_DEV_POSITION lRecordEnd = lRecordOffset + Record.rdSize*sizeof(WORD);
//				TRACE("Count:%d; Here: %ld; lRecordEnd: %ld\n",
//						nStrLength, Here, lRecordEnd);
				int nDXSize = nStrLength*sizeof(short);
				short* pDX = NULL;
				if (lRecordEnd >= Here + nDXSize)
				{
					pDX = new short[nStrLength];
					file.read(pDX, nDXSize);
				}

				OUTLINE_POINT p;
				p.x = (short)Parms[1];
				p.y = (short)Parms[0];

				RECT r;
				r.left = rClip.left;
				r.top = rClip.top;
				r.right = rClip.right;
				r.bottom = rClip.bottom;
				// Draw the text.
				DrawText(p, Parms[3], (LPCSTR)pString, nStrLength, &r, pDX);

				// Free the dx array.
				delete [] pDX;
				// Free the text.
				delete pString;
			}
			END_TRY
			fPrimitive = TRUE;
			break;
		}
		case META_TEXTOUT:
		{
			// Handle TextOut call.

			// Read the string size.
			short nStrLength;
			file.read(&nStrLength, sizeof(nStrLength));

			int nStrSize = (nStrLength + 1) & ~1;
			LPBYTE pString = NULL;
			TRY
			{
				// Read the text.
				pString = new BYTE[nStrSize];
				file.huge_read(pString, nStrSize);
				// Read the x and y.
				short Parms[2];
				file.read(Parms, sizeof(Parms));

				OUTLINE_POINT p;
				p.x = (short)Parms[1];
				p.y = (short)Parms[0];

				// Draw the text.
				DrawText(p, 0, (LPCSTR)pString, nStrLength, NULL);

				// Free the text.
				delete pString;
			}
			END_TRY
			fPrimitive = TRUE;
			break;
		}
		case META_MOVETO:
		case META_LINETO:
		{
			short Parms[2];
			file.read(&Parms, sizeof(Parms));

//			TRACE("%s: %d, %d\n", Record.rdFunction == META_MOVETO ? "MoveTo" : "LineTo", Parms[1], Parms[0]);

			OUTLINE_POINT p;
			p.x = Parms[1];
			p.y = Parms[0];

			if (Record.rdFunction == META_MOVETO)
			{
				// Move to.
				MoveTo(p);
			}
			else
			{
				// Must be Line to.
				LineTo(p);
				fPrimitive = TRUE;
			}
			break;
		}
		case META_PATBLT:
		{
			WORD Parms[6];
			// Parms[0] - op low word
			// Parms[1] - op high word
			// Parms[2] - height
			// Parms[3] - width
			// Parms[4] - top
			// Parms[5] - left
			file.read(Parms, sizeof(Parms));

			OUTLINE_POINT p0, p1;
			p0.x = Parms[5];
			p0.y = Parms[4];
			p1.x = p0.x + Parms[3];
			p1.y = p0.y + Parms[2];

			DoPatBlt(p0, p1, MAKELONG(Parms[0], Parms[1]));

			fPrimitive = TRUE;
			break;
		}
		case META_PIE:
		case META_ARC:
		{
			short Parms[8];
			// Parms[0] = y4		end pt y
			// Parms[1] = x4		end pt x
			// Parms[2] = y3		start pt y
			// Parms[3] = x3		start pt x
			// Parms[4] = y2		Bound bottom
			// Parms[5] = x2		Bound right
			// Parms[6] = y1		Bound top
			// Parms[7] = x1		Bound left
			file.read(Parms, sizeof(Parms));

			OUTLINE_POINT Center;
			Center.x = (short)midpoint(Parms[7], Parms[5]);
			Center.y = (short)midpoint(Parms[6], Parms[4]);

			double rx = Parms[5] - Center.x;
			if (rx < 0) rx = -rx;
			double ry = Parms[4] - Center.y;
			if (ry < 0) ry = -ry;

			double dStart = angle_from_vector(Parms[2] - Center.y, Parms[3] - Center.x);
			double dEnd = angle_from_vector(Parms[0] - Center.y, Parms[1] - Center.x);

			draw_elliptical_arc(Center, rx, ry, dStart-PI/2, dEnd-PI/2, (Record.rdFunction == META_PIE) ? 1 : -1);
			break;
		}
		case META_SAVEDC:
		{
			PushState();
			break;
		}
		case META_RESTOREDC:
		{
			PopState();
			break;
		}
		case META_SCALEVIEWPORTEXT:
		{
			// Read the parameter.
			short Parms[4];
			// Parms[0] = ydenom
			// Parms[1] = ynum
			// Parms[2] = xdenom
			// Parms[3] = xnum
			file.read(Parms, sizeof(Parms));

			m_DCState.m_cpViewportScaleNum.x = Parms[3];
			m_DCState.m_cpViewportScaleDenom.x = Parms[2];
			m_DCState.m_cpViewportScaleNum.y = Parms[1];
			m_DCState.m_cpViewportScaleDenom.y = Parms[0];

			NewSourceVars();
			break;
		}
		default:
		{
			TRACE("UNKNOWN Record %d function: %04x, size: %08lx\n", m_nRecord, Record.rdFunction, Record.rdSize);
			break;
		}
	}

	m_nRecord++;

	// Seek past the record
	file.seek(lRecordOffset + Record.rdSize*sizeof(WORD), ST_DEV_SEEK_SET);
	*primitive = fPrimitive;
	return TRUE;
}
Example #28
0
static void
draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
{
    if ((gr->overlay_parent && !gr->overlay_parent->overlay_enable) || (gr->overlay_parent && gr->overlay_parent->overlay_enable && !gr->overlay_enable) )
    {
      	return;
    }

    /* you might expect lines to be simpler than the other shapes.
       but, that would be wrong. 1 line can generate 1 polygon + 2 circles
       and even worse, we have to calculate their parameters!
       go dust off your trigonometry hat.
       */
    /* sort of based on graphics_opengl.c::draw_lines */
    /* FIXME: should honor ./configure flag for no fp.
       this could be 100% integer code pretty easily,
       except that i am lazy
       */
    struct point vert[4];
    int lw = gc->linewidth;
    //int lw = 1;
    int i;

    for(i = 0; i < count-1; i++)
    {
	float dx=p[i+1].x-p[i].x;
	float dy=p[i+1].y-p[i].y;
        float angle;

        int x_lw_adj, y_lw_adj;

        if(lw == 1)
        {
            if(gr->aa)
            {
                raster_aaline(gr->screen, p[i].x, p[i].y, p[i+1].x, p[i+1].y,
                        SDL_MapRGBA(gr->screen->format,
                            gc->fore_r,
                            gc->fore_g,
                            gc->fore_b,
                            gc->fore_a));
            }
            else
            {
                raster_line(gr->screen, p[i].x, p[i].y, p[i+1].x, p[i+1].y,
                        SDL_MapRGBA(gr->screen->format,
                            gc->fore_r,
                            gc->fore_g,
                            gc->fore_b,
                            gc->fore_a));
            }
        }
        else
        {
            /* there is probably a much simpler way but this works ok */

            /* FIXME: float + double mixture */
            /* FIXME: lrint(round())? */
            if(dy == 0.0)
            {
                angle = 0.0;
                x_lw_adj = 0;
                y_lw_adj = round((float)lw/2.0);
            }
            else if(dx == 0.0)
            {
                angle = 0.0;
                x_lw_adj = round((float)lw/2.0);
                y_lw_adj = 0;
            }
            else
            {
                angle = (M_PI/2.0) - atan(abs(dx)/abs(dy));
                x_lw_adj = round(sin(angle)*(float)lw/2.0);
                y_lw_adj = round(cos(angle)*(float)lw/2.0);
                if((x_lw_adj < 0) || (y_lw_adj < 0))
                {
                    dbg(lvl_debug, "i=%d\n", i);
                    dbg(lvl_debug, "   %d,%d->%d,%d\n", p[i].x, p[i].y, p[i+1].x, p[i+1].y);
                    dbg(lvl_debug, "   lw=%d angle=%f\n", lw, 180.0 * angle / M_PI);
                    dbg(lvl_debug, "   x_lw_adj=%d y_lw_adj=%d\n", x_lw_adj, y_lw_adj);
                }
            }

            if(p[i+1].x > p[i].x)
            {
                x_lw_adj = -x_lw_adj;
            }
            if(p[i+1].y > p[i].y)
            {
                y_lw_adj = -y_lw_adj;
            }

            /* FIXME: draw a circle/square if p[i]==p[i+1]? */
            /* FIXME: clipping, check for neg values. hoping sdl-gfx does this */
            vert[0].x = p[i].x + x_lw_adj;
            vert[0].y = p[i].y - y_lw_adj;
            vert[1].x = p[i].x - x_lw_adj;
            vert[1].y = p[i].y + y_lw_adj;
            vert[2].x = p[i+1].x - x_lw_adj;
            vert[2].y = p[i+1].y + y_lw_adj;
            vert[3].x = p[i+1].x + x_lw_adj;
            vert[3].y = p[i+1].y - y_lw_adj;

            draw_polygon(gr, gc, vert, 4);

            /* draw small circles at the ends. this looks better than nothing, and slightly
             * better than the triangle used by graphics_opengl, but is more expensive.
             * should have an ifdef/xml attr?
             */

            /* FIXME: should just draw a half circle */

            /* now some circular endcaps, if the width is over 2 */
            if(lw > 2)
            {
                if(i == 0)
                {
                    draw_circle(gr, gc, &p[i], lw/2);
                }
                /* we truncate on the divide on purpose, so we don't go outside the line */
                draw_circle(gr, gc, &p[i+1], lw/2);
            }
        }
    }
}
Example #29
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 (nine_patch_stretch && (mode == FILL_LEFT_TO_RIGHT || mode == FILL_RIGHT_TO_LEFT || mode == FILL_TOP_TO_BOTTOM || mode == FILL_BOTTOM_TO_TOP)) {
				if (under.is_valid()) {
					draw_nine_patch_stretched(under, FILL_LEFT_TO_RIGHT, 1.0, tint_under);
				}
				if (progress.is_valid()) {
					draw_nine_patch_stretched(progress, mode, get_as_ratio(), tint_progress);
				}
				if (over.is_valid()) {
					draw_nine_patch_stretched(over, FILL_LEFT_TO_RIGHT, 1.0, tint_over);
				}
			} else {
				if (under.is_valid())
					draw_texture(under, Point2(), tint_under);
				if (progress.is_valid()) {
					Size2 s = progress->get_size();
					switch (mode) {
						case FILL_LEFT_TO_RIGHT: {
							Rect2 region = Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y));
							draw_texture_rect_region(progress, region, region, tint_progress);
						} break;
						case FILL_RIGHT_TO_LEFT: {
							Rect2 region = Rect2(Point2(s.x - s.x * get_as_ratio(), 0), Size2(s.x * get_as_ratio(), s.y));
							draw_texture_rect_region(progress, region, region, tint_progress);
						} break;
						case FILL_TOP_TO_BOTTOM: {
							Rect2 region = Rect2(Point2(), Size2(s.x, s.y * get_as_ratio()));
							draw_texture_rect_region(progress, region, region, tint_progress);
						} break;
						case FILL_BOTTOM_TO_TOP: {
							Rect2 region = Rect2(Point2(0, s.y - s.y * get_as_ratio()), Size2(s.x, s.y * get_as_ratio()));
							draw_texture_rect_region(progress, region, region, tint_progress);
						} break;
						case FILL_CLOCKWISE:
						case FILL_COUNTER_CLOCKWISE:
						case FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE: {
							float val = get_as_ratio() * rad_max_degrees / 360;
							if (val == 1) {
								Rect2 region = Rect2(Point2(), s);
								draw_texture_rect_region(progress, region, region, tint_progress);
							} else if (val != 0) {
								Array pts;
								float direction = mode == FILL_COUNTER_CLOCKWISE ? -1 : 1;
								float start;

								if (mode == FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE) {
									start = rad_init_angle / 360 - val / 2;
								} else {
									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));
								}
								Vector<Color> colors;
								colors.push_back(tint_progress);
								draw_polygon(points, colors, uvs, progress);
							}
							if (Engine::get_singleton()->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;
						case FILL_BILINEAR_LEFT_AND_RIGHT: {
							Rect2 region = Rect2(Point2(s.x / 2 - s.x * get_as_ratio() / 2, 0), Size2(s.x * get_as_ratio(), s.y));
							draw_texture_rect_region(progress, region, region, tint_progress);
						} break;
						case FILL_BILINEAR_TOP_AND_BOTTOM: {
							Rect2 region = Rect2(Point2(0, s.y / 2 - s.y * get_as_ratio() / 2), Size2(s.x, s.y * get_as_ratio()));
							draw_texture_rect_region(progress, region, region, tint_progress);
						} break;
						default:
							draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), tint_progress);
					}
				}
				if (over.is_valid())
					draw_texture(over, Point2(), tint_over);
			}

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