Beispiel #1
0
void
matrix_display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glColor3ub(255, 255, 255);
    
    polygon_display();
    
    setfont("helvetica", 18);
    
    drawstr(10, translation[0].y-30, "glMatrixMode(GL_TEXTURE);");
    drawstr(10, translation[0].y, "glTranslatef(");
    drawstr(170, translation[0].y, ",");
    drawstr(230, translation[0].y, ","); 
    drawstr(290, translation[0].y, ");");
    drawstr(30, rotation[0].y, "glRotatef(");
    drawstr(170, rotation[0].y, ",");
    drawstr(230, rotation[0].y, ","); 
    drawstr(290, rotation[0].y, ",");
    drawstr(350, rotation[0].y, ");");
    drawstr(38, scale[0].y, "glScalef(");
    drawstr(170, scale[0].y, ",");
    drawstr(230, scale[0].y, ","); 
    drawstr(290, scale[0].y, ");");
    drawstr(10, scale[0].y+30, "glMatrixMode(GL_MODELVIEW);");
    
    cell_draw(&translation[0]);
    cell_draw(&translation[1]);
    cell_draw(&translation[2]);
    
    cell_draw(&rotation[0]);
    cell_draw(&rotation[1]);
    cell_draw(&rotation[2]);
    cell_draw(&rotation[3]);
    
    cell_draw(&scale[0]);
    cell_draw(&scale[1]);
    cell_draw(&scale[2]);
    
    if (!selection) {
        glColor3ub(255, 255, 0);
        drawstr(10, 525,
            "Click on the arguments and move the mouse to modify values.");
    }   
    
    glutSwapBuffers();
}
Beispiel #2
0
void
spotlight_display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3ub(255, 255, 255);

    lighting_display();

    setfont("helvetica", 18);
    drawstr(10, spot_direction[0].y, "GLfloat spot_direction[ ] = {");
    drawstr(10, spot_exponent.y, "GLint spot_exponent =                 "
            "spot_cutoff =   ");
    drawstr(spot_direction[0].x+50, spot_direction[0].y, ",");
    drawstr(spot_direction[1].x+50, spot_direction[1].y, ",");
    drawstr(spot_direction[2].x+50, spot_direction[2].y, "};");
    drawstr(spot_exponent.x+40, spot_cutoff.y, ",");
    drawstr(spot_cutoff.x+40, spot_cutoff.y, ";");

    setfont("helvetica", 12);
    drawstr(10, spot_cutoff.y+30,
            "glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction);");
    drawstr(10, spot_cutoff.y+50,
            "glLighti(GL_LIGHT0, GL_SPOT_EXPONENT, spot_exponent);");
    drawstr(10, spot_cutoff.y+70,
            "glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, spot_cutoff);");

    setfont("helvetica", 18);
    drawstr(10, Kc.y,
            "GLfloat Kc =          , Kl =          , Kq =          ;");

    setfont("helvetica", 12);
    drawstr(10, Kq.y+30, "glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, Kc);");
    drawstr(10, Kq.y+50, "glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, Kl);");
    drawstr(10, Kq.y+70, "glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, Kq);");

    setfont("helvetica", 18);
    cell_draw(&spot_direction[0]);
    cell_draw(&spot_direction[1]);
    cell_draw(&spot_direction[2]);

    cell_draw(&spot_exponent);
    cell_draw(&spot_cutoff);

    cell_draw(&Kc);
    cell_draw(&Kl);
    cell_draw(&Kq);

    if (!selection) {
        glColor3ub(255, 255, 0);
        drawstr(10, 525,
                "Click on the arguments and move the mouse to modify values.");
    }

    glutSwapBuffers();
}
Beispiel #3
0
Datei: sim.c Projekt: fouf/RAL
void simulation_render(float delta_time)
{
	if(cells != NULL)
	{
		int i = 0, j = 0;
		for(i = 0; i < MAP_HEIGHT; i++)
		{
			for(j = 0; j < MAP_WIDTH; j++)
			{
				cell_draw(j, i);
			}
		}
	}
	update_graph();
}
Beispiel #4
0
void
command_display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glColor3ub(255, 255, 255);
    setfont("helvetica", 18);
    drawstr(20, color[0].y, "GLfloat color[4] = {");
    drawstr(230, color[0].y, ",");
    drawstr(290, color[0].y, ","); 
    drawstr(350, color[0].y, ",");
    drawstr(410, color[0].y, "};");
    drawstr(20, 80, "glFogfv(GL_FOG_COLOR, color);");
    if (mode == GL_LINEAR) {
        drawstr(20, fstart.y, "glFogf(GL_FOG_START, ");
        drawstr(290, fstart.y, ");");
        drawstr(20, fend.y, "glFogf(GL_FOG_END, ");
        drawstr(290, fend.y, ");");
    } else {
        drawstr(20, density.y, "glFogf(GL_FOG_DENSITY, ");
        drawstr(310, density.y, ");");
    }
    drawstr(20, 200, "glFogi(GL_FOG_MODE, %s);", 
        mode == GL_LINEAR ? "GL_LINEAR" : 
    mode == GL_EXP ? "GL_EXP" : "GL_EXP2");
    
    cell_draw(&color[0]);
    cell_draw(&color[1]);
    cell_draw(&color[2]);
    cell_draw(&color[3]);
    
    if (mode == GL_LINEAR) {
        cell_draw(&fstart);
        cell_draw(&fend);
    } else {
        cell_draw(&density);
    }
    
    if (!selection) {
        glColor3ub(255, 255, 0);
        drawstr(10, 240,
            "Click on the arguments and move the mouse to modify values.");
    }   
    
    glutSwapBuffers();
}
Beispiel #5
0
int display( char *name,
             char *mapset,
             RASTER_MAP_TYPE data_type )
{
  struct Colors colors;

  if ( G_read_colors( name, mapset, &colors ) == -1 )
    G_fatal_error(( "Color file for <%s> not available" ), name );

  //G_set_null_value_color(r, g, b, &colors);

  /* Go draw the raster map */
  cell_draw( name, mapset, &colors, data_type );

  /* release the colors now */
  G_free_colors( &colors );

  return 0;
}
Beispiel #6
0
void
lmodel_display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3ub(255, 255, 255);

    lighting_display();

    setfont("helvetica", 18);
    drawstr(10, lmodel_Ka[0].y, "GLfloat lmodel_Ka[ ] = {");
    drawstr(lmodel_Ka[0].x+50, lmodel_Ka[0].y, ",");
    drawstr(lmodel_Ka[1].x+50, lmodel_Ka[1].y, ",");
    drawstr(lmodel_Ka[2].x+50, lmodel_Ka[2].y, ",");
    drawstr(lmodel_Ka[3].x+50, lmodel_Ka[3].y, "};");

    setfont("helvetica", 12);
    drawstr(10, lmodel_Ka[3].y+30,
            "glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_Ka);");

    setfont("helvetica", 18);
    drawstr(10, local_viewer.y, "glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, ");
    drawstr(local_viewer.x+35, local_viewer.y, ");");

    drawstr(10, two_side.y, "glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, ");
    drawstr(two_side.x+35, two_side.y, ");");

    cell_draw(&lmodel_Ka[0]);
    cell_draw(&lmodel_Ka[1]);
    cell_draw(&lmodel_Ka[2]);
    cell_draw(&lmodel_Ka[3]);

    cell_draw(&local_viewer);
    cell_draw(&two_side);

    if (!selection) {
        glColor3ub(255, 255, 0);
        drawstr(10, 525,
                "Click on the arguments and move the mouse to modify values.");
    }

    glutSwapBuffers();
}
Beispiel #7
0
void
command_display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glColor3ub(255,255,255);
    
    setfont("helvetica", 18);
    
    if (mode == PERSPECTIVE) {
        drawstr(180, perspective[0].y-40, "fovy"); 
        drawstr(230, perspective[0].y-40, "aspect"); 
        drawstr(300, perspective[0].y-40, "zNear"); 
        drawstr(360, perspective[0].y-40, "zFar");
    } else {
        drawstr(120, perspective[0].y-40, "left"); 
        drawstr(180, perspective[0].y-40, "right"); 
        drawstr(230, perspective[0].y-40, "bottom");
        drawstr(310, perspective[0].y-40, "top"); 
        drawstr(360, perspective[0].y-40, "near");
        drawstr(420, perspective[0].y-40, "far");
    }
    
    if (mode == PERSPECTIVE) {
        drawstr(40, perspective[0].y, "gluPerspective(");
        drawstr(230, perspective[0].y, ","); 
        drawstr(290, perspective[0].y, ",");
        drawstr(350, perspective[0].y, ",");
        drawstr(410, perspective[0].y, ");");
    } else if (mode == FRUSTUM) {
        drawstr(20, frustum[0].y, "glFrustum(");
        drawstr(170, frustum[0].y, ",");
        drawstr(230, frustum[0].y, ","); 
        drawstr(290, frustum[0].y, ",");
        drawstr(350, frustum[0].y, ",");
        drawstr(410, frustum[0].y, ","); 
        drawstr(470, frustum[0].y, ");");
    } else {
        drawstr(35, ortho[0].y, "glOrtho(");
        drawstr(170, ortho[0].y, ",");
        drawstr(230, ortho[0].y, ","); 
        drawstr(290, ortho[0].y, ",");
        drawstr(350, ortho[0].y, ",");
        drawstr(410, ortho[0].y, ","); 
        drawstr(470, ortho[0].y, ");");
    }
    
    drawstr(78, lookat[0].y, "gluLookAt(");
    drawstr(230, lookat[0].y, ","); 
    drawstr(290, lookat[0].y, ",");
    drawstr(350, lookat[0].y, ",");
    drawstr(380, lookat[0].y, "<- eye");
    drawstr(230, lookat[3].y, ","); 
    drawstr(290, lookat[3].y, ",");
    drawstr(350, lookat[3].y, ",");
    drawstr(380, lookat[3].y, "<- center");
    drawstr(230, lookat[6].y, ","); 
    drawstr(290, lookat[6].y, ",");
    drawstr(350, lookat[6].y, ");");
    drawstr(380, lookat[6].y, "<- up");
    
    if (mode == PERSPECTIVE) {
        cell_draw(&perspective[0]);
        cell_draw(&perspective[1]);
        cell_draw(&perspective[2]);
        cell_draw(&perspective[3]); 
    } else if (mode == FRUSTUM) {
        cell_draw(&frustum[0]);
        cell_draw(&frustum[1]);
        cell_draw(&frustum[2]);
        cell_draw(&frustum[3]);
        cell_draw(&frustum[4]);
        cell_draw(&frustum[5]);
    } else if (mode == ORTHO) {
        cell_draw(&ortho[0]);
        cell_draw(&ortho[1]);
        cell_draw(&ortho[2]);
        cell_draw(&ortho[3]);
        cell_draw(&ortho[4]);
        cell_draw(&ortho[5]);
    }   
    
    cell_draw(&lookat[0]);
    cell_draw(&lookat[1]);
    cell_draw(&lookat[2]);
    cell_draw(&lookat[3]);
    cell_draw(&lookat[4]);
    cell_draw(&lookat[5]);
    cell_draw(&lookat[6]);
    cell_draw(&lookat[7]);
    cell_draw(&lookat[8]);
    
    if (!selection) {
        glColor3ub(255, 255, 0);
        drawstr(10, 240,
            "Click on the arguments and move the mouse to modify values.");
    }   
    
    glutSwapBuffers();
}
Beispiel #8
0
void
lighting_display(void)
{
    setfont("helvetica", 18);
    drawstr(10, light_pos[0].y, "GLfloat light_pos[ ] = {");
    drawstr(10, light_Ka[0].y, "GLfloat light_Ka[ ] = {");
    drawstr(10, light_Kd[0].y, "GLfloat light_Kd[ ] = {");
    drawstr(10, light_Ks[0].y, "GLfloat light_Ks[ ] = {");
    drawstr(light_pos[0].x+50, light_pos[0].y, ",");
    drawstr(light_pos[1].x+50, light_pos[1].y, ",");
    drawstr(light_pos[2].x+50, light_pos[2].y, ",");
    drawstr(light_pos[3].x+50, light_pos[3].y, "};");
    drawstr(light_Ka[0].x+50, light_Ka[0].y, ",");
    drawstr(light_Ka[1].x+50, light_Ka[1].y, ",");
    drawstr(light_Ka[2].x+50, light_Ka[2].y, ",");
    drawstr(light_Ka[3].x+50, light_Ka[3].y, "};");
    drawstr(light_Kd[0].x+50, light_Kd[0].y, ",");
    drawstr(light_Kd[1].x+50, light_Kd[1].y, ",");
    drawstr(light_Kd[2].x+50, light_Kd[2].y, ",");
    drawstr(light_Kd[3].x+50, light_Kd[3].y, "};");
    drawstr(light_Ks[0].x+50, light_Ks[0].y, ",");
    drawstr(light_Ks[1].x+50, light_Ks[1].y, ",");
    drawstr(light_Ks[2].x+50, light_Ks[2].y, ",");
    drawstr(light_Ks[3].x+50, light_Ks[3].y, "};");

    setfont("helvetica", 12);
    drawstr(10, light_Ks[0].y+30,
            "glLightfv(GL_LIGHT0, GL_POSITION, light_pos);");
    drawstr(10, light_Ks[1].y+50,
            "glLightfv(GL_LIGHT0, GL_AMBIENT, light_Ka);");
    drawstr(10, light_Ks[2].y+70,
            "glLightfv(GL_LIGHT0, GL_DIFFUSE, light_Kd);");
    drawstr(10, light_Ks[3].y+90,
            "glLightfv(GL_LIGHT0, GL_SPECULAR, light_Ks);");

    setfont("helvetica", 18);

    cell_draw(&light_pos[0]);
    cell_draw(&light_pos[1]);
    cell_draw(&light_pos[2]);
    cell_draw(&light_pos[3]);

    cell_draw(&light_Ka[0]);
    cell_draw(&light_Ka[1]);
    cell_draw(&light_Ka[2]);
    cell_draw(&light_Ka[3]);

    cell_draw(&light_Kd[0]);
    cell_draw(&light_Kd[1]);
    cell_draw(&light_Kd[2]);
    cell_draw(&light_Kd[3]);

    cell_draw(&light_Ks[0]);
    cell_draw(&light_Ks[1]);
    cell_draw(&light_Ks[2]);
    cell_draw(&light_Ks[3]);

    glColor3ub(255, 255, 255);
}
Beispiel #9
0
void
material_display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3ub(255, 255, 255);

    lighting_display();

    setfont("helvetica", 18);
    drawstr(10, material_Ka[0].y, "GLfloat material_Ka[ ] = {");
    drawstr(10, material_Kd[0].y, "GLfloat material_Kd[ ] = {");
    drawstr(10, material_Ks[0].y, "GLfloat material_Ks[ ] = {");
    drawstr(10, material_Ke[0].y, "GLfloat material_Ke[ ] = {");
    drawstr(10, material_Se.y, "GLfloat material_Se =          ;");
    drawstr(material_Ka[0].x+50, material_Ka[0].y, ",");
    drawstr(material_Ka[1].x+50, material_Ka[1].y, ",");
    drawstr(material_Ka[2].x+50, material_Ka[2].y, ",");
    drawstr(material_Ka[3].x+50, material_Ka[3].y, "};");
    drawstr(material_Kd[0].x+50, material_Kd[0].y, ",");
    drawstr(material_Kd[1].x+50, material_Kd[1].y, ",");
    drawstr(material_Kd[2].x+50, material_Kd[2].y, ",");
    drawstr(material_Kd[3].x+50, material_Kd[3].y, "};");
    drawstr(material_Ks[0].x+50, material_Ks[0].y, ",");
    drawstr(material_Ks[1].x+50, material_Ks[1].y, ",");
    drawstr(material_Ks[2].x+50, material_Ks[2].y, ",");
    drawstr(material_Ks[3].x+50, material_Ks[3].y, "};");
    drawstr(material_Ke[0].x+50, material_Ke[0].y, ",");
    drawstr(material_Ke[1].x+50, material_Ke[1].y, ",");
    drawstr(material_Ke[2].x+50, material_Ke[2].y, ",");
    drawstr(material_Ke[3].x+50, material_Ke[3].y, "};");

    setfont("helvetica", 12);
    drawstr(10, material_Se.y+30,
            "glMaterialfv(GL_FRONT, GL_AMBIENT, material_Ka);");
    drawstr(10, material_Se.y+50,
            "glMaterialfv(GL_FRONT, GL_DIFFUSE, material_Kd);");
    drawstr(10, material_Se.y+70,
            "glMaterialfv(GL_FRONT, GL_SPECULAR, material_Ks);");
    drawstr(10, material_Se.y+90,
            "glMaterialfv(GL_FRONT, GL_EMISSION, material_Ke);");
    drawstr(10, material_Se.y+110,
            "glMaterialfv(GL_FRONT, GL_SHININESS, material_Se);");

    setfont("helvetica", 18);

    cell_draw(&material_Ka[0]);
    cell_draw(&material_Ka[1]);
    cell_draw(&material_Ka[2]);
    cell_draw(&material_Ka[3]);

    cell_draw(&material_Kd[0]);
    cell_draw(&material_Kd[1]);
    cell_draw(&material_Kd[2]);
    cell_draw(&material_Kd[3]);

    cell_draw(&material_Ks[0]);
    cell_draw(&material_Ks[1]);
    cell_draw(&material_Ks[2]);
    cell_draw(&material_Ks[3]);

    cell_draw(&material_Ke[0]);
    cell_draw(&material_Ke[1]);
    cell_draw(&material_Ke[2]);
    cell_draw(&material_Ke[3]);

    cell_draw(&material_Se);

    if (!selection) {
        glColor3ub(255, 255, 0);
        drawstr(10, 525,
                "Click on the arguments and move the mouse to modify values.");
    }

    glutSwapBuffers();
}
Beispiel #10
0
void
parameters_display(void)
{
    float pos[4];
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glColor3ub(255, 255, 255);
    
    polygon_display();
    
    setfont("helvetica", 18);
    drawstr(10, bcolor[0].y, "GLfloat border_color[ ] = { ");
    drawstr(bcolor[0].x+40, bcolor[0].y, ",");
    drawstr(bcolor[1].x+40, bcolor[0].y, ",");
    drawstr(bcolor[2].x+40, bcolor[0].y, ",");
    drawstr(bcolor[3].x+40, bcolor[0].y, "};");
    drawstr(10, ecolor[0].y, "GLfloat env_color[ ] = { ");
    drawstr(ecolor[0].x+40, ecolor[0].y, ",");
    drawstr(ecolor[1].x+40, ecolor[0].y, ",");
    drawstr(ecolor[2].x+40, ecolor[0].y, ",");
    drawstr(ecolor[3].x+40, ecolor[0].y, "};");
    
    setfont("helvetica", 12);
    drawstr(10, 90, "glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR,"
        " border_color);");
    drawstr(10, 110, "glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, "
        "env_color);");
    
    drawstr(10, 140, "glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,");
    drawstr(10, 160, "glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,");
    drawstr(10, 180, "glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,");
    drawstr(10, 200, "glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,");
    drawstr(10, 220, "glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,");
    
    glColor3ub(0, 255, 128);
    if (minfilter == GL_LINEAR_MIPMAP_LINEAR) {
        drawstr(380, 140, "GL_LINEAR_MIPMAP_LINEAR");
    } else if (minfilter == GL_LINEAR_MIPMAP_NEAREST) {
        drawstr(380, 140, "GL_LINEAR_MIPMAP_NEAREST");
    } else if (minfilter == GL_NEAREST_MIPMAP_LINEAR) {
        drawstr(380, 140, "GL_NEAREST_MIPMAP_LINEAR");
    } else if (minfilter == GL_NEAREST_MIPMAP_NEAREST) {
        drawstr(380, 140, "GL_NEAREST_MIPMAP_NEAREST");
    } else if (minfilter == GL_LINEAR) {
        drawstr(380, 140, "GL_LINEAR");
    } else {
        drawstr(380, 140, "GL_NEAREST");
    }
    
    glColor3ub(255, 255, 255);
    glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); 
    drawstr(pos[0]+2, glutGet(GLUT_WINDOW_HEIGHT)-pos[1]-1, ");");
    glColor3ub(0, 255, 128);
    
    if (magfilter == GL_LINEAR) {
        drawstr(390, 160, "GL_LINEAR");
    } else {
        drawstr(390, 160, "GL_NEAREST");
    }
    
    glColor3ub(255, 255, 255);
    glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); 
    drawstr(pos[0]+2, glutGet(GLUT_WINDOW_HEIGHT)-pos[1]-1, ");");
    glColor3ub(0, 255, 128);
    
    if (wraps == GL_REPEAT) {
        drawstr(360, 180, "GL_REPEAT");
    } else {
        drawstr(360, 180, "GL_CLAMP");
    }
    
    glColor3ub(255, 255, 255);
    glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); 
    drawstr(pos[0]+2, glutGet(GLUT_WINDOW_HEIGHT)-pos[1]-1, ");");
    glColor3ub(0, 255, 128);
    
    if (wrapt == GL_REPEAT) {
        drawstr(360, 200, "GL_REPEAT");
    } else {
        drawstr(360, 200, "GL_CLAMP");
    }
    
    glColor3ub(255, 255, 255);
    glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); 
    drawstr(pos[0]+2, glutGet(GLUT_WINDOW_HEIGHT)-pos[1]-1, ");");
    glColor3ub(0, 255, 128);
    
    if (env == GL_MODULATE) {
        drawstr(360, 220, "GL_MODULATE");
    } else if (env == GL_DECAL) {
        drawstr(360, 220, "GL_DECAL");
    } else if (env == GL_BLEND) {
        drawstr(360, 220, "GL_BLEND");
    } else {
        drawstr(360, 220, "GL_REPLACE");
    }
    
    glColor3ub(255, 255, 255);
    glGetFloatv(GL_CURRENT_RASTER_POSITION, pos); 
    drawstr(pos[0]+2, glutGet(GLUT_WINDOW_HEIGHT)-pos[1]-1, ");");
    
    setfont("helvetica", 18);
    
    cell_draw(&bcolor[0]);
    cell_draw(&bcolor[1]);
    cell_draw(&bcolor[2]);
    cell_draw(&bcolor[3]);
    
    cell_draw(&ecolor[0]);
    cell_draw(&ecolor[1]);
    cell_draw(&ecolor[2]);
    cell_draw(&ecolor[3]);
    
    if (!selection) {
        glColor3ub(255, 255, 0);
        drawstr(10, 525,
            "Click on the arguments and move the mouse to modify values.");
    }   
    
    glutSwapBuffers();
}
Beispiel #11
0
void
polygon_display(void)
{
    setfont("helvetica", 12);
    
    drawstr(10, pcolor[0].y-50, "glEnable(GL_TEXTURE_2D);");
    drawstr(10, pcolor[0].y-30, "gluBuild2DMipmaps(GL_TEXTURE_2D, 3, w, h, "
        "GL_RGB, GL_UNSIGNED_BYTE, image);");
    
    setfont("helvetica", 18);
    
    drawstr(10, pcolor[0].y, "glColor4f(");
    drawstr(pcolor[0].x+50, pcolor[0].y, ",");
    drawstr(pcolor[1].x+50, pcolor[1].y, ","); 
    drawstr(pcolor[2].x+50, pcolor[2].y, ","); 
    drawstr(pcolor[3].x+50, pcolor[2].y, ");"); 
    
    drawstr(10, texcoords[0].y-30, "glBegin(GL_POLYGON);");
    drawstr(10, texcoords[0].y, "glTexCoord2f(");
    drawstr(texcoords[0].x+40, texcoords[0].y, ",");
    drawstr(texcoords[1].x+40, texcoords[1].y, ");"); 
    drawstr(250, vertices[0].y, "glVertex3f(");
    drawstr(vertices[0].x+40, vertices[0].y, ",");
    drawstr(vertices[1].x+40, vertices[1].y, ","); 
    drawstr(vertices[2].x+40, vertices[1].y, ");"); 
    
    drawstr(10, texcoords[2].y, "glTexCoord2f(");
    drawstr(texcoords[2].x+40, texcoords[2].y, ",");
    drawstr(texcoords[3].x+40, texcoords[3].y, ");"); 
    drawstr(250, vertices[3].y, "glVertex3f(");
    drawstr(vertices[3].x+40, vertices[3].y, ",");
    drawstr(vertices[4].x+40, vertices[4].y, ","); 
    drawstr(vertices[5].x+40, vertices[5].y, ");"); 
    
    drawstr(10, texcoords[4].y, "glTexCoord2f(");
    drawstr(texcoords[4].x+40, texcoords[4].y, ",");
    drawstr(texcoords[5].x+40, texcoords[5].y, ");"); 
    drawstr(250, vertices[6].y, "glVertex3f(");
    drawstr(vertices[6].x+40, vertices[6].y, ",");
    drawstr(vertices[7].x+40, vertices[7].y, ","); 
    drawstr(vertices[8].x+40, vertices[8].y, ");"); 
    
    drawstr(10, texcoords[6].y, "glTexCoord2f(");
    drawstr(texcoords[6].x+40, texcoords[6].y, ",");
    drawstr(texcoords[7].x+40, texcoords[7].y, ");"); 
    drawstr(250, vertices[9].y, "glVertex3f(");
    drawstr(vertices[9].x+40, vertices[9].y, ",");
    drawstr(vertices[10].x+40, vertices[10].y, ","); 
    drawstr(vertices[11].x+40, vertices[11].y, ");"); 
    
    drawstr(10, vertices[11].y+30, "glEnd();");
    
    cell_draw(&texcoords[0]); 
    cell_draw(&texcoords[1]); 
    cell_draw(&texcoords[2]); 
    cell_draw(&texcoords[3]); 
    cell_draw(&texcoords[4]); 
    cell_draw(&texcoords[5]); 
    cell_draw(&texcoords[6]); 
    cell_draw(&texcoords[7]); 
    
    cell_draw(&vertices[0]);
    cell_draw(&vertices[1]);
    cell_draw(&vertices[2]);
    cell_draw(&vertices[3]);
    cell_draw(&vertices[4]);
    cell_draw(&vertices[5]);
    cell_draw(&vertices[6]);
    cell_draw(&vertices[7]);
    cell_draw(&vertices[8]);
    cell_draw(&vertices[9]);
    cell_draw(&vertices[10]);
    cell_draw(&vertices[11]);
    
    cell_draw(&pcolor[0]);
    cell_draw(&pcolor[1]);
    cell_draw(&pcolor[2]);
    cell_draw(&pcolor[3]);
    
    glColor3ub(255, 255, 255);
}
Beispiel #12
0
void
command_display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    if (swapped) {
        translation[0].y = 80;
        translation[1].y = 80;
        translation[2].y = 80;
        rotation[0].y = 40;
        rotation[1].y = 40;
        rotation[2].y = 40;
        rotation[3].y = 40;
    } else {
        translation[0].y = 40;
        translation[1].y = 40;
        translation[2].y = 40;
        rotation[0].y = 80;
        rotation[1].y = 80;
        rotation[2].y = 80;
        rotation[3].y = 80;
    }
    
    glColor3ub(255, 255, 255);
    setfont("helvetica", 18);
    drawstr(30, rotation[0].y, "glRotatef(");
    drawstr(170, rotation[0].y, ",");
    drawstr(230, rotation[0].y, ","); 
    drawstr(290, rotation[0].y, ",");
    drawstr(350, rotation[0].y, ");");
    drawstr(10, translation[0].y, "glTranslatef(");
    drawstr(170, translation[0].y, ",");
    drawstr(230, translation[0].y, ","); 
    drawstr(290, translation[0].y, ");");
    drawstr(38, 120, "glScalef(");
    drawstr(170, 120, ",");
    drawstr(230, 120, ","); 
    drawstr(290, 120, ");");
    drawstr(41, 160, "glBegin(  . . .  );");
    drawstr(41, 200, " . . .");
    
    cell_draw(&translation[0]);
    cell_draw(&translation[1]);
    cell_draw(&translation[2]);
    
    cell_draw(&rotation[0]);
    cell_draw(&rotation[1]);
    cell_draw(&rotation[2]);
    cell_draw(&rotation[3]);
    
    cell_draw(&scale[0]);
    cell_draw(&scale[1]);
    cell_draw(&scale[2]);
    
    if (!selection) {
        glColor3ub(255, 255, 0);
        drawstr(10, 240,
            "Click on the arguments and move the mouse to modify values.");
    }   
    
    glutSwapBuffers();
}
Beispiel #13
0
void
command_display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3ub(255, 255, 255);

    setfont("helvetica", 18);
    if (swapped) {
        lookat[0].y = 120;
        lookat[1].y = 120;
        lookat[2].y = 120;
        lookat[3].y = 120+40;
        lookat[4].y = 120+40;
        lookat[5].y = 120+40;
        lookat[6].y = 120+80;
        lookat[7].y = 120+80;
        lookat[8].y = 120+80;
    } else {
        lookat[0].y = 80;
        lookat[1].y = 80;
        lookat[2].y = 80;
        lookat[3].y = 80+40;
        lookat[4].y = 80+40;
        lookat[5].y = 80+40;
        lookat[6].y = 80+80;
        lookat[7].y = 80+80;
        lookat[8].y = 80+80;
    }

    drawstr(30, light[0].y, "GLfloat pos[4] = {");
    drawstr(230, light[0].y, ",");
    drawstr(290, light[0].y, ","); 
    drawstr(350, light[0].y, ",");
    drawstr(410, light[0].y, "};");
    if (swapped)
      drawstr(30, 80, "glLightfv(GL_LIGHT0, GL_POSITION, pos);");
    else
      drawstr(30, 200, "glLightfv(GL_LIGHT0, GL_POSITION, pos);");
    drawstr(78, lookat[0].y, "gluLookAt(");
    drawstr(230, lookat[0].y, ","); 
    drawstr(290, lookat[0].y, ",");
    drawstr(350, lookat[0].y, ",");
    drawstr(380, lookat[0].y, "<- eye");
    drawstr(230, lookat[3].y, ","); 
    drawstr(290, lookat[3].y, ",");
    drawstr(350, lookat[3].y, ",");
    drawstr(380, lookat[3].y, "<- center");
    drawstr(230, lookat[6].y, ","); 
    drawstr(290, lookat[6].y, ",");
    drawstr(350, lookat[6].y, ");");
    drawstr(380, lookat[6].y, "<- up");

    cell_draw(&light[0]);
    cell_draw(&light[1]);
    cell_draw(&light[2]);
    cell_draw(&light[3]);

    cell_draw(&lookat[0]);
    cell_draw(&lookat[1]);
    cell_draw(&lookat[2]);
    cell_draw(&lookat[3]);
    cell_draw(&lookat[4]);
    cell_draw(&lookat[5]);
    cell_draw(&lookat[6]);
    cell_draw(&lookat[7]);
    cell_draw(&lookat[8]);

    if (!selection) {
	glColor3ub(255, 255, 0);
	drawstr(10, 240,
	     "Click on the arguments and move the mouse to modify values.");
    }   
    
    glutSwapBuffers();
}
Beispiel #14
0
static gboolean
item_grid_draw_region (GocItem const *item, cairo_t *cr,
		       double x_0, double y_0, double x_1, double y_1)
{
	GocCanvas *canvas = item->canvas;
	double scale = canvas->pixels_per_unit;
	gint64 x0 = x_0 * scale, y0 = y_0 * scale, x1 = x_1 * scale, y1 = y_1 * scale;
	gint width  = x1 - x0;
	gint height = y1 - y0;
	GnmPane *pane = GNM_PANE (canvas);
	Sheet const *sheet = scg_sheet (pane->simple.scg);
	WBCGtk *wbcg = scg_wbcg (pane->simple.scg);
	GnmCell const * const edit_cell = wbcg->editing_cell;
	GnmItemGrid *ig = GNM_ITEM_GRID (item);
	ColRowInfo const *ri = NULL, *next_ri = NULL;
	int const dir = sheet->text_is_rtl ? -1 : 1;
	SheetView const *sv = scg_view (ig->scg);
	WorkbookView *wbv = sv_wbv (sv);
	gboolean show_function_cell_markers = wbv->show_function_cell_markers;
	gboolean show_extension_markers = wbv->show_extension_markers;
	 /* we use the selected background color from an entry for selected cells */
	GtkWidget *entry = gtk_entry_new ();
	GtkStyleContext *ctxt = gtk_widget_get_style_context (entry);

	/* To ensure that far and near borders get drawn we pretend to draw +-2
	 * pixels around the target area which would include the surrounding
	 * borders if necessary */
	/* TODO : there is an opportunity to speed up the redraw loop by only
	 * painting the borders of the edges and not the content.
	 * However, that feels like more hassle that it is worth.  Look into this someday.
	 */
	int x;
	gint64 y, start_x, offset;
	int col, row, n, start_col, end_col;
	int start_row = gnm_pane_find_row (pane, y0-2, &y);
	int end_row = gnm_pane_find_row (pane, y1+2, NULL);
	gint64 const start_y = y - canvas->scroll_y1 * scale;

	GnmStyleRow sr, next_sr;
	GnmStyle const **styles;
	GnmBorder const **borders, **prev_vert;
	GnmBorder const *none =
		sheet->hide_grid ? NULL : gnm_style_border_none ();

	GnmRange     view;
	GSList	 *merged_active, *merged_active_seen,
		 *merged_used, *merged_unused, *ptr, **lag;

	int *colwidths = NULL;

	gboolean const draw_selection =
		ig->scg->selected_objects == NULL &&
		wbcg->new_object == NULL;

	start_col = gnm_pane_find_col (pane, x0-2, &start_x);
	end_col   = gnm_pane_find_col (pane, x1+2, NULL);

	g_return_val_if_fail (start_col <= end_col, TRUE);

#if 0
	g_printerr ("%s:", cell_coord_name (start_col, start_row));
	g_printerr ("%s <= %ld vs ???", cell_coord_name(end_col, end_row), (long)y);
	g_printerr (" [%s]\n", cell_coord_name (ig->bound.end.col, ig->bound.end.row));

#endif

	/* clip to bounds */
	if (end_col > ig->bound.end.col)
		end_col = ig->bound.end.col;
	if (end_row > ig->bound.end.row)
		end_row = ig->bound.end.row;

	/* Skip any hidden cols/rows at the start */
	for (; start_col <= end_col ; ++start_col) {
		ri = sheet_col_get_info (sheet, start_col);
		if (ri->visible)
			break;
	}
	for (; start_row <= end_row ; ++start_row) {
		ri = sheet_row_get_info (sheet, start_row);
		if (ri->visible)
			break;
	}

	/* if everything is hidden no need to draw */
	if (end_col < ig->bound.start.col || start_col > ig->bound.end.col ||
	    end_row < ig->bound.start.row || start_row > ig->bound.end.row)
		return TRUE;

	/* Respan all rows that need it.  */
	for (row = start_row; row <= end_row; row++) {
		ColRowInfo const *ri = sheet_row_get_info (sheet, row);
		if (ri->visible && ri->needs_respan)
			row_calc_spans ((ColRowInfo *)ri, row, sheet);
	}

	sheet_style_update_grid_color (sheet);

	/* Fill entire region with default background (even past far edge) */
	cairo_save (cr);
	if (canvas->direction == GOC_DIRECTION_LTR)
		gtk_render_background (goc_item_get_style_context (item),
				       cr,
				       x0 - canvas->scroll_x1 * scale,
				       y0 - canvas->scroll_y1 * scale,
				       width, height);
	else
		gtk_render_background (goc_item_get_style_context (item),
				       cr,
				       canvas->width - x0 + canvas->scroll_x1 * scale - width,
				       y0 - canvas->scroll_y1 * scale,
				       width, height);
	cairo_restore (cr);

	/* Get ordered list of merged regions */
	merged_active = merged_active_seen = merged_used = NULL;
	merged_unused = gnm_sheet_merge_get_overlap (sheet,
		range_init (&view, start_col, start_row, end_col, end_row));

	/*
	 * allocate a single blob of memory for all 8 arrays of pointers.
	 *	- 6 arrays of n GnmBorder const *
	 *	- 2 arrays of n GnmStyle const *
	 *
	 * then alias the arrays for easy access so that array [col] is valid
	 * for all elements start_col-1 .. end_col+1 inclusive.
	 * Note that this means that in some cases array [-1] is legal.
	 */
	n = end_col - start_col + 3; /* 1 before, 1 after, 1 fencepost */
	style_row_init (&prev_vert, &sr, &next_sr, start_col, end_col,
			g_alloca (n * 8 * sizeof (gpointer)), sheet->hide_grid);

	/* load up the styles for the first row */
	next_sr.row = sr.row = row = start_row;
	sheet_style_get_row (sheet, &sr);

	/* Collect the column widths */
	colwidths = g_alloca (n * sizeof (int));
	colwidths -= start_col;
	for (col = start_col; col <= end_col; col++) {
		ColRowInfo const *ci = sheet_col_get_info (sheet, col);
		colwidths[col] = ci->visible ? ci->size_pixels : -1;
	}

	goc_canvas_c2w (canvas, start_x / scale, 0, &x, NULL);
	start_x = x;
	for (y = start_y; row <= end_row; row = sr.row = next_sr.row, ri = next_ri) {
		/* Restore the set of ranges seen, but still active.
		 * Reinverting list to maintain the original order */
		g_return_val_if_fail (merged_active == NULL, TRUE);

#if DEBUG_SELECTION_PAINT
		g_printerr ("row = %d (startcol = %d)\n", row, start_col);
#endif
		while (merged_active_seen != NULL) {
			GSList *tmp = merged_active_seen->next;
			merged_active_seen->next = merged_active;
			merged_active = merged_active_seen;
			merged_active_seen = tmp;
			MERGE_DEBUG (merged_active->data, " : seen -> active\n");
		}

		/* find the next visible row */
		while (1) {
			++next_sr.row;
			if (next_sr.row <= end_row) {
				next_ri = sheet_row_get_info (sheet, next_sr.row);
				if (next_ri->visible) {
					sheet_style_get_row (sheet, &next_sr);
					break;
				}
			} else {
				for (col = start_col ; col <= end_col; ++col)
					next_sr.vertical [col] =
					next_sr.bottom [col] = none;
				break;
			}
		}

		/* look for merges that start on this row, on the first painted row
		 * also check for merges that start above. */
		view.start.row = row;
		lag = &merged_unused;
		for (ptr = merged_unused; ptr != NULL; ) {
			GnmRange * const r = ptr->data;

			if (r->start.row <= row) {
				GSList *tmp = ptr;
				ptr = *lag = tmp->next;
				if (r->end.row < row) {
					tmp->next = merged_used;
					merged_used = tmp;
					MERGE_DEBUG (r, " : unused -> used\n");
				} else {
					ColRowInfo const *ci =
						sheet_col_get_info (sheet, r->start.col);
					g_slist_free_1 (tmp);
					merged_active = g_slist_insert_sorted (merged_active, r,
								(GCompareFunc)merged_col_cmp);
					MERGE_DEBUG (r, " : unused -> active\n");

					if (ci->visible)
						item_grid_draw_merged_range (cr, ig,
									     start_x, y, &view, r,
									     draw_selection,
									     ctxt);
				}
			} else {
				lag = &(ptr->next);
				ptr = ptr->next;
			}
		}

		for (col = start_col, x = start_x; col <= end_col ; col++) {
			GnmStyle const *style;
			CellSpanInfo const *span;
			ColRowInfo const *ci = sheet_col_get_info (sheet, col);

#if DEBUG_SELECTION_PAINT
			g_printerr ("col [%d] = %d\n", col, x);
#endif
			if (!ci->visible) {
				if (merged_active != NULL) {
					GnmRange const *r = merged_active->data;
					if (r->end.col == col) {
						ptr = merged_active;
						merged_active = merged_active->next;
						if (r->end.row <= row) {
							ptr->next = merged_used;
							merged_used = ptr;
							MERGE_DEBUG (r, " : active2 -> used\n");
						} else {
							ptr->next = merged_active_seen;
							merged_active_seen = ptr;
							MERGE_DEBUG (r, " : active2 -> seen\n");
						}
					}
				}
				continue;
			}

			/* Skip any merged regions */
			if (merged_active != NULL) {
				GnmRange const *r = merged_active->data;
				if (r->start.col <= col) {
					gboolean clear_top, clear_bottom = FALSE;
					int i, first = r->start.col;
					int last  = r->end.col;

					ptr = merged_active;
					merged_active = merged_active->next;
					if (r->end.row <= row) {
						ptr->next = merged_used;
						merged_used = ptr;
						MERGE_DEBUG (r, " : active -> used\n");

						/* in case something managed the bottom of a merge */
						if (r->end.row < row)
							goto plain_draw;
					} else {
						ptr->next = merged_active_seen;
						merged_active_seen = ptr;
						MERGE_DEBUG (r, " : active -> seen\n");
						if (next_sr.row <= r->end.row)
							clear_bottom = TRUE;
					}

					x += dir * scg_colrow_distance_get (
						pane->simple.scg, TRUE, col, last+1);
					col = last;

					if (first < start_col) {
						first = start_col;
						sr.vertical [first] = NULL;
					}
					if (last > end_col) {
						last = end_col;
						sr.vertical [last+1] = NULL;
					}
					clear_top = (r->start.row != row);

					/* Clear the borders */
					for (i = first ; i <= last ; i++) {
						if (clear_top)
							sr.top [i] = NULL;
						if (clear_bottom)
							sr.bottom [i] = NULL;
						if (i > first)
							sr.vertical [i] = NULL;
					}
					continue;
				}
			}

plain_draw : /* a quick hack to deal with 142267 */
			if (dir < 0)
				x -= ci->size_pixels;
			style = sr.styles [col];
			item_grid_draw_background (cr, ig,
				style, col, row, x, y,
				ci->size_pixels, ri->size_pixels,
				draw_selection, ctxt);


			/* Is this part of a span?
			 * 1) There are cells allocated in the row
			 *       (indicated by ri->spans != NULL)
			 * 2) Look in the rows hash table to see if
			 *    there is a span descriptor.
			 */
			if (NULL == ri->spans || NULL == (span = row_span_get (ri, col))) {

				/* If it is being edited pretend it is empty to
				 * avoid problems with long cells'
				 * contents extending past the edge of the edit
				 * box.  Ignore blanks too.
				 */
				GnmCell const *cell = sheet_cell_get (sheet, col, row);
				if (!gnm_cell_is_empty (cell) && cell != edit_cell) {
					if (show_function_cell_markers)
						draw_function_marker (ig, cell, cr, x, y,
								      ci->size_pixels,
								      ri->size_pixels,
								      dir);
					cell_draw (cell, cr,
						   x, y, ci->size_pixels,
						   ri->size_pixels, -1,
						   show_extension_markers);
				}
			/* Only draw spaning cells after all the backgrounds
			 * that we are going to draw have been drawn.  No need
			 * to draw the edit cell, or blanks. */
			} else if (edit_cell != span->cell &&
				   (col == span->right || col == end_col)) {
				GnmCell const *cell = span->cell;
				int const start_span_col = span->left;
				int const end_span_col = span->right;
				int real_x = x;
				ColRowInfo const *cell_col =
					sheet_col_get_info (sheet, cell->pos.col);
				int center_offset = cell_col->size_pixels/2;
				int tmp_width = ci->size_pixels;

				if (col != cell->pos.col)
					style = sheet_style_get (sheet,
						cell->pos.col, row);

				/* x, y are relative to this cell origin, but the cell
				 * might be using columns to the left (if it is set to right
				 * justify or center justify) compute the pixel difference */
				if (dir > 0 && start_span_col != cell->pos.col)
					center_offset += scg_colrow_distance_get (
						pane->simple.scg, TRUE,
						start_span_col, cell->pos.col);
				else if (dir < 0 && end_span_col != cell->pos.col)
					center_offset += scg_colrow_distance_get (
						pane->simple.scg, TRUE,
						cell->pos.col, end_span_col);

				if (start_span_col != col) {
					offset = scg_colrow_distance_get (
						pane->simple.scg, TRUE,
						start_span_col, col);
					tmp_width += offset;
					if (dir > 0)
						real_x -= offset;
					sr.vertical [col] = NULL;
				}
				if (end_span_col != col) {
					offset = scg_colrow_distance_get (
						pane->simple.scg, TRUE,
						col+1, end_span_col + 1);
					tmp_width += offset;
					if (dir < 0)
						real_x -= offset;
				}

				if (show_function_cell_markers)
					draw_function_marker (ig, cell, cr, real_x, y,
							      tmp_width,
							      ri->size_pixels, dir);
				cell_draw (cell, cr,
					   real_x, y, tmp_width,
					   ri->size_pixels, center_offset,
					   show_extension_markers);

			} else if (col != span->left)
				sr.vertical [col] = NULL;

			if (dir > 0)
				x += ci->size_pixels;
		}
		gnm_style_borders_row_draw (prev_vert, &sr,
					cr, start_x, y, y+ri->size_pixels,
					colwidths, TRUE, dir);

		/* In case there were hidden merges that trailed off the end */
		while (merged_active != NULL) {
			GnmRange const *r = merged_active->data;
			ptr = merged_active;
			merged_active = merged_active->next;
			if (r->end.row <= row) {
				ptr->next = merged_used;
				merged_used = ptr;
				MERGE_DEBUG (r, " : active3 -> used\n");
			} else {
				ptr->next = merged_active_seen;
				merged_active_seen = ptr;
				MERGE_DEBUG (r, " : active3 -> seen\n");
			}
		}

		/* roll the pointers */
		borders = prev_vert; prev_vert = sr.vertical;
		sr.vertical = next_sr.vertical; next_sr.vertical = borders;
		borders = sr.top; sr.top = sr.bottom;
		sr.bottom = next_sr.top = next_sr.bottom; next_sr.bottom = borders;
		styles = sr.styles; sr.styles = next_sr.styles; next_sr.styles = styles;

		y += ri->size_pixels;
	}

	if (ig->bound.start.row > 0 && start_y < 1)
		ig_cairo_draw_bound (ig, cr, start_x, 1, x, 1);
	if (ig->bound.start.col > 0) {
		if (canvas->direction == GOC_DIRECTION_RTL && start_x >= goc_canvas_get_width (canvas)) {
			x = goc_canvas_get_width (canvas);
			ig_cairo_draw_bound (ig, cr, x, start_y, x, y);
		} else if (canvas->direction == GOC_DIRECTION_LTR && start_x < 1)
			ig_cairo_draw_bound (ig, cr, 1, start_y, 1, y);
	}

	g_object_ref_sink (entry);
	g_object_unref (entry);

	g_slist_free (merged_used);	   /* merges with bottom in view */
	g_slist_free (merged_active_seen); /* merges with bottom the view */
	g_slist_free (merged_unused);	   /* merges in hidden rows */
	g_return_val_if_fail (merged_active == NULL, TRUE);
	return TRUE;
}
Beispiel #15
0
static void
item_grid_draw_merged_range (cairo_t *cr, GnmItemGrid *ig,
			     int start_x, int start_y,
			     GnmRange const *view, GnmRange const *range,
			     gboolean draw_selection, GtkStyleContext *ctxt)
{
	int l, r, t, b, last;
	SheetView const *sv = scg_view (ig->scg);
	WorkbookView *wbv = sv_wbv (sv);
	gboolean show_function_cell_markers = wbv->show_function_cell_markers;
	gboolean show_extension_markers = wbv->show_extension_markers;
	Sheet const *sheet  = sv->sheet;
	GnmCell const *cell = sheet_cell_get (sheet, range->start.col, range->start.row);
	int const dir = sheet->text_is_rtl ? -1 : 1;

	/* load style from corner which may not be visible */
	GnmStyle const *style = sheet_style_get (sheet, range->start.col, range->start.row);
	gboolean const is_selected = draw_selection &&
		(sv->edit_pos.col != range->start.col ||
		 sv->edit_pos.row != range->start.row) &&
		sv_is_full_range_selected (sv, range);

	/* Get the coordinates of the visible region */
	l = r = start_x;
	if (view->start.col < range->start.col)
		l += dir * scg_colrow_distance_get (ig->scg, TRUE,
			view->start.col, range->start.col);
	if (range->end.col <= (last = view->end.col))
		last = range->end.col;
	r += dir * scg_colrow_distance_get (ig->scg, TRUE, view->start.col, last+1);

	t = b = start_y;
	if (view->start.row < range->start.row)
		t += scg_colrow_distance_get (ig->scg, FALSE,
			view->start.row, range->start.row);
	if (range->end.row <= (last = view->end.row))
		last = range->end.row;
	b += scg_colrow_distance_get (ig->scg, FALSE, view->start.row, last+1);

	if (l == r || t == b)
		return;

	if (style->conditions) {
		GnmEvalPos ep;
		int res;
		eval_pos_init (&ep, (Sheet *)sheet, range->start.col, range->start.row);
		if ((res = gnm_style_conditions_eval (style->conditions, &ep)) >= 0)
			style = g_ptr_array_index (style->cond_styles, res);
	}

	/* Check for background THEN selection */
	if (gnumeric_background_set (style, cr, is_selected, ctxt) ||
	    is_selected) {
		/* Remember X excludes the far pixels */
		if (dir > 0)
			cairo_rectangle (cr, l, t, r-l+1, b-t+1);
		else
			cairo_rectangle (cr, r, t, l-r+1, b-t+1);
		cairo_fill (cr);
	}

	/* Expand the coords to include non-visible areas too.  The clipped
	 * region is only necessary when drawing the background */
	if (range->start.col < view->start.col)
		l -= dir * scg_colrow_distance_get (ig->scg, TRUE,
			range->start.col, view->start.col);
	if (view->end.col < range->end.col)
		r += dir * scg_colrow_distance_get (ig->scg, TRUE,
			view->end.col+1, range->end.col+1);
	if (range->start.row < view->start.row)
		t -= scg_colrow_distance_get (ig->scg, FALSE,
			range->start.row, view->start.row);
	if (view->end.row < range->end.row)
		b += scg_colrow_distance_get (ig->scg, FALSE,
			view->end.row+1, range->end.row+1);

	if (cell != NULL) {
		ColRowInfo *ri = sheet_row_get (sheet, range->start.row);

		if (ri->needs_respan)
			row_calc_spans (ri, cell->pos.row, sheet);

		if (dir > 0) {
			if (show_function_cell_markers)
				draw_function_marker (ig, cell, cr, l, t,
						      r - l, b - t, dir);
			cell_draw (cell, cr,
				   l, t, r - l, b - t, -1,
				   show_extension_markers);
		} else {
			if (show_function_cell_markers)
				draw_function_marker (ig, cell, cr, r, t,
						      l - r, b - t, dir);
			cell_draw (cell, cr,
				   r, t, l - r, b - t, -1,
				   show_extension_markers);
		}
	}
	if (dir > 0)
		gnm_style_border_draw_diag (style, cr, l, t, r, b);
	else
		gnm_style_border_draw_diag (style, cr, r, t, l, b);
}
Beispiel #16
0
/* no spans or merges */
static gboolean
preview_grid_draw_region (GocItem const *item, cairo_t *cr,
			  double x0, double y0, double x1, double y1)
{
	GnmPreviewGrid *pg = GNM_PREVIEW_GRID (item);

	/* To ensure that far and near borders get drawn we pretend to draw +-2
	 * pixels around the target area which would include the surrounding
	 * borders if necessary */
	/* TODO : there is an opportunity to speed up the redraw loop by only
	 * painting the borders of the edges and not the content.
	 * However, that feels like more hassle that it is worth.  Look into this someday.
	 */
	int x, y, col, row, n;
	int const start_col = pg_get_col_offset (pg, x0 - 2, &x);
	int end_col         = pg_get_col_offset (pg, x1 + 2, NULL);
	int diff_x    = x;
	int start_row       = pg_get_row_offset (pg, y0 - 2, &y);
	int end_row         = pg_get_row_offset (pg, y1 + 2, NULL);
	int diff_y    = y;
	int row_height = pg->defaults.row_height;

	GnmStyleRow sr, next_sr;
	GnmStyle const **styles;
	GnmBorder const **borders, **prev_vert;
	GnmBorder const *none = pg->gridlines ? gnm_style_border_none () : NULL;

	int *colwidths = NULL;

	gnm_style_border_none_set_color (style_color_grid ());

	/*
	 * allocate a single blob of memory for all 8 arrays of pointers.
	 *	- 6 arrays of n GnmBorder const *
	 *	- 2 arrays of n GnmStyle const *
	 */
	n = end_col - start_col + 3; /* 1 before, 1 after, 1 fencepost */
	style_row_init (&prev_vert, &sr, &next_sr, start_col, end_col,
			g_alloca (n * 8 * sizeof (gpointer)), !pg->gridlines);

	/* load up the styles for the first row */
	next_sr.row = sr.row = row = start_row;
	pg_style_get_row (pg, &sr);

	/* Collect the column widths */
	colwidths = g_alloca (n * sizeof (int));
	colwidths -= start_col;
	for (col = start_col; col <= end_col; col++)
		colwidths[col] = pg->defaults.col_width;

	/* Fill entire region with default background (even past far edge) */
	gtk_render_background (goc_item_get_style_context (item),
			       cr, diff_x, diff_y, x1 - x0, y1 - y0);

	for (y = diff_y; row <= end_row; row = sr.row = next_sr.row) {
		if (++next_sr.row > end_row) {
			for (col = start_col ; col <= end_col; ++col)
				next_sr.vertical[col] =
				next_sr.bottom[col] = none;
		} else
			pg_style_get_row (pg, &next_sr);

		for (col = start_col, x = diff_x; col <= end_col; col++) {
			GnmStyle const *style = sr.styles[col];
			GnmCell const *cell = pg_fetch_cell (pg, col, row);

			preview_grid_draw_background (cr, pg,
						      style, col, row, x, y,
						      colwidths[col], row_height);

			if (!gnm_cell_is_empty (cell))
				cell_draw (cell, cr,
					   x, y, colwidths[col], row_height,
					   -1, FALSE);

			x += colwidths[col];
		}

		gnm_style_borders_row_draw
			(prev_vert, &sr, cr,
			 diff_x, y, y + row_height,
			 colwidths, TRUE, 1 /* cheat dir == 1 for now */);

		/* roll the pointers */
		borders = prev_vert; prev_vert = sr.vertical;
		sr.vertical = next_sr.vertical; next_sr.vertical = borders;
		borders = sr.top; sr.top = sr.bottom;
		sr.bottom = next_sr.top = next_sr.bottom; next_sr.bottom = borders;
		styles = sr.styles; sr.styles = next_sr.styles; next_sr.styles = styles;

		y += row_height;
	}
	return TRUE;
}