Пример #1
0
inline bool
DrawingCursor::mayMoveDownwards(void) {
    return NodeCursor<VisualNode>::mayMoveDownwards() &&
           !node()->isHidden() &&
           node()->childrenLayoutIsDone() &&
           !isClipped();
}
Пример #2
0
//------------------------------------------------------------------------------
int GzPutTriangle(GzRender *render, int numParts, GzToken *nameList, GzPointer *valueList) {
    /* numParts : how many names and values */

    // Do some sanity checking    
    if(NULL == render || NULL == nameList || NULL == valueList || numParts != 3)
    {
        return GZ_FAILURE;
    } 
    
        
    Matrix *Xsm = render->xStack.leftMulMatricesOnStack();
    if (Xsm == NULL)
    {
        fprintf(stderr, "Got NULL from stack in GzPutTriangle.\n");
    } 
    
    
    
    
    GzCoord *c_old;
    GzCoord *n;
    GzColor triEdgeColors[3];
    GzTextureIndex *triTextures;
    
    for (int i = 0; i < numParts; i++)
    {
        int name = nameList[i];
        switch(name)
        {
            case GZ_POSITION:
            {
                // Get ready to read coordinates
                void *l1 = valueList;
                GzCoord **l2 = static_cast<GzCoord **> (l1);
                c_old = static_cast<GzCoord *> (l2[i]);
                
                break;
            }
            
            case GZ_NORMAL:
            {
                void *l1 = valueList;
                GzCoord **l2 = static_cast<GzCoord **> (l1);
                
                n = static_cast<GzCoord *> (l2[i]);
                
                
                if (render->interp_mode == GZ_COLOR) 
                {
                    for (int k = 0; k < 3; k++)
                        calc_color(render, n[k], triEdgeColors[k], (render->tex_fun == false));

                }

                break;
            }
            
            case GZ_TEXTURE_INDEX:
            {
                void *l1 = valueList;
                GzTextureIndex **l2 = static_cast<GzTextureIndex**> (l1);
                triTextures = l2[i];             
                
                break;
            }
            
            default:
                return GZ_FAILURE;            
        }// end of switch statement
    }//end of for loop
    
    
    
   

    GzCoord c[3];
    // Transform triangle coordinates into screen coordinates
    for(int i = 0; i < 3 ; i++)
    {
        float array[4] = {c_old[i][0], c_old[i][1], c_old[i][2], 1};
        float rMulResult[4] ={0, 0, 0, 0};
        Xsm->rightMultiply(array, 4, rMulResult);
        c[i][X] = rMulResult[0] + render->aa_delta_x;
        c[i][Y] = rMulResult[1] + render->aa_delta_y;
        c[i][Z] = rMulResult[2];           
    }

    // Lets see if all 3 triangle coordinates are viewable or not.
    if(isBehindViewPlane(render, c) || isClipped(render, c))
        return GZ_FAILURE;   

    // Find bounding box
    int x_min = floor(findMin(c, 0, 3));
    int x_max = ceil (findMax(c, 0, 3));
    int y_min = floor(findMin(c, 1, 3));
    int y_max = ceil (findMax(c, 1, 3));


    // Iterate over every pixel in the bounding box
    for(int j = y_min; j <= y_max; j++)        
        for(int i = x_min; i <= x_max; i++)
        {
            // Calculate Barycentric coordinates
            GzCoord p = {float(i), float(j), 0};
            float alpha = f(c[1], c[2], p) / f(c[1], c[2], c[0]);
            float beta  = f(c[2], c[0], p) / f(c[2], c[0], c[1]);
            float gamma = f(c[0], c[1], p) / f(c[0], c[1], c[2]);

            // Litmus Test: Is pixel (i,j) inside triangle?
            if ( alpha > 0 && beta > 0 && gamma > 0)                
            {
                //interpolate z value
                float newZ = alpha*(c[0][2]) + beta*(c[1][2]) + gamma*(c[2][2]);


                // Get current Z value for this specific pixel (i,j)
                GzIntensity dummy;
                GzDepth oldZ;
                GzGetDisplay(render->display, i, j, &dummy, &dummy, &dummy, &dummy, &oldZ);


                // Check will this pixel be displayed or not
                if(newZ < oldZ)
                {

                    GzColor interpColor = {0, 0, 0};                    
                    GzColor color = {1.0f, 1.0f, 1.0f}; // color coming from texture
                    if(render->tex_fun != false)
                        calcTexture(render, triTextures, c, newZ, alpha, beta, gamma, color);


                    
                    
                    
                    if(render->interp_mode == GZ_NORMALS) // Phong Shading
                    {
                        GzCoord interpN = {0,0,0};
                        for (int k = 0; k < 3; k++)
                            interpN[k] = alpha*n[0][k] + beta*n[1][k] + gamma*n[2][k];
                        
                        if(render->tex_fun != false)
                        {
                                memcpy(render->Ka, color, sizeof (GzColor));
                                memcpy(render->Kd, color, sizeof (GzColor));
                        }
                
                        

                          
                        calc_color(render, interpN, interpColor, true);
                        
                        GzPutDisplay(render->display, i, j, ctoi(interpColor[X]), ctoi(interpColor[Y]), ctoi(interpColor[Z]), 1, newZ);
                        
                    }
                    else if(render->interp_mode == GZ_COLOR) // Gouraud Shading
                    {
                        float r = alpha * triEdgeColors[0][X] + beta * triEdgeColors[1][X] + gamma * triEdgeColors[2][X];
                        float g = alpha * triEdgeColors[0][Y] + beta * triEdgeColors[1][Y] + gamma * triEdgeColors[2][Y];
                        float b = alpha * triEdgeColors[0][Z] + beta * triEdgeColors[1][Z] + gamma * triEdgeColors[2][Z];
                        
                        // Multiply by Kt which is in color due to earlier texture calculation
                        r *= color[RED];
                        g *= color[GREEN];
                        b *= color[BLUE];



                        GzPutDisplay(render->display, i, j, ctoi(r), ctoi(g), ctoi(b), 1, newZ);
                        
                    }
                    
                    
                    // FLAT Shading 
                                            
                        //GzPutDisplay(render->display, i, j, ctoi(render->flatcolor[0]), 
                        //ctoi(render->flatcolor[1]), ctoi(render->flatcolor[2]), 1, newZ);                   

                }


            }// end of litmus test if
        }   
    
    return GZ_SUCCESS;
}
void MarkedScrollBar::paintEvent(QPaintEvent *event)
{
    // Draw the scrollbar control
    QScrollBar::paintEvent(event);

    // Get the style options for the control
    QStyleOptionSlider styleOption;
    initStyleOption(&styleOption);

    // Get the bounding rectangles of the add/sub pages
    QRect addPage = style()->subControlRect(QStyle::CC_ScrollBar, &styleOption,
                                            QStyle::SC_ScrollBarAddPage, this);
    QRect subPage = style()->subControlRect(QStyle::CC_ScrollBar, &styleOption,
                                            QStyle::SC_ScrollBarSubPage, this);
    QRect slider = style()->subControlRect(QStyle::CC_ScrollBar, &styleOption,
                                           QStyle::SC_ScrollBarSlider, this);


    // Create a painter to do the actual drawing
    QPainter p(this);

    // Clip it so that we do not draw over the slider
	if (isClipped())
	{
		p.setClipRegion(QRegion(addPage) + QRegion(subPage));
	}

    // The scale factor to use
    qreal sf;

    // Scale and translate the painter appropriately
    if (orientation() == Qt::Horizontal)
    {
        p.translate(qMin(subPage.left(), addPage.left()), 0.0);

        sf = (addPage.width() + subPage.width() + slider.width())
           / ((qreal) maximum() - minimum());
    }
    else // if (orientation() == Qt::Vertical)
    {
        p.translate(0.0, qMin(subPage.top(), addPage.top()));

        sf = (addPage.height() + subPage.height() + slider.height())
           / ((qreal) maximum() - minimum());
    }

    foreach (markData mark, m_marks)
    {
        p.setPen(mark.colour);

        if (orientation() == Qt::Horizontal)
        {
            p.drawLine(QPoint(mark.pos * sf, 2),
                       QPoint(mark.pos * sf, slider.height() - 3));
        }
        else if (orientation() == Qt::Vertical)
        {
            p.drawLine(QPoint(2, mark.pos * sf),
                       QPoint(slider.width() - 3, mark.pos * sf));
        }
    }