Ejemplo n.º 1
0
void BarGraph::drawContents( QPainter *p )
{
    int h = contentsRect().height();
    int y = contentsRect().top();

    int total = 0;
    for ( int i = 0; i < data->count(); i++ )
        total += data->value(i);

    int pos = 0;
    p->setPen(Qt::NoPen);
    QRect r = contentsRect();
    for ( int i = 0; i < data->count(); i++ ) {
        int len;
        if ( i == data->count() - 1 || !total )
            len = r.width() - pos;
        else
            len = (uint)data->value(i) * r.width() / total;
        QColor col;
        col.setHsv( i * 360 / data->count(), 255, 255 );
        if ( layoutDirection() == Qt::LeftToRight )
            drawSegment( p, QRect(r.x() + pos, y, len, h), col );
        else
            drawSegment( p, QRect(r.width()+ r.x()-pos-len ,y,len,h), col );
        pos += len;
    }
}
Ejemplo n.º 2
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
    
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);

    _winSize = Director::getInstance()->getWinSize();
    auto drawNode = DrawNode::create();
    drawNode->drawSegment(Point(0, _winSize.height/2), Point(_winSize.width, _winSize.height/2), 1, Color4F(1.0f, 1.0f, 1.0f, 1.0f));
    drawNode->drawSegment(Point(_winSize.width/2, _winSize.height), Point(_winSize.width/2, 0), 1, Color4F(1.0f, 1.0f, 1.0f, 1.0f));
    
    Point centerPoint = Point(_winSize.width/2, _winSize.height/2);
    float R = 128;
    std::vector<Color4F> colors = {
        Color4F(1.0f, 0.0f, 0.0f, 0.6f), Color4F(0.0f, 1.0f, 0.0f, 0.6f),
        Color4F(0.0f, 0.0f, 1.0f, 0.6f), Color4F(0.5f, 0.5f, 0.0f, 0.6f),
        Color4F(0.0f, 0.5f, 0.5f, 0.6f), Color4F(0.5f, 0.5f, 0.5f, 0.5f),
    };
    for (float angles = 0, i = 0; angles < 360; angles += 60, i++) {
        float x = R * cos(CC_DEGREES_TO_RADIANS(angles));
        float y = R * sin(CC_DEGREES_TO_RADIANS(angles));
        drawNode->drawDot(centerPoint + Point(x, y), R/2, colors[i]);
        auto label = LabelTTF::create("angle:" + std::to_string((int)(angles)), "Arial", 24);
        label->setPosition(centerPoint + Point(x, y));
        drawNode->addChild(label);
    }
    this->addChild(drawNode, 1, 1);

    //    auto label = LabelTTF::create("angle(000)", "Arial", 48);
    //    label->setColor(Color3B::WHITE);
    //    label->setTag(TAG_LABEL);
    //    this->addChild(label, TAG_LABEL, TAG_LABEL);
    //    label->setPosition(Point(winSize.width/2, winSize.height/2));
    //    enableTouchEvent(true);
    return true;
}
Ejemplo n.º 3
0
int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent )
{
    boost::optional<VECTOR2D> startingPoint;

    if( m_editModules )
    {
        m_frame->SetToolID( ID_MODEDIT_LINE_TOOL, wxCURSOR_PENCIL, _( "Add graphic line" ) );

        EDGE_MODULE* line = new EDGE_MODULE( m_board->m_Modules );

        while( drawSegment( S_SEGMENT, reinterpret_cast<DRAWSEGMENT*&>( line ), startingPoint  ) )
        {
            if( line )
            {
                m_frame->OnModify();
                m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT );
                line->SetParent( m_board->m_Modules );
                line->SetLocalCoord();
                m_board->m_Modules->GraphicalItems().PushFront( line );
                startingPoint = line->GetEnd();
            }
            else
            {
                startingPoint = boost::none;
            }

            line = new EDGE_MODULE( m_board->m_Modules );
        }
    }
    else // !m_editModules case
    {
        m_frame->SetToolID( ID_PCB_ADD_LINE_BUTT, wxCURSOR_PENCIL, _( "Add graphic line" ) );

        DRAWSEGMENT* line = new DRAWSEGMENT;

        while( drawSegment( S_SEGMENT, line, startingPoint ) )
        {
            if( line )
            {
                m_board->Add( line );
                m_frame->OnModify();
                m_frame->SaveCopyInUndoList( line, UR_NEW );
                startingPoint = line->GetEnd();
            }
            else
            {
                startingPoint = boost::none;
            }

            line = new DRAWSEGMENT;
        }
    }

    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );

    return 0;
}
Ejemplo n.º 4
0
void drawPoint(
    const Vec3& pos,
    const Color& color
) {
    Segment seg1(pos - Vec3(1,0,0), pos + Vec3(1,0,0));
    Segment seg2(pos - Vec3(0,0,1), pos + Vec3(0,0,1));
    
    drawSegment(seg1, color, 0.1f);
    drawSegment(seg2, color, 0.1f);
}
Ejemplo n.º 5
0
void MapView::createGrid()
{
	auto grid = DrawNode::create();
	this->addChild(grid, MapManager::LAYER_GRID);

	Fixed i;
	for (i=0; i<=m_mapW; ++i)
	{
		grid->drawSegment(Vec2(i*m_gridW, 0), Vec2(i*m_gridW, m_mapH*m_gridH), 0.5f, Color4F(0.5f, 0.5f, 0.5f, 0.5f));
	}
	for (i=0; i<=m_mapH; ++i)
	{
		grid->drawSegment(Vec2(0, i*m_gridH), Vec2(m_mapW*m_gridW, i*m_gridH), 0.5f, Color4F(0.5f, 0.5f, 0.5f, 0.5f));
	}
}
Ejemplo n.º 6
0
void ImageSegmentation::drawSegment(cv::Mat &disp, const cv::Scalar &colorOut, const cv::Scalar &colorIn, const Segment &seg, const int32_t level, const int32_t levels, const bool fill, const int lineSize, const cv::Point &offset)
{
  cv::Scalar color = level % 2 ? colorIn : colorOut;

  std::vector<std::vector<cv::Point>> tmp;
  tmp.push_back(seg.contour);
  if(fill)
  {
    cv::fillPoly(disp, tmp, color, 8, 0, offset);
  }
  else
  {
    cv::polylines(disp, tmp, true, color, lineSize, CV_AA);
  }

  // Stop after first inner contour
  if(level == levels)
  {
    return;
  }

  for(size_t i = 0; i < seg.children.size(); ++i)
  {
    drawSegment(disp, colorOut, colorIn, seg.children[i], level + 1, levels, fill, lineSize, offset);
  }
}
Ejemplo n.º 7
0
void drawTrack(track* t){
	trackSegment* temp;
	
	for(temp = t->head; temp->next; temp = temp->next){
		drawSegment(temp);
	}
}
Ejemplo n.º 8
0
int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent )
{
    BOARD_ITEM_CONTAINER* parent = m_frame->GetModel();
    DRAWSEGMENT* line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
    boost::optional<VECTOR2D> startingPoint;
    BOARD_COMMIT commit( m_frame );

    SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE );

    m_frame->SetToolID( m_editModules ? ID_MODEDIT_LINE_TOOL : ID_PCB_ADD_LINE_BUTT,
                        wxCURSOR_PENCIL, _( "Add graphic line" ) );

    while( drawSegment( S_SEGMENT, line, startingPoint ) )
    {
        if( line )
        {
            commit.Add( line );
            commit.Push( _( "Draw a line segment" ) );
            startingPoint = line->GetEnd();
        }
        else
        {
            startingPoint = boost::none;
        }

        line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
    }

    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );

    return 0;
}
Ejemplo n.º 9
0
int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent )
{
    BOARD_ITEM_CONTAINER* parent = m_frame->GetModel();
    DRAWSEGMENT* circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
    BOARD_COMMIT commit( m_frame );

    SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE );

    m_frame->SetToolID( m_editModules ? ID_MODEDIT_CIRCLE_TOOL : ID_PCB_CIRCLE_BUTT,
            wxCURSOR_PENCIL, _( "Add graphic circle" ) );

    while( drawSegment( S_CIRCLE, circle ) )
    {
        if( circle )
        {
            commit.Add( circle );
            commit.Push( _( "Draw a circle" ) );
        }

        circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
    }

    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );

    return 0;
}
Ejemplo n.º 10
0
void ImageSegmentation::drawSegments2D(cv::Mat &disp, const std::vector<Segment> &segments, const std::vector<std::string> &text,
                                       const int sizeLine, const double sizeText, const int font)
{
  std::ostringstream oss;

  for(int32_t i = 0; i < segments.size(); ++i)
  {
    const Segment &seg = segments[i];
    drawSegment(disp, CV_RGB(128, 128, 128), CV_RGB(0, 0, 0), seg, 0, 1, true, sizeLine);

    cv::rectangle(disp, seg.rect, CV_RGB(0, 0, 255), sizeLine);
    cv::circle(disp, seg.center, 5, CV_RGB(255, 255, 255), sizeLine, CV_AA);

    cv::line(disp, seg.center, seg.center + seg.axisX, CV_RGB(255, 0, 0), sizeLine);
    cv::line(disp, seg.center, seg.center + seg.axisY, CV_RGB(0, 255, 0), sizeLine);
  }

  for(int32_t i = 0; i < text.size(); ++i)
  {
    const Segment &seg = segments[i];

    oss.str("");
    oss << i << " : " << text[i];
    int baseLine;
    cv::Size textSize = cv::getTextSize(oss.str(), font, sizeText, sizeLine, &baseLine);
    cv::putText(disp, oss.str(), cv::Point(seg.rect.x + (seg.rect.width - textSize.width) / 2, seg.rect.y - textSize.height), font, sizeText, CV_RGB(255, 255, 255), sizeLine, CV_AA);
  }
}
Ejemplo n.º 11
0
bool BaseDemo::init()
{
    if(!Layer::init())
    {
        return false;
    }
    
    Size size = VisibleRect::getVisibleRect().size;
    auto bg = LayerColor::create(Color4B(125, 125, 125, 255), size.width, size.height);
    this->addChild(bg);
    
    auto bg_grid = DrawNode::create();
    int i = 0;
    for (i = 0; i < size.height; i += GRID_SPACE) {
        bg_grid->drawSegment(Point(0, i), Point(size.width, i), 0.5, Color4F(0, 0, 0, 0.4));
    }
    
    for (i = 0; i < size.width; i += GRID_SPACE) {
        bg_grid->drawSegment(Point(i, 0), Point(i, size.height), 0.5, Color4F(0, 0, 0, 0.4));
    }
    this->addChild(bg_grid);
    
    //加入封闭的盒子,用作墙壁
    auto body = PhysicsBody::createEdgeBox(size, PHYSICSBODY_MATERIAL_DEFAULT, 3);
    auto edgeNode = Node::create();
    edgeNode->setPosition(size.width/2, size.height/2);
    edgeNode->setPhysicsBody(body);
    this->addChild(edgeNode);
    
    auto backMenuItem = MenuItemImage::create("backNormal.png", "backSelected.png", CC_CALLBACK_1(BaseDemo::backCallback, this));
    auto restartMenuItem = MenuItemImage::create("refreshNormal.png", "refreshSelected.png", CC_CALLBACK_1(BaseDemo::restartCallback, this));
    
    restartMenuItem->setPosition(VisibleRect::rightTop() + Point(-200, -80));
    backMenuItem->setPosition(restartMenuItem->getPosition() + Point(90, 0));
    auto menu = Menu::create(backMenuItem, restartMenuItem, NULL);
    menu->setPosition(Point::ZERO);
    this->addChild(menu, 300);
    
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->onTouchBegan = CC_CALLBACK_2(BaseDemo::onTouchBegan, this);
    touchListener->onTouchMoved = CC_CALLBACK_2(BaseDemo::onTouchMoved, this);
    touchListener->onTouchEnded = CC_CALLBACK_2(BaseDemo::onTouchEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
    
    return true;
}
Ejemplo n.º 12
0
//this is where the list of segments is created
//returns t which is an object whose head points to the first segment of the track
track *NewTrack(int maxx, int maxy){
	int i, random;
	
	track *t = (track *) malloc(sizeof(track));
	t->maxx = maxx;
	t->maxy = maxy;
	t->tail = NewSegment(10, t, maxx, maxy);
	drawSegment(t->tail);
	for(i = 0; i < maxy-2; i++){
		t->head = NewSegment(10, t, maxx, maxy);
		//drawSegment(t->head);
	}
	drawSegment(t->head);

	refresh();
	return t;
}
Ejemplo n.º 13
0
int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent )
{
    if( m_editModules )
    {
        m_frame->SetToolID( ID_MODEDIT_CIRCLE_TOOL, wxCURSOR_PENCIL, _( "Add graphic circle" ) );

        EDGE_MODULE* circle = new EDGE_MODULE( m_board->m_Modules );

        while( drawSegment( S_CIRCLE, reinterpret_cast<DRAWSEGMENT*&>( circle ) ) )
        {
            if( circle )
            {
                m_frame->OnModify();
                m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT );
                circle->SetParent( m_board->m_Modules );
                circle->SetLocalCoord();
                m_board->m_Modules->GraphicalItems().PushFront( circle );
            }

            circle = new EDGE_MODULE( m_board->m_Modules );
        }
    }
    else // !m_editModules case
    {
        m_frame->SetToolID( ID_PCB_CIRCLE_BUTT, wxCURSOR_PENCIL, _( "Add graphic circle" ) );

        DRAWSEGMENT* circle = new DRAWSEGMENT;

        while( drawSegment( S_CIRCLE, circle ) )
        {
            if( circle )
            {
                m_board->Add( circle );
                m_frame->OnModify();
                m_frame->SaveCopyInUndoList( circle, UR_NEW );
            }

            circle = new DRAWSEGMENT;
        }
    }

    m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );

    return 0;
}
Ejemplo n.º 14
0
void QLCDNumberPrivate::drawDigit(const QPoint &pos, QPainter &p, int segLen,
                                  char newCh, char oldCh)
{
// Draws and/or erases segments to change display of a single digit
// from oldCh to newCh

    char updates[18][2];        // can hold 2 times number of segments, only
                                // first 9 used if segment table is correct
    int  nErases;
    int  nUpdates;
    const char *segs;
    int  i,j;

    const char erase      = 0;
    const char draw       = 1;
    const char leaveAlone = 2;

    segs = getSegments(oldCh);
    for (nErases=0; segs[nErases] != 99; nErases++) {
        updates[nErases][0] = erase;            // get segments to erase to
        updates[nErases][1] = segs[nErases];    // remove old char
    }
    nUpdates = nErases;
    segs = getSegments(newCh);
    for(i = 0 ; segs[i] != 99 ; i++) {
        for (j=0;  j<nErases; j++)
            if (segs[i] == updates[j][1]) {   // same segment ?
                updates[j][0] = leaveAlone;     // yes, already on screen
                break;
            }
        if (j == nErases) {                   // if not already on screen
            updates[nUpdates][0] = draw;
            updates[nUpdates][1] = segs[i];
            nUpdates++;
        }
    }
    for (i=0; i<nUpdates; i++) {
        if (updates[i][0] == draw)
            drawSegment(pos, updates[i][1], p, segLen);
        if (updates[i][0] == erase)
            drawSegment(pos, updates[i][1], p, segLen, true);
    }
}
Ejemplo n.º 15
0
void BlackBoardWidget::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
{
    QPointF lastPos = event->lastPos();

    if (m_oldPoint.x() != -1){
        drawSegment(m_oldPoint, lastPos, 1);      
    }

    m_oldPoint = lastPos;
}
Ejemplo n.º 16
0
void Game::onTouchMoved(cocos2d::Touch *touch, cocos2d::Event *event){
    isMoved=true;
    points[index]=touch->getLocation();
    auto p=touch->getLocation();
    auto r=DrawNode::create();
    addChild(r);
    if(index>0){
        r->drawSegment(points[index-1], p, 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
    }
    index++;
}
Ejemplo n.º 17
0
bool MainScene::init()
{
    Size sizeWin = DIRECTOR->getWinSize();
    float listWidth = sizeWin.width - sizeWin.height;
    
    // background layout
    auto layerColor = LayerColor::create(Color4B::WHITE, sizeWin.width, sizeWin.height);
    auto drawNodeV = DrawNode::create();
    drawNodeV->drawSegment(Point(listWidth, 0), Point(listWidth, sizeWin.height), 2, Color4F::GRAY);
    layerColor->addChild(drawNodeV);
    auto drawNodeH = DrawNode::create();
    drawNodeH->drawSegment(Point(listWidth, sizeWin.height / 3), Point(sizeWin.width, sizeWin.height / 3), 2, Color4F::GRAY);
    layerColor->addChild(drawNodeH);
    addChild(layerColor);
    
    // title
    auto btnTitle = Button::create();
    btnTitle->setTouchEnabled(true);
    btnTitle->ignoreContentAdaptWithSize(false);
    btnTitle->setTitleFontName("Marker Felt");
    btnTitle->setTitleText("Cocos2d Manual");
    btnTitle->setTitleColor(Color3B::GREEN);
    btnTitle->setTitleFontSize(30);
    btnTitle->setSize(Size(listWidth, 40));
    btnTitle->setPosition(Point(listWidth / 2, sizeWin.height - 30));
    BIND_LISTENER_TOUCH(btnTitle, this, MainScene::onTouchTitle);
    addChild(btnTitle);
    
    // manual layer
    auto layerDisplay = ManualDisplay::create();
    auto layerCode = ManualCode::create();
    auto layerList = ManualList::create();
    layerCode->setDisplay(layerDisplay);
    layerCode->setTag(Tag::TAG_CODELAYER);
    layerList->setCode(layerCode);
    addChild(layerDisplay);
    addChild(layerCode);
    addChild(layerList);
    
    return Layer::init();
}
Ejemplo n.º 18
0
// Static.  
void LCDPainter::drawDigit(QPainter* painter, const QRect& rect, char ascii_char)
{
  if(ascii_char < 0x30 || ascii_char >= 39)
    return;
  const int idx = ascii_char - 0x30;
  const bool* segs = _LCD_DigitSegments[idx];
  for(int i = 0; i < 7; ++i)
  {
    if(segs[i])
      drawSegment(painter, rect, i);
  }
}
Ejemplo n.º 19
0
Adesk::Boolean SimpleChimneyDraw::subWorldDraw ( AcGiWorldDraw* mode )
{
    assertReadEnabled () ;

    int len = m_pts.length();
    if( len < 2 ) return Adesk::kTrue;

    for( int i = 0; i < len - 1; i++ )
    {
        drawSegment( mode, m_pts[i], m_pts[i + 1] );
    }
    return Adesk::kTrue;
}
Ejemplo n.º 20
0
void H2CanvasDelegate::drawH2GeodesicArc(const H2GeodesicArc &L, const QColor &color, int width, bool back)
{
    Complex center, endpoint1, endpoint2;
    double radius;
    if((mobius*L).getCircleAndEndpointsInDiskModel(center, radius, endpoint1, endpoint2))
    {
        drawSmallerArc(center, radius, endpoint1, endpoint2, color, width, back);
    }
    else
    {
        drawSegment(endpoint1, endpoint2, color, width, back);
    }
}
Ejemplo n.º 21
0
Archivo: wall.cpp Proyecto: gja/lblock
void Wall::generateList()
{
	QList <Window *> list = windows;
	Window *window;

	float startx = 0.0f; // Startx moves from left to right, drawing each window

	// For each window, we draw a solid wall till the window
	while (! list.isEmpty()) {
		window = list.takeFirst();

		// solid wall
		drawSegment(startx, 0.0f, window->position, height);

		// below, then above window
		drawSegment(window->position, 0.0f, window->position + window->length, window->lowerHeight);
		drawSegment(window->position, window->upperHeight, window->position + window->length, height);

		startx = window->position + window->length;
	}

	// The remaining part of the wall
	drawSegment(startx, 0.0f, length, height);

	// Side walls
	glBindTexture(GL_TEXTURE_2D, outerTexture.texture);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, -thickness);
		glTexCoord2f(0.0f, height / innerTexture.sizey); glVertex3f(0.0f, height, -thickness);
		glTexCoord2f(thickness / innerTexture.sizex, height / innerTexture.sizey); glVertex3f(0.0f, height, 0.0f);
		glTexCoord2f(thickness / innerTexture.sizex, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f);

		glTexCoord2f(0.0f, 0.0f); glVertex3f(length, 0.0f, -thickness);
		glTexCoord2f(0.0f, height / innerTexture.sizey); glVertex3f(length, height, -thickness);
		glTexCoord2f(thickness / innerTexture.sizex, height / innerTexture.sizey); glVertex3f(length, height, 0.0f);
		glTexCoord2f(thickness / innerTexture.sizex, 0.0f); glVertex3f(length, 0.0f, 0.0f);
	glEnd();
}
Ejemplo n.º 22
0
void MainScene::addBar(){
    auto barNode = DrawNode::create();
    barNode->drawSegment(Vec2(30,300), Vec2(50,300),2.0f, Color4F(.5f, 1.0f, .7f, 1.0f));
    this->addChild(barNode);
    auto move = MoveTo::create(_noteSpeedUserSetting, Vec2(30, 0));
    
    auto remove = CallFuncN::create([this](Node *node){
        auto label = dynamic_cast<Label *>(node);
        label->removeFromParent();
    });
    
    auto sequence = Sequence::create(move, remove, NULL);
    barNode->runAction(sequence);
}
Ejemplo n.º 23
0
void Tree::drawTree()
{
	int ii=0,countF=0;
	addressF=basicUnitList.begin();
	
	//FF[F[F]F]FFF
	glRotatef(90.0,-1.0,0.0,0.0);

	for(int i=0;i<simpleStringF.length();i++)
	{
		if (simpleStringF[i]=='[')
		{
			glPushMatrix();						
		}
		else if (simpleStringF[i]==']')
		{
			glPopMatrix();
		}
		else //simpleStringF[i]=='F'
		{
			countF++;
			//生成随机颜色
			glColor3ub(color[countF%2][0],color[countF%2][1],color[countF%2][2]);
					
			if (addressF->angleZ!=0)
				glRotatef(addressF->angleZ,0.0,0.0,addressF->angleZ);
			if (addressF->angleY!=0)
				glRotatef(addressF->angleY,0.0,addressF->angleY,0.0);
			if (addressF->angleX!=0)
				glRotatef(addressF->angleX,addressF->angleX,0.0,0.0);

			drawSegment(addressF->redius,addressF->length);
			
			if (addressF->leafAmount)
			{
					drawLeaf(addressF->leafArea[0],addressF->length);
					drawLeaf(addressF->leafArea[0],addressF->length-0.35);
			}

			addressF++;
		}
	}

	//drawLeaf(1,1);
}
Ejemplo n.º 24
0
void scanLine() {
	int xscan = (int)posx;	 
	int yscan = (int)posy; 
	int zscan = (int)posz;

	xdir = (vx>0)*2-1; 
	ydir = (vy>0)*2-1; 

	float xtemp = posx-xscan; 
	if (xdir > 0) 
		xtemp = 1.0f-xtemp;

	float ytemp = posy-yscan; 
	if (ydir > 0) 
		ytemp = 1.0f-ytemp;

	float d = xtemp*incy - ytemp*incx;

	int depth=128;
	for(; depth>0; depth--) {
		if(d < 0) { 
			if(inside(xscan+xdir, yscan, zscan)) 
				break;
			xscan += xdir;
			d += incy;
		} else {
			if(inside(xscan, yscan+ydir, zscan))
				break;
			yscan += ydir;
			d -= incx;
		}
	}	

	if(depth==0) {
		drawSegment(sx, 0, height, 0);
		return;
	}

	scanUp(xscan, yscan, zscan, d, height/2, 0);
	scanDown(xscan, yscan, zscan, d, height/2, height);
}
Ejemplo n.º 25
0
void Draw2D::drawSegment(SDL_Surface *screen,Point3D _ptA, Point3D _ptB, Uint8 r, Uint8 g, Uint8 b)
{
    bool ptAOut = false, ptBOut = false;

    Point3D ptA = _ptA;
    geometryTransformation(ptA);
    ptAOut = !modelview(ptA);

    Point3D ptB = _ptB;
    geometryTransformation(ptB);
    ptBOut = !modelview(ptB);

    if(ptAOut && ptBOut){return;}

    float threahold = 1.0;

    if (ptAOut )// A is out
    {
        Point3D ptBA = ptA-ptB;
        if (ptBA.z<threahold&&ptBA.z>-threahold) { ptBA.z = threahold; }
        float t = (near-ptB.z)/ptBA.z;
        ptA = ptB + ptBA*t;
    }

    if ( ptBOut)// B is out
    {
        Point3D ptAB = ptB-ptA;
        if (ptAB.z<threahold&&ptAB.z>-threahold) { ptAB.z = threahold; }
        float t = (near-ptA.z)/ptAB.z;
        ptB = ptA + ptAB*t;
    }

    Point2D result1 = project(ptA);
    Point2D result2 = project(ptB);

    drawSegment(screen, result1.x,result1.y,result2.x,result2.y,r,g,b);
}
Ejemplo n.º 26
0
void ImageSegmentation::drawSegments3D(cv::Mat &disp, const std::vector<Segment> &segments, const cv::Mat &cameraMatrix, const cv::Mat &distCoefficients,
                                       const std::vector<std::string> &text, const int sizeLine, const double sizeText, const int font)
{
  std::ostringstream oss;

  for(int32_t i = 0; i < segments.size(); ++i)
  {
    const Segment &seg = segments[i];
    drawSegment(disp, CV_RGB(255, 255, 255), CV_RGB(0, 0, 0), seg, 0, 1, false, sizeLine);

    std::vector<cv::Point2f> pointsImage;
    std::vector<cv::Point3f> axis(4);
    axis[0] = cv::Point3f(0, 0, 0);
    axis[1] = cv::Point3f(1, 0, 0) * seg.lengthX;
    axis[2] = cv::Point3f(0, 1, 0) * seg.lengthY;
    axis[3] = cv::Point3f(0, 0, 1) * 0.02;

    cv::projectPoints(axis, seg.rotation, seg.translation, cameraMatrix, distCoefficients, pointsImage);

    //draw the axes on the colored image
    cv::line(disp, pointsImage[0], pointsImage[1], CV_RGB(255, 0, 0), sizeLine, CV_AA);
    cv::line(disp, pointsImage[0], pointsImage[2], CV_RGB(0, 255, 0), sizeLine, CV_AA);
    cv::line(disp, pointsImage[0], pointsImage[3], CV_RGB(0, 0, 255), sizeLine, CV_AA);
  }

  for(int32_t i = 0; i < text.size(); ++i)
  {
    const Segment &seg = segments[i];

    oss.str("");
    oss << i << " : " << text[i];
    int baseLine;
    cv::Size textSize = cv::getTextSize(oss.str(), font, sizeText, sizeLine, &baseLine);
    cv::putText(disp, oss.str(), cv::Point(seg.rect.x + (seg.rect.width - textSize.width) / 2, seg.rect.y - textSize.height), font, sizeText, CV_RGB(255, 255, 255), sizeLine, CV_AA);
  }
}
Ejemplo n.º 27
0
bool BlackBoardWidget::event(QEvent *event)
{
    switch (event->type()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd: {
        QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
        foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) {
            switch (touchPoint.state()) {
            case Qt::TouchPointStationary:
                // don't do anything if this touch point hasn't moved
                continue;
            default:
                drawSegment(touchPoint.lastPos(), touchPoint.pos(), 3*touchPoint.pressure());
                break;
            }
        }
        break;
    }
    default:
        return QGraphicsWidget::event(event);
    }
    return true;
}
Ejemplo n.º 28
0
void H2CanvasDelegate::drawStraightH2GeodesicArc(const H2GeodesicArc &L, const QColor &color, int width, bool back)
{
    Complex zA, zB;
    (mobius*L).getEndpointsInDiskModel(zA, zB);
    drawSegment(zA, zB, color, width, back);
}
Ejemplo n.º 29
0
	void TurtleRenderer::parseSystem()
	{
		m_stack = std::stack<glm::mat4>();
		m_stack.push(glm::mat4(1.0f));
		
		std::stack<Node*> branchStack;

		std::string path = m_system->generate();
		//std::cout << "Word: " << path << std::endl;

		float angle = m_system->definition()->angle;

		glm::mat4 m;
		glm::vec3 right, up, forward;
		Node * parent = m_root = new Node();

		for (unsigned i = 0; i < path.length(); i++)
		{
			char chr = path[i];
			switch (chr)
			{
			case 'X':
				// ignored symbol
				break;
			case 'F':
				parent = drawSegment(parent);
				m = glm::translate(m_stack.top(), glm::vec3(0.0f, length, 0.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case 'Q':
			case 'f':
				parent = drawLeaf(parent);
				break;
			case '+':
				m = glm::rotate(m_stack.top(), angle, glm::vec3(1.0f, 0.0f, 0.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '-':
				m = glm::rotate(m_stack.top(), -angle, glm::vec3(1.0f, 0.0f, 0.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '!':
				m = glm::rotate(m_stack.top(), angle, glm::vec3(0.0f, 1.0f, 0.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '?':
				m = glm::rotate(m_stack.top(), -angle, glm::vec3(0.0f, 1.0f, 0.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '&':
				m = glm::rotate(m_stack.top(), angle, glm::vec3(0.0f, 0.0f, 1.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '/':
				m = glm::rotate(m_stack.top(), -angle, glm::vec3(0.0f, 0.0f, 1.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '|':
				m = glm::rotate(m_stack.top(), 180.0f, glm::vec3(0.0f, 0.0f, 1.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '[':
				m_stack.push(m_stack.top());
				thickness /= thinning;
				branchStack.push(parent);
				break;
			case ']':
				m_stack.pop();
				thickness *= thinning;
				parent = branchStack.top();
				branchStack.pop();
				break;
			default:
				{
				//Trace::info("Encountered unkown turtle command: %c\n", chr);
				}
			}
		}
	}
Ejemplo n.º 30
0
bool MIRPoliticalLayer::init(KTPauseLayerDelegate *delegate)
{
    if (!KTPauseLayer::init(delegate)) {
        return false;
    }
    
    //adapt
    float bgHt;
    float tableViewHt;
    if (IS_IPHONE5) {
        bgHt = 800;
        tableViewHt = 680;
    } else if (IS_IPAD) {
        bgHt = 640;
        tableViewHt = 520;
    } else if (IS_IPAD_HD) {
        bgHt = (640 + 100) * 2;
        tableViewHt = (520 + 100)* 2;
    } else {
        bgHt = 600;
        tableViewHt = 480;
    }
    
    auto bg = LayerColor::create(MIRCellColor, winSize.width, bgHt);
    addChild(bg, -1);
    
    __Dictionary *root = __Dictionary::createWithContentsOfFile("Financial.plist");
    
    
    __Array *array = (__Array *)root->objectForKey("political");
    
    for (int i = 0; i < array->count(); i++) {
        
        __Dictionary *dict = (__Dictionary *)array->getObjectAtIndex(i);
        
        MIRModel *m = new MIRModel(dict);
        _dataArray.insert(0, m);
        m->release();
        m->update(InvestmentType::POLITICAL, array->count() - 1 - i);
        
    }
    
    _tableView = TableView::create(this, Size(winSize.width, tableViewHt));
    _tableView->setDirection(ScrollView::Direction::VERTICAL);
    _tableView->setDelegate(this);
    _tableView->setPosition(Point(0, 120 * _scale));
    _tableView->setColor(Color3B(255, 0, 0));
    addChild(_tableView);
    _tableView->reloadData();
    
    
    auto drawer = DrawNode::create();
    drawer->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
    drawer->setPosition(Point::ZERO);
    addChild(drawer, 128);
    
    
    auto type = Sprite::create("finantial_item.png");
    type->setScaleY(60/type->getContentSize().height);
    type->setAnchorPoint(Point::ZERO);
    type->setPosition(Point(0, _tableView->getPositionY() + _tableView->getViewSize().height));
    addChild(type);
    
    
    //画线
    drawer->drawSegment(type->getPosition(), Point(winSize.width, type->getPositionY()), 0.5, Color4F::WHITE);
    drawer->drawSegment(Point(0,type->getPositionY() + 60), Point(winSize.width, 60 + type->getPositionY()), 0.5, Color4F::WHITE);
    
    const float typeLabelX[4] = {static_cast<float>(0.06 * screenSize.width), static_cast<float>(0.38 * screenSize.width), static_cast<float>(0.6 * screenSize.width), static_cast<float>(0.89 * screenSize.width)};
    const char *typeStr[4] = {"项目", "等级", "消耗", "收益"};
    for (int i = 0; i < sizeof(typeLabelX)/sizeof(typeLabelX[0]); i++) {
        
        Label *typeLabel = Label::createWithTTF(typeStr[i], TITLE_FONT, 24);
        typeLabel->setPosition(Point(typeLabelX[i], type->getPositionY() + 30));
        typeLabel->setColor(MIRBrown);
        addChild(typeLabel);
    }
    
    auto header = Sprite::create("finantial_item.png");
    header->setScaleY(100/type->getContentSize().height);
    header->setAnchorPoint(Point::ZERO);
    header->setPosition(Point(0, type->getPositionY() + 60));
    addChild(header);
    
    auto titleLabel = Label::createWithTTF("海外投资", TITLE_FONT, 30);
    titleLabel->setPosition(Point(winSize.width/2, header->getPositionY() + 70));
    addChild(titleLabel);
    
    auto subTitle = Label::createWithTTF("(关闭游戏仍可获得收入)", TITLE_FONT, 26);
    subTitle->setTextColor(Color4B(MIRBrown));
    subTitle->setPosition(Point(winSize.width/2, header->getPositionY() + 26));
    addChild(subTitle);
    
    MenuItemImage *item = MenuItemImage::create("close_investments.png", "close_investments.png", [=](Ref *sender){
        this->playEffect(SOUND_BUTTON);
        doCancel();
    });
    item->setPosition(Point(winSize.width - 42, titleLabel->getPositionY()));
    
    auto menu = Menu::create(item, NULL);
    menu->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT);
    menu->setPosition(Point::ZERO);
    addChild(menu);
    
    
    
    return true;
}