root/paper-tape-project/trunk/visualisator/lochstreifen.h

Revision 19, 8.1 kB (checked in by sven, 4 years ago)

The Gtk::PaperTape? gtkmm implementation of the GtkPaperTape? widget. Now
quite more object oriented, using a MVC approach. There's much still to
do.

I commit these files now because I won't be able to work at the project
in the next week(s). Afterwards I plan to make more use of the
versioning features, commiting on a more regular basis.

-- Sven @ workstation

Line 
1#ifndef __LOCHSTREIFEN_H__
2#define __LOCHSTREIFEN_H__
3
4// if C++ compiling...
5#ifdef __cplusplus
6extern "C" {
7#endif 
8
9#include <cairo-svg.h> /* because using cairo_t */
10
11typedef unsigned char byte_t;
12typedef struct lochstreifen LOCHSTREIFEN;
13
14/**
15 * Identifing a track.
16 * This enum is used in various functions.
17 * Principally it's only sensefule for the
18 * LOCHSTREIFEN_NO_TRACK value.
19 **/
20typedef enum lochstreifen_track {
21        LOCHSTREIFEN_TRACK_0        = 0,
22        LOCHSTREIFEN_TRACK_1        = 1,
23        LOCHSTREIFEN_TRACK_2        = 2,
24        LOCHSTREIFEN_TRACK_FEED     = -13,
25        LOCHSTREIFEN_TRACK_3        = 3,
26        LOCHSTREIFEN_TRACK_4        = 4,
27        LOCHSTREIFEN_TRACK_5        = 5,
28        LOCHSTREIFEN_TRACK_6        = 6,
29        LOCHSTREIFEN_TRACK_7        = 7,
30        LOCHSTREIFEN_NO_TRACK       = -42
31} track_t;
32
33/**
34 * This typedef just says: This int represents a row in a LOCHSTREIFEN
35 * It's range should be >= 0 and <= the data_len member of the
36 * LOCHSTREIFEN structure.
37 * The MAX_INT value is therefore also the value of bytes which can be
38 * drawn: 4 GB. That's pretty much, because it all must be held in RAM ;-)
39 **/
40typedef int row_t;
41
42/**
43 * The adequate to the lochstreifen_track enum value LOCHSTREIFEN_NO_TRACK.
44 * If a row_t == LOCHSTREIFEN_NO_ROW, it indicates that this
45 * is not a row at all. Of course you could also simply use check if
46 * row_t is < 0, but this is more meaningful.
47 **/
48#define LOCHSTREIFEN_NO_ROW  -1
49
50/**
51 * To be used as a return value, in comparision with
52 * LOCHSTREIFEN_NO_ROW and LOCHSTREIFEN_NO_TRACK: It indicates that
53 * everything successed.
54 **/
55#define LOCHSTREIFEN_SUCCESS (-42*42)
56
57/**
58 * This is the LOCHSTREIFEN structure. It will always be referenced as a
59 * pointer, created by lochstreifen_new(). This function will also
60 * initialize the LOCHSTREIFEN structure.
61 * It's commonly referenced as "*l" or "l->", using "l" as abbrevation
62 * for LOCHSTREIFEN.
63 **/
64struct lochstreifen {
65        /* DATA (not supposed to be set directly) */
66        /// Length of data array (counting from 1, like argc)
67        int data_length;
68        /// data array (the data which LOCHSTREIFEN will print)
69        byte_t *data;
70
71        /* COLORS / SWITCHES WHETER PARTS ARE PAINTED */
72        cairo_pattern_t *outer_background_color;
73        cairo_pattern_t *papertape_background_color;
74        cairo_pattern_t *one_code_hole_color;
75        cairo_pattern_t *zero_code_hole_color;
76        cairo_pattern_t *feed_hole_color;
77
78        /// Highlighting a (row/byte) region
79        row_t highlight_region_start; ///< counting from 0, already in selection
80        row_t highlight_region_end;   ///< counting from 0, no more in selection
81        cairo_pattern_t *highlight_region_color; ///< == NULL => no selection painted
82
83        /// Highlight one special row
84        row_t highlight_row_number;  ///< counting from 0
85        cairo_pattern_t *highlight_row_color;
86
87        /// Highlight one special bit (not complete track)
88        row_t   highlight_bit_row;
89        track_t highlight_bit_track;
90        cairo_pattern_t *highlight_bit_color;
91
92        /// Perfomant Clipping
93        cairo_rectangle_t *clip;
94       
95        /// Matrix to apply for every paint process
96        /// Call lochstreifen_check_matrix() after you have touched it.
97        cairo_matrix_t matrix;
98
99        /// Callback functions:
100        void (*row_callback) (const row_t* current_row, cairo_t* context, void* user_data);
101        void* row_callback_user_data;
102        //void (*bit_callback)
103        // etc.
104
105        /*<private>*/
106        /* The following datas are private. */
107       
108        /// Make debug output if debug != 0.
109        byte_t debug;
110       
111        /// Inverse CTM. Don't touch it, use
112        /// lochstreifen_check_matrix() instead to calculate it automatically
113        cairo_matrix_t matrix_inverse;
114};
115
116/// The default color values
117#define LOCHSTREIFEN_DEFAULT_OUTER_BACKGROUND_COLOR        NULL
118#define LOCHSTREIFEN_DEFAULT_PAPERTAPE_BACKGROUND_COLOR    cairo_pattern_create_rgb(0.7, 0.7, 0.7)
119#define LOCHSTREIFEN_DEFAULT_ONE_CODE_HOLE_COLOR           cairo_pattern_create_rgb(0,   0,   0)
120#define LOCHSTREIFEN_DEFAULT_ZERO_CODE_HOLE_COLOR          NULL
121#define LOCHSTREIFEN_DEFAULT_FEED_HOLE_COLOR               cairo_pattern_create_rgb(0.5, 0.7, 1)
122#define LOCHSTREIFEN_DEFAULT_HIGHLIGHT_REGION_COLOR        cairo_pattern_create_rgb(0.95,  1, 0)
123#define LOCHSTREIFEN_DEFAULT_HIGHLIGHT_ROW_COLOR           cairo_pattern_create_rgb(1,     0, 0)
124#define LOCHSTREIFEN_DEFAULT_HIGHLIGHT_BIT_COLOR           cairo_pattern_create_rgb(1,1,1)
125#define LOCHSTREIFEN_DEFAULT_CTM                           { 1, 0, 0, 1, 0, 0 }
126
127/// dimensions of the paper tape after ECMA-10 standard
128
129// width of paper tape, according to "PROPERTIES OF UNPUNCHED TAPE", section 1.1.2:
130// 25.40mm = 1". This is the "base" unit in our vector drawing.
131#define LOCHSTREIFEN_WIDTH                 1.0
132
133// length of tear-off: about the half of the width of a papertape
134#define LOCHSTREIFEN_TEAR_OFF_LENGTH       ( 0.5 * LOCHSTREIFEN_WIDTH )
135
136// Within a row the distance of the centres of the code holes from
137// the centre of the feed hole shall be 2,54mm (=0.1"), where n is an integer.
138#define LOCHSTREIFEN_TRACK_DISTANCE        0.1
139
140// The distance between two adjacent rows shall be 2,54mm (=0.1") measured
141// at the feed holes.
142#define LOCHSTREIFEN_ROW_DISTANCE          0.1
143
144// feed hole diameter: 1.170mm
145#define LOCHSTREIFEN_RADIUS_FEED_HOLE    ( (1.170 / 25.40) / 2)
146
147// code hol diameter: 1.83mm
148#define LOCHSTREIFEN_RADIUS_CODE_HOLE    ( (1.830 / 25.40) / 2)
149
150// length of paper tape: Tear off at start and end, data rows + 0.05" offset at start + end spacing
151#define LOCHSTREIFEN_LENGTH              ( 2 * LOCHSTREIFEN_TEAR_OFF_LENGTH + \
152                                           LOCHSTREIFEN_ROW_DISTANCE * (l->data_length + 1) )
153
154typedef enum lochstreifen_direction {
155        // special values for compatibility to old implementation
156        LOCHSTREIFEN_MOVEMENT_TO_LEFT       = 0,
157        LOCHSTREIFEN_MOVEMENT_TO_TOP        = 1,
158        LOCHSTREIFEN_MOVEMENT_TO_RIGHT      = 2,
159        LOCHSTREIFEN_MOVEMENT_TO_BOTTOM     = 3,
160        LOCHSTREIFEN_MOVEMENT_NONE          = -1,
161        LOCHSTREIFEN_ROTATION_CLOCKWISE     = 4,
162        LOCHSTREIFEN_ROTATION_ANTICLOCKWISE = 5
163} lochstreifen_direction_t;
164
165
166
167
168
169// functions
170LOCHSTREIFEN *lochstreifen_new();
171LOCHSTREIFEN* lochstreifen_copy(const LOCHSTREIFEN* t);
172void lochstreifen_free(LOCHSTREIFEN* l);
173void lochstreifen_print_debug(LOCHSTREIFEN* l);
174void lochstreifen_set_data(LOCHSTREIFEN *l, int data_length, byte_t *data);
175void lochstreifen_add_null_bytes(LOCHSTREIFEN *l, int start, int end);
176double lochstreifen_get_length(LOCHSTREIFEN *l);
177void lochstreifen_set_highlight_region(LOCHSTREIFEN *l, int start, int end);
178int lochstreifen_get_highlight_region(LOCHSTREIFEN *l, int *start, int *end);
179void lochstreifen_remove_highlight_region(LOCHSTREIFEN *l);
180void lochstreifen_set_highlight_row(LOCHSTREIFEN *l, int number_of_row);
181int lochstreifen_get_highlight_row(LOCHSTREIFEN *l);
182void lochstreifen_remove_highlight_row(LOCHSTREIFEN *l);
183void lochstreifen_set_highlight_bit(LOCHSTREIFEN *l, int number_of_row, int number_of_bit);
184int lochstreifen_get_highlight_bit(LOCHSTREIFEN *l, int *number_of_row, int *number_of_bit);
185void lochstreifen_remove_highlight_bit(LOCHSTREIFEN *l);
186void lochstreifen_set_clip(LOCHSTREIFEN *l, double x, double y, double width, double height);
187void lochstreifen_remove_clip(LOCHSTREIFEN *l);
188void lochstreifen_check_matrix(LOCHSTREIFEN* l);
189void lochstreifen_set_scaling_by_length(LOCHSTREIFEN *l, int length);
190void lochstreifen_set_scaling_by_width(LOCHSTREIFEN *l, int width);
191void lochstreifen_set_scaling_by_code_hole(LOCHSTREIFEN *l, int diameter);
192void lochstreifen_get_target_dimensions(LOCHSTREIFEN *l, int *width, int *height);
193int lochstreifen_get_target_width(LOCHSTREIFEN *l);
194int lochstreifen_get_target_height(LOCHSTREIFEN *l);
195void lochstreifen_get_target_bit_from_point(LOCHSTREIFEN* l, row_t* row, track_t* track, double x, double y);
196row_t lochstreifen_get_target_row_from_point(LOCHSTREIFEN* l, double x, double y);
197track_t lochstreifen_get_target_track_from_point(LOCHSTREIFEN* l, double x, double y);
198int lochstreifen_get_target_rect_from_row(LOCHSTREIFEN* l, row_t row, cairo_rectangle_t* rect);
199int lochstreifen_get_target_rect_from_bit(LOCHSTREIFEN* l, row_t row, track_t track, cairo_rectangle_t* rect);
200void lochstreifen_set_rotation(LOCHSTREIFEN *l, enum lochstreifen_direction direction);
201void lochstreifen_draw(LOCHSTREIFEN *l, cairo_t *cr);
202
203#ifdef __cplusplus
204} // extern "C"
205#endif 
206
207
208#endif /* __LOCHSTREIFEN_H__ */
Note: See TracBrowser for help on using the browser.
© 2008 - 2010 Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License