Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
linear_gradient.c File Reference
#include "cairo_test.h"
#include "stdio.h"

Go to the source code of this file.

Defines

#define N_GRADIENT_ANGLES   3
#define N_ROTATE_ANGLES   3
#define N_N_STOPS   2
#define UNIT_SIZE   75
#define UNIT_SIZE   75
#define PAD   5
#define WIDTH   N_GRADIENT_ANGLES * UNIT_SIZE + (N_GRADIENT_ANGLES + 1) * PAD
#define HEIGHT   N_N_STOPS * N_ROTATE_ANGLES * UNIT_SIZE + (N_N_STOPS * N_ROTATE_ANGLES + 1) * PAD

Functions

static void draw_unit (cairo_t *cr, double gradient_angle, double rotate_angle, int n_stops)
static void draw (cairo_t *cr, int width, int height)
int main (void)

Variables

static const double gradient_angles [] = { 0, 45, 90 }
static const double rotate_angles [] = { 0, 45, 90 }
static const int n_stops [] = { 2, 3 }
cairo_test_t test

Define Documentation

Definition at line 55 of file linear_gradient.c.

Definition at line 44 of file linear_gradient.c.

#define N_N_STOPS   2

Definition at line 48 of file linear_gradient.c.

Definition at line 46 of file linear_gradient.c.

#define PAD   5

Definition at line 52 of file linear_gradient.c.

#define UNIT_SIZE   75

Definition at line 51 of file linear_gradient.c.

#define UNIT_SIZE   75

Definition at line 51 of file linear_gradient.c.

Definition at line 54 of file linear_gradient.c.


Function Documentation

static void draw ( cairo_t *  cr,
int  width,
int  height 
) [static]

Definition at line 112 of file linear_gradient.c.

{
    int i, j, k;

    cairo_set_rgb_color (cr, 0.5, 0.5, 0.5);
    cairo_rectangle (cr, 0, 0, width, height);
    cairo_fill (cr);

    for (i = 0; i < N_GRADIENT_ANGLES; i++)
       for (j = 0; j < N_ROTATE_ANGLES; j++)
         for (k = 0; k < N_N_STOPS; k++) {
              cairo_save (cr);
              cairo_translate (cr,
                             PAD + (PAD + UNIT_SIZE) * i,
                             PAD + (PAD + UNIT_SIZE) * (N_ROTATE_ANGLES * k + j));
              cairo_scale (cr, UNIT_SIZE, UNIT_SIZE);
              
              draw_unit (cr,
                        gradient_angles[i] * M_PI / 180.,
                        rotate_angles[j] * M_PI / 180.,
                        n_stops[k]);
              cairo_restore (cr);
           }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void draw_unit ( cairo_t *  cr,
double  gradient_angle,
double  rotate_angle,
int  n_stops 
) [static]

Definition at line 64 of file linear_gradient.c.

{
    cairo_pattern_t *pattern;

    cairo_rectangle (cr, 0, 0, 1, 1);
    cairo_clip (cr);
    cairo_new_path(cr);
    
    cairo_set_rgb_color (cr, 0.0, 0.0, 0.0);
    cairo_rectangle (cr, 0, 0, 1, 1);
    cairo_fill (cr);
    
    cairo_translate (cr, 0.5, 0.5);
    cairo_scale (cr, 1 / 1.5, 1 / 1.5);
    cairo_rotate (cr, rotate_angle);
    
    pattern = cairo_pattern_create_linear (-0.5 * cos (gradient_angle),  -0.5 * sin (gradient_angle),
                                       0.5 * cos (gradient_angle),   0.5 * sin (gradient_angle));

    if (n_stops == 2) {
       cairo_pattern_add_color_stop (pattern, 0.,
                                  0.3, 0.3, 0.3,
                                  1.0);
       cairo_pattern_add_color_stop (pattern, 1.,
                                  1.0, 1.0, 1.0,
                                  1.0);
    } else {
       cairo_pattern_add_color_stop (pattern, 0.,
                                  1.0, 0.0, 0.0,
                                  1.0);
       cairo_pattern_add_color_stop (pattern, 0.5,
                                  1.0, 1.0, 1.0,
                                  1.0);
       cairo_pattern_add_color_stop (pattern, 1.,
                                  0.0, 0.0, 1.0,
                                  1.0);
    }

    cairo_set_pattern (cr, pattern);
    cairo_pattern_destroy (pattern);
    cairo_rectangle (cr, -0.5, -0.5, 1, 1);
    cairo_fill (cr);
}

Here is the caller graph for this function:

int main ( void  )

Definition at line 138 of file linear_gradient.c.

{
    return cairo_test (&test, draw);
}

Here is the call graph for this function:


Variable Documentation

const double gradient_angles[] = { 0, 45, 90 } [static]

Definition at line 43 of file linear_gradient.c.

const int n_stops[] = { 2, 3 } [static]

Definition at line 47 of file linear_gradient.c.

const double rotate_angles[] = { 0, 45, 90 } [static]

Definition at line 45 of file linear_gradient.c.

Initial value:
 {
    "linear_gradient",
    "Tests the drawing of linear gradients",
    WIDTH, HEIGHT
}

Definition at line 57 of file linear_gradient.c.