Root/eeshow/gfx/gfx.c

1/*
2 * gfx/gfx.c - Generate graphical output for Eeschema items
3 *
4 * Written 2016 by Werner Almesberger
5 * Copyright 2016 by Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdbool.h>
15
16#include "gfx/style.h"
17#include "gfx/text.h"
18#include "gfx/gfx.h"
19
20
21void *gfx_ctx;
22
23static const struct gfx_ops *gfx_ops;
24
25
26void gfx_line(int sx, int sy, int ex, int ey, int color, unsigned layer)
27{
28    if (gfx_ops->line) {
29        gfx_ops->line(gfx_ctx, sx, sy, ex, ey, color, layer);
30        return;
31    }
32
33    int vx[] = { sx, ex };
34    int vy[] = { sy, ey };
35
36    gfx_poly(2, vx, vy, color, COLOR_NONE, layer);
37}
38
39
40void gfx_rect(int sx, int sy, int ex, int ey,
41    int color, int fill_color, unsigned layer)
42{
43    if (gfx_ops->rect) {
44        gfx_ops->rect(gfx_ctx, sx, sy, ex, ey,
45            color, fill_color, layer);
46        return;
47    }
48
49    int vx[] = { sx, ex, ex, sx, sx };
50    int vy[] = { sy, sy, ey, ey, sy };
51
52    gfx_poly(5, vx, vy, color, fill_color, layer);
53}
54
55
56void gfx_poly(int points, const int x[points], const int y[points],
57    int color, int fill_color, unsigned layer)
58{
59    gfx_ops->poly(gfx_ctx, points, x, y, color, fill_color, layer);
60}
61
62
63void gfx_circ(int x, int y, int r, int color, int fill_color, unsigned layer)
64{
65    gfx_ops->circ(gfx_ctx, x, y, r, color, fill_color, layer);
66}
67
68
69void gfx_arc(int x, int y, int r, int sa, int ea,
70    int color, int fill_color, unsigned layer)
71{
72    gfx_ops->arc(gfx_ctx, x, y, r, sa, ea, color, fill_color, layer);
73}
74
75
76void gfx_text(int x, int y, const char *s, unsigned size,
77    enum text_align align, int rot, unsigned color, unsigned layer)
78{
79    gfx_ops->text(gfx_ctx, x, y, s, size, align, rot, color, layer);
80}
81
82
83void gfx_tag(const char *s,
84    unsigned points, const int x[points], int const y[points])
85{
86    if (gfx_ops->tag)
87        gfx_ops->tag(gfx_ctx, s, points, x, y);
88}
89
90
91unsigned gfx_text_width(const char *s, unsigned size)
92{
93    return gfx_ops->text_width(gfx_ctx, s, size);
94}
95
96
97void gfx_init(const struct gfx_ops *ops, int argc, char *const *argv)
98{
99    gfx_ctx = ops->init(argc, argv);
100    gfx_ops = ops;
101}
102
103
104void gfx_sheet_name(const char *name)
105{
106    if (gfx_ops->sheet_name)
107        gfx_ops->sheet_name(gfx_ctx, name);
108}
109
110
111void gfx_new_sheet(void)
112{
113    if (gfx_ops->new_sheet)
114        gfx_ops->new_sheet(gfx_ctx);
115}
116
117
118bool gfx_multi_sheet(void)
119{
120    return !!gfx_ops->new_sheet;
121}
122
123void gfx_end(void)
124{
125    if (gfx_ops->end)
126        gfx_ops->end(gfx_ctx);
127}
128

Archive Download this file

Branches:
master



interactive