Beispiel #1
0
//Trim the trangle tri by the (s,t) box of the timage.
//Function's return value is the number of vertices of the output polygon.
//When the number of the vertices is 0, st_tri was outside the timage.
int trim_triangle(
	const MGBox& box,//The box (left,bottom, right, top)
	const MGPosition st_tri[3],
	const MGPosition world_tri[3],
	std::vector<MGPosition>& st_polygon,
		//The vertices of the trimmed polygon of (s,t) coordinates will be output.
		//The maximum number of the trimmed polygon is 7.
		//The coordinates will be subtracted by (left, bottom) of the box.
	std::vector<MGPosition>& world_polygon
		//The vertices world coordinates corresponding to the trimmed polygon
		//of (s,t) will be output.
		//The maximum number of the trimmed polygon is 7.
){
	MGPosition minst=box.low(), maxst=box.high();
	double smin=minst[0], smax=maxst[0];
	double tmin=minst[1], tmax=maxst[1];
	double s0=st_tri[0][0], s1=st_tri[1][0], s2=st_tri[2][0];
	double t0=st_tri[0][1], t1=st_tri[1][1], t2=st_tri[2][1];

	if(s0<=smin && s1<=smin && s2<=smin)
		return 0;
	if(s0>=smax && s1>=smax && s2>=smax)
		return 0;
	if(t0<=tmin && t1<=tmin && t2<=tmin)
		return 0;
	if(t0>=tmax && t1>=tmax && t2>=tmax)
		return 0;

	if(s0>=smin && s1>=smin && s2>=smin
		&& s0<=smax && s1<=smax && s2<=smax
		&& t0>=tmin && t1>=tmin && t2>=tmin
		&& t0<=tmax && t1<=tmax && t2<=tmax){
		for(size_t i=0; i<3; i++){
			st_polygon.push_back(st_tri[i]);
			world_polygon.push_back(world_tri[i]);
		}
		return 3;
	}

	mgImageRect irect(box,st_tri,world_tri);
	//std::cout<<"trim_triangle ,irect="<<irect;/////
	//for(size_t ii=0; ii<3; ii++)std::cout<<std::endl<<st_tri[ii];
	//std::cout<<std::endl;
	irect.createTrimPolygon(st_polygon);
	irect.convert_to_world(st_polygon,world_polygon);
	return st_polygon.size();
}
Beispiel #2
0
WebBitmap* Frame::imageFromRect(const FloatRect& rect) const
{
    // We should not try to create a bitmap of zero height or width as it is not supported.
	IntRect irect(rect);
    if(irect.size().width() == 0 || irect.size().height() == 0) 
        return NULL;

    FrameLoaderClientApollo* const clientApollo = FrameLoaderClientApollo::clientApollo(this);
    WebHost* webHost = clientApollo->webHost();
    ASSERT(webHost);

    WebBitmap* resultBitmap = webHost->m_pVTable->createBitmap(webHost, irect.size().width(), irect.size().height());
    
	// clear pixels with transparent black (0)
	void *pixelData = resultBitmap->m_pVTable->getPixelData(resultBitmap);
    unsigned long stride = resultBitmap->m_pVTable->getStride(resultBitmap);
    memset( pixelData, 0, stride * irect.height() );
	

	// now, paint the selection in a graphics context
	WebIntRect sourceRect;
		
	sourceRect.m_left = 0; 
	sourceRect.m_top = 0; 
	sourceRect.m_right = irect.width();
	sourceRect.m_bottom = irect.height();
	
	GraphicsContext gc (resultBitmap,&sourceRect);

	IntSize offset = view()->scrollOffset();
    irect.move(-offset.width(), -offset.height());
    irect = view()->convertToContainingWindow(irect);

#if OS(WINDOWS) ||  OS(DARWIN)
	// changing origin from top-left to bottom-left 
	gc.concatCTM(TransformationMatrix(1, 0, 0, -1, 0, irect.height()).toAffineTransform());
#endif 

	// this transformation moves the clip into the origin of the user space
	gc.concatCTM(TransformationMatrix().translate(-irect.x(), -irect.y()).toAffineTransform());
	
	view()->paint(&gc,irect);
	
    return resultBitmap;
}
Beispiel #3
0
		void GUI::addWindow(gui::Window* window) {
			mWindowList.push_front(window);
			window->mInternalRect = irect(mRect.w/4, mRect.h/4, mRect.w/2, mRect.h/2);
		}
void
GLPainter::draw_filled_rect(const DrawingRequest& request)
{
  const FillRectRequest* fillrectrequest
    = (FillRectRequest*) request.request_data;

  glDisable(GL_TEXTURE_2D);
  glColor4f(fillrectrequest->color.red, fillrectrequest->color.green,
            fillrectrequest->color.blue, fillrectrequest->color.alpha);
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);

  if (fillrectrequest->radius != 0.0f)
  {
    // draw round rect
    // Keep radius in the limits, so that we get a circle instead of
    // just graphic junk
    float radius = std::min(fillrectrequest->radius,
                            std::min(fillrectrequest->size.x/2,
                                     fillrectrequest->size.y/2));

    // inner rectangle
    Rectf irect(request.pos.x    + radius,
                request.pos.y    + radius,
                request.pos.x + fillrectrequest->size.x - radius,
                request.pos.y + fillrectrequest->size.y - radius);

    int n = 8;
    int p = 0;
    std::vector<float> vertices((n+1) * 4 * 2);

    for(int i = 0; i <= n; ++i)
    {
      float x = sinf(i * (M_PI/2) / n) * radius;
      float y = cosf(i * (M_PI/2) / n) * radius;

      vertices[p++] = irect.get_left() - x;
      vertices[p++] = irect.get_top()  - y;

      vertices[p++] = irect.get_right() + x;
      vertices[p++] = irect.get_top()   - y;
    }

    for(int i = 0; i <= n; ++i)
    {
      float x = cosf(i * (M_PI/2) / n) * radius;
      float y = sinf(i * (M_PI/2) / n) * radius;

      vertices[p++] = irect.get_left()   - x;
      vertices[p++] = irect.get_bottom() + y;

      vertices[p++] = irect.get_right()  + x;
      vertices[p++] = irect.get_bottom() + y;
    }

    glVertexPointer(2, GL_FLOAT, 0, &*vertices.begin());
    glDrawArrays(GL_TRIANGLE_STRIP, 0,  vertices.size()/2);
  }
  else
  {
    float x = request.pos.x;
    float y = request.pos.y;
    float w = fillrectrequest->size.x;
    float h = fillrectrequest->size.y;

    float vertices[] = {
      x,   y,
      x+w, y,
      x+w, y+h,
      x,   y+h
    };
    glVertexPointer(2, GL_FLOAT, 0, vertices);

    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  }

  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glEnable(GL_TEXTURE_2D);
  glColor4f(1, 1, 1, 1);
}