summaryrefslogtreecommitdiff
path: root/test/bezier.c
blob: c523da8942200f5910772b920a4e05c010220346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* libnsfb plotetr test program */

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

#include "libnsfb.h"
#include "libnsfb_plot.h"
#include "libnsfb_event.h"

#define UNUSED(x) ((x) = (x))


int main(int argc, char **argv)
{
    nsfb_t *nsfb;
    nsfb_event_t event;
    nsfb_bbox_t box;
    nsfb_bbox_t box2;
    uint8_t *fbptr;
    int fbstride;
    nsfb_point_t ctrla;
    nsfb_point_t ctrlb;
    int loop;
    nsfb_plot_pen_t pen;

    UNUSED(argc);
    UNUSED(argv);

    nsfb = nsfb_init(NSFB_FRONTEND_SDL);
    if (nsfb == NULL) {
        fprintf(stderr, "Unable to initialise nsfb with SDL frontend\n");
        return 1;
    }

    if (nsfb_init_frontend(nsfb) == -1) {
        fprintf(stderr, "Unable to initialise nsfb frontend\n");
        return 2;
    }

    /* get the geometry of the whole screen */
    box.x0 = box.y0 = 0;
    nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);

    nsfb_get_framebuffer(nsfb, &fbptr, &fbstride);

    /* claim the whole screen for update */
    nsfb_claim(nsfb, &box);

    nsfb_plot_clg(nsfb, 0xffffffff);

    box2.x0=100;
    box2.y0=100;

    box2.x1=400;
    box2.y1=400;

    for (loop=-300;loop < 600;loop+=100) {
    ctrla.x = 100;
    ctrla.y = loop;

    ctrlb.x = 400;
    ctrlb.y = 500 - loop;

    nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrlb, 0xff000000);
    }

    pen.stroke_colour = 0xff000000;

    box2.x0=400;
    box2.y0=100;

    box2.x1=600;
    box2.y1=400;

    nsfb_plot_line(nsfb, &box2, &pen);

    box2.x0=800;
    box2.y0=100;

    box2.x1=600;
    box2.y1=400;

    nsfb_plot_line(nsfb, &box2, &pen);

    box2.x0=400;
    box2.y0=100;

    box2.x1=800;
    box2.y1=100;

    ctrla.x = 600;
    ctrla.y = 400;

    nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrla, 0xffff0000);

    box2.x0=400;
    box2.y0=100;

    box2.x1=800;
    box2.y1=100;

    ctrla.x = 600;
    ctrla.y = 400;

    nsfb_plot_quadratic_bezier(nsfb, &box2, &ctrla, 0xff0000ff);

    nsfb_update(nsfb, &box);
    
    while (event.type != NSFB_EVENT_CONTROL)
        nsfb_event(nsfb, &event, -1);

    return 0;
}