summaryrefslogtreecommitdiff
path: root/twin.h
blob: c99a1f7729a4fb23972d855effe34294435a9ee9 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
/*
 * $Id$
 *
 * Copyright © 2004 Keith Packard
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Keith Packard not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Keith Packard makes no
 * representations about the suitability of this software for any purpose.  It
 * is provided "as is" without express or implied warranty.
 *
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _TWIN_H_
#define _TWIN_H_

#include <stdlib.h>
#include <stdint.h>
#include <twin_def.h>

typedef uint8_t	    twin_a8_t;
typedef uint16_t    twin_a16_t;
typedef uint16_t    twin_rgb16_t;
typedef uint32_t    twin_argb32_t;
typedef uint32_t    twin_ucs4_t;
typedef int	    twin_bool_t;
typedef int16_t	    twin_coord_t;
typedef int16_t	    twin_style_t;
typedef int16_t	    twin_count_t;
typedef int16_t	    twin_keysym_t;
typedef int32_t	    twin_area_t;
typedef int32_t	    twin_time_t;
typedef int16_t	    twin_stretch_t;

#define TWIN_FALSE  0
#define TWIN_TRUE   1

typedef enum { TWIN_A8, TWIN_RGB16, TWIN_ARGB32 } twin_format_t;

#define twin_bytes_per_pixel(format)    (1 << (twin_coord_t) (format))

/*
 * Angles
 */
typedef int16_t	    twin_angle_t;   /* -2048 .. 2048 for -180 .. 180 */

#define TWIN_ANGLE_360	    4096
#define TWIN_ANGLE_180	    (TWIN_ANGLE_360 >> 1)
#define TWIN_ANGLE_90	    (TWIN_ANGLE_360 >> 2)
#define TWIN_ANGLE_45	    (TWIN_ANGLE_360 >> 3)
#define TWIN_ANGLE_22_5	    (TWIN_ANGLE_360 >> 4)
#define TWIN_ANGLE_11_25    (TWIN_ANGLE_360 >> 5)

#define TWIN_ANGLE_270	    (TWIN_ANGLE_180 + TWIN_ANGLE_90)
#define TWIN_ANGLE_0	    (0)

#define twin_degrees_to_angle(d)    ((twin_angle_t) ((((int32_t) (d)) * TWIN_ANGLE_360 / 360)))

/*
 * A rectangle
 */
typedef struct _twin_rect {
    twin_coord_t    left, right, top, bottom;
} twin_rect_t;

typedef union _twin_pointer {
    void	    *v;
    uint8_t	    *b;
    twin_a8_t	    *a8;
    twin_rgb16_t    *rgb16;
    twin_argb32_t   *argb32;
} twin_pointer_t;

typedef struct _twin_window twin_window_t;

/*
 * A rectangular array of pixels
 */
typedef struct _twin_pixmap {
    /*
     * Screen showing these pixels
     */
    struct _twin_screen		*screen;
    twin_count_t		disable;
    /*
     * List of displayed pixmaps
     */
    struct _twin_pixmap		*down, *up;
    /*
     * Screen position
     */
    twin_coord_t		x, y;
    /*
     * Pixmap layout
     */
    twin_format_t		format;
    twin_coord_t		width;	    /* pixels */
    twin_coord_t		height;	    /* pixels */
    twin_coord_t		stride;	    /* bytes */
    /*
     * Clipping - a single rectangle in pixmap coordinates.
     * Drawing is done relative to this rectangle
     */
    twin_rect_t			clip;
    /*
     * Pixels
     */
    twin_pointer_t		p;
    /*
     * When representing a window, this point
     * refers to the window object
     */
    twin_window_t		*window;
} twin_pixmap_t;

/*
 * twin_put_begin_t: called before data are drawn to the screen
 * twin_put_span_t: called for each scanline drawn
 */
typedef void	(*twin_put_begin_t) (twin_coord_t left,
				     twin_coord_t top,
				     twin_coord_t right,
				     twin_coord_t bottom,
				     void *closure);
typedef void	(*twin_put_span_t) (twin_coord_t left,
				    twin_coord_t top,
				    twin_coord_t right,
				    twin_argb32_t *pixels,
				    void *closure);

/*
 * A screen
 */
typedef struct _twin_screen {
    /*
     * List of displayed pixmaps
     */
    twin_pixmap_t	*top, *bottom;
    /*
     * One of them receives all key events
     */
    twin_pixmap_t	*active;
    /*
     * pointer down for this window
     */
    twin_pixmap_t	*pointer;
    /*
     * Output size
     */
    twin_coord_t	width, height;
    /*
     * Background pattern
     */
    twin_pixmap_t	*background;
    /*
     * Damage
     */
    twin_rect_t		damage;
    void		(*damaged) (void *);
    void		*damaged_closure;
    twin_count_t	disable;
    /*
     * Repaint function
     */
    twin_put_begin_t	put_begin;
    twin_put_span_t	put_span;
    void		*closure;
    /*
     * Window manager stuff
     */
    twin_coord_t	button_x, button_y;
} twin_screen_t;

/*
 * A source operand
 */

typedef enum { TWIN_SOLID, TWIN_PIXMAP } twin_source_t;

typedef struct _twin_operand {
    twin_source_t	source_kind;
    union {
	twin_pixmap_t	*pixmap;
	twin_argb32_t	argb;
    }			u;
} twin_operand_t;

typedef enum { TWIN_OVER, TWIN_SOURCE } twin_operator_t;

typedef int32_t	    twin_fixed_t;   /* 16.16 format */

#define TWIN_FIXED_ONE	(0x10000)
#define TWIN_FIXED_HALF	(0x08000)
#define TWIN_FIXED_MAX	(0x7fffffff)
#define TWIN_FIXED_MIN	(-0x7fffffff)

/* 
 * 'double' is a no-no in any shipping code, but useful during
 * development
 */
#define twin_double_to_fixed(d)    ((twin_fixed_t) ((d) * 65536))
#define twin_fixed_to_double(f)    ((double) (f) / 65536.0)

#define twin_int_to_fixed(i)	   ((twin_fixed_t) (i) << 16)
#define twin_fixed_ceil(f)	   (((f) + 0xffff) & ~0xffff)
#define twin_fixed_floor(f)	   ((f) & ~0xffff)
#define twin_fixed_to_int(f)	   ((int) ((f) >> 16))

typedef struct _twin_point {
    twin_fixed_t    x, y;
} twin_point_t;

/*
 * Place matrices in structures so they can be easily copied
 */
typedef struct _twin_matrix {
    twin_fixed_t	m[3][2];
} twin_matrix_t;

typedef struct _twin_path twin_path_t;

typedef enum _twin_cap {
    TwinCapRound,
    TwinCapButt,
    TwinCapProjecting,
} twin_cap_t;

typedef struct _twin_state {
    twin_matrix_t   matrix;
    twin_fixed_t    font_size;
    twin_style_t    font_style;
    twin_cap_t	    cap_style;
} twin_state_t;

/*
 * Text metrics
 */

typedef struct _twin_text_metrics {
    twin_fixed_t    left_side_bearing;
    twin_fixed_t    right_side_bearing;
    twin_fixed_t    ascent;
    twin_fixed_t    descent;
    twin_fixed_t    width;
    twin_fixed_t    font_ascent;
    twin_fixed_t    font_descent;
} twin_text_metrics_t;

/*
 * Events
 */

typedef enum _twin_event_kind {
    TwinEventButtonDown, TwinEventButtonUp, TwinEventMotion,
    TwinEventKeyDown, TwinEventKeyUp, TwinEventUcs4,
    TwinEventActivate, TwinEventDeactivate,
    TwinEventPaint,
    TwinEventShow,
    TwinEventQueryGeometry,
    TwinEventConfigure,
    TwinEventDestroy,
} twin_event_kind_t;

typedef struct _twin_event {
    twin_event_kind_t	kind;
    union {
	struct {
	    twin_coord_t    x, y;
	    twin_coord_t    screen_x, screen_y;
	    twin_count_t    button;
	} pointer;
	struct {
	    twin_keysym_t   key;
	} key;
	struct {
	    twin_ucs4_t	    ucs4;
	} ucs4;
	struct {
	    twin_rect_t	    extents;
	} configure;
    } u;
} twin_event_t;

typedef struct _twin_event_queue {
    struct _twin_event_queue	*next;
    twin_event_t		event;
} twin_event_queue_t;

/*
 * Windows
 */

typedef enum _twin_window_style {
    TwinWindowPlain,
    TwinWindowApplication,
    TwinWindowFullScreen,
    TwinWindowDialog,
    TwinWindowAlert,
} twin_window_style_t;

typedef void	    (*twin_draw_func_t) (twin_window_t	    *window);

typedef twin_bool_t (*twin_event_func_t) (twin_window_t	    *window,
					  twin_event_t	    *event);

typedef void	    (*twin_destroy_func_t) (twin_window_t   *window);

struct _twin_window {
    twin_screen_t	*screen;
    twin_pixmap_t	*pixmap;
    twin_window_style_t	style;
    twin_rect_t		client;
    twin_rect_t		damage;
    twin_bool_t		client_grab;
    twin_bool_t		want_focus;
    void		*client_data;
    char		*name;
    
    twin_draw_func_t	draw;
    twin_event_func_t	event;
    twin_destroy_func_t	destroy;
};

/*
 * Icons
 */

typedef enum _twin_icon {
    TwinIconMenu,
    TwinIconMinimize,
    TwinIconMaximize,
    TwinIconClose,
    TwinIconResize,
} twin_icon_t;

/*
 * Timeout and work procs return TWIN_TRUE to remain in the queue,
 * timeout procs are called every 'delay' ms
 */

typedef twin_time_t (*twin_timeout_proc_t) (twin_time_t now,
					    void	*closure);

typedef twin_bool_t (*twin_work_proc_t) (void *closure);

typedef enum _twin_file_op {
    TWIN_READ = 1,
    TWIN_WRITE = 2
} twin_file_op_t;

typedef twin_bool_t (*twin_file_proc_t) (int		file,
					 twin_file_op_t	ops,
					 void		*closure);
					    
#define twin_time_compare(a,op,b)	(((a) - (b)) op 0)

typedef struct _twin_timeout	twin_timeout_t;
typedef struct _twin_work	twin_work_t;
typedef struct _twin_file	twin_file_t;

/*
 * Widgets
 */

typedef struct _twin_widget twin_widget_t;
typedef struct _twin_box    twin_box_t;

#define _twin_widget_width(w)	(((twin_widget_t *)(w))->extents.right - \
				 ((twin_widget_t *)(w))->extents.left)

#define _twin_widget_height(w)	(((twin_widget_t *)(w))->extents.bottom - \
				 ((twin_widget_t *)(w))->extents.top)

typedef enum _twin_box_dir {
    TwinBoxHorz, TwinBoxVert
} twin_box_dir_t;

typedef enum _twin_dispatch_result {
    TwinDispatchDone,
    TwinDispatchContinue
} twin_dispatch_result_t;

typedef twin_dispatch_result_t (*twin_dispatch_proc_t) (twin_widget_t *widget,
							twin_event_t *event);
		       
typedef struct _twin_widget_layout {
    twin_coord_t	    width;
    twin_coord_t	    height;
    twin_stretch_t	    stretch_width;
    twin_stretch_t	    stretch_height;
} twin_widget_layout_t;

typedef enum _twin_shape {
    TwinShapeRectangle,
    TwinShapeRoundedRectangle,
    TwinShapeLozenge,
    TwinShapeTab,
    TwinShapeEllipse,
} twin_shape_t;

struct _twin_widget {
    twin_window_t	    *window;
    twin_widget_t	    *next;
    twin_box_t		    *parent;
    twin_dispatch_proc_t    dispatch;
    twin_rect_t		    extents;	/* current geometry */
    twin_widget_t	    *copy_geom;
    twin_bool_t		    paint;
    twin_bool_t		    layout;
    twin_bool_t		    want_focus;
    twin_argb32_t	    background;
    twin_widget_layout_t    preferred;
    twin_shape_t	    shape;
    twin_fixed_t	    radius;
};

struct _twin_box {
    twin_widget_t	widget;
    twin_box_dir_t	dir;
    twin_widget_t	*children;
    twin_widget_t	*button_down;
    twin_widget_t	*focus;
};

typedef struct _twin_toplevel {
    twin_box_t		box;
} twin_toplevel_t;

typedef enum _twin_align {
    TwinAlignLeft, TwinAlignCenter, TwinAlignRight
} twin_align_t;

typedef struct _twin_label {
    twin_widget_t	widget;
    char		*label;
    twin_argb32_t	foreground;
    twin_fixed_t	font_size;
    twin_style_t	font_style;
    twin_point_t	offset;
    twin_align_t	align;
} twin_label_t;

typedef enum _twin_button_signal {
    TwinButtonSignalDown,   /* sent when button pressed */
    TwinButtonSignalUp,	    /* send when button released inside widget */
} twin_button_signal_t;

typedef struct _twin_button twin_button_t;

typedef void	(*twin_button_signal_proc_t) (twin_button_t	    *button,
					      twin_button_signal_t  signal,
					      void		    *closure);

struct _twin_button {
    twin_label_t		label;
    twin_bool_t			pressed;
    twin_bool_t			active;
    twin_button_signal_proc_t	signal;
    void			*closure;
};

typedef enum _twin_scroll_signal {
    TwinScrollSignalUpArrow,
    TwinScrollSignalDownArrow,
    TwinScrollSignalThumb,
    TwinScrollSignalAboveThumb,
    TwinScrollSignalBelowThumb,
} twin_scroll_signal_t;

typedef struct _twin_scroll twin_scroll_t;

typedef void	(*twin_scroll_signal_proc_t) (twin_scroll_t	    *scroll,
					      twin_scroll_signal_t  signal,
					      void		    *closure);

struct _twin_scroll {
    twin_widget_t		widget;
};

/*
 * twin_box.c
 */

twin_box_t *
twin_box_create (twin_box_t	*parent,
		 twin_box_dir_t	dir);

/*
 * twin_button.c
 */

twin_button_t *
twin_button_create (twin_box_t	    *parent,
		   const char	    *value,
		   twin_argb32_t    foreground,
		   twin_fixed_t	    font_size,
		   twin_style_t	    font_style);

/*
 * twin_convolve.c
 */
void
twin_path_convolve (twin_path_t	*dest,
		    twin_path_t	*stroke,
		    twin_path_t	*pen);

/*
 * twin_dispatch.c
 */
void
twin_dispatch (void);

/*
 * twin_draw.c
 */

void
twin_composite (twin_pixmap_t	*dst,
		twin_coord_t	dst_x,
		twin_coord_t	dst_y,
		twin_operand_t	*src,
		twin_coord_t	src_x,
		twin_coord_t	src_y,
		twin_operand_t	*msk,
		twin_coord_t	msk_x,
		twin_coord_t	msk_y,
		twin_operator_t	operator,
		twin_coord_t	width,
		twin_coord_t	height);

void
twin_fill (twin_pixmap_t    *dst,
	   twin_argb32_t    pixel,
	   twin_operator_t  operator,
	   twin_coord_t	    left,
	   twin_coord_t	    top,
	   twin_coord_t	    right,
	   twin_coord_t	    bottom);

/*
 * twin_event.c
 */

void
twin_event_enqueue (const twin_event_t *event);

/*
 * twin_file.c
 */
 
twin_file_t *
twin_set_file (twin_file_proc_t	    file_proc,
	       int		    file,
	       twin_file_op_t	    ops,
	       void		    *closure);

void
twin_clear_file (twin_file_t *file);

/*
 * twin_fixed.c
 */

#if 0
twin_fixed_t
twin_fixed_mul (twin_fixed_t af, twin_fixed_t bf);
#else
#define twin_fixed_mul(a,b)    ((twin_fixed_t) (((int64_t) (a) * (b)) >> 16))
#endif

twin_fixed_t
twin_fixed_sqrt (twin_fixed_t a);

#if 0
twin_fixed_t
twin_fixed_div (twin_fixed_t a, twin_fixed_t b);
#else
#define twin_fixed_div(a,b)	((twin_fixed_t) ((((int64_t) (a)) << 16) / b))
#endif

/*
 * twin_font.c
 */

twin_bool_t
twin_has_ucs4 (twin_ucs4_t ucs4);
    
#define TWIN_TEXT_ROMAN	    0
#define TWIN_TEXT_BOLD	    1
#define TWIN_TEXT_OBLIQUE   2
#define TWIN_TEXT_UNHINTED  4

void
twin_path_ucs4_stroke (twin_path_t *path, twin_ucs4_t ucs4);

void
twin_path_ucs4 (twin_path_t *path, twin_ucs4_t ucs4);
 
void
twin_path_utf8 (twin_path_t *path, const char *string);

twin_fixed_t
twin_width_ucs4 (twin_path_t *path, twin_ucs4_t ucs4);
 
twin_fixed_t
twin_width_utf8 (twin_path_t *path, const char *string);

void
twin_text_metrics_ucs4 (twin_path_t	    *path, 
			twin_ucs4_t	    ucs4, 
			twin_text_metrics_t *m);

void
twin_text_metrics_utf8 (twin_path_t	    *path,
			const char	    *string,
			twin_text_metrics_t *m);
/*
 * twin_hull.c
 */

twin_path_t *
twin_path_convex_hull (twin_path_t *path);

/*
 * twin_icon.c
 */

void
twin_icon_draw (twin_pixmap_t *pixmap, twin_icon_t icon, twin_matrix_t matrix);

/*
 * twin_label.c
 */

twin_label_t *
twin_label_create (twin_box_t	    *parent,
		   const char	    *value,
		   twin_argb32_t    foreground,
		   twin_fixed_t	    font_size,
		   twin_style_t	    font_style);

void
twin_label_set (twin_label_t	*label,
		const char	*value,
		twin_argb32_t	foreground,
		twin_fixed_t	font_size,
		twin_style_t	font_style);

/*
 * twin_matrix.c
 */

void
twin_matrix_identity (twin_matrix_t *m);

void
twin_matrix_translate (twin_matrix_t *m, twin_fixed_t tx, twin_fixed_t ty);

void
twin_matrix_scale (twin_matrix_t *m, twin_fixed_t sx, twin_fixed_t sy);

void
twin_matrix_rotate (twin_matrix_t *m, twin_angle_t a);

void
twin_matrix_multiply (twin_matrix_t	    *result,
		      const twin_matrix_t   *a,
		      const twin_matrix_t   *b);

/*
 * twin_path.c
 */

void 
twin_path_move (twin_path_t *path, twin_fixed_t x, twin_fixed_t y);

void 
twin_path_rmove (twin_path_t *path, twin_fixed_t x, twin_fixed_t y);

void
twin_path_draw (twin_path_t *path, twin_fixed_t x, twin_fixed_t y);

void
twin_path_rdraw (twin_path_t *path, twin_fixed_t x, twin_fixed_t y);

void
twin_path_circle(twin_path_t	*path, 
		 twin_fixed_t	x,
		 twin_fixed_t	y,
		 twin_fixed_t	radius);

void
twin_path_ellipse (twin_path_t	*path,
		   twin_fixed_t	x,
		   twin_fixed_t	y,
		   twin_fixed_t x_radius, 
		   twin_fixed_t	y_radius);
void
twin_path_arc (twin_path_t  *path,
	       twin_fixed_t x,
	       twin_fixed_t y,
	       twin_fixed_t x_radius,
	       twin_fixed_t y_radius,
	       twin_angle_t start,
	       twin_angle_t extent);

void
twin_path_rectangle (twin_path_t    *path,
		     twin_fixed_t   x,
		     twin_fixed_t   y,
		     twin_fixed_t   w,
		     twin_fixed_t   h);

void
twin_path_rounded_rectangle (twin_path_t	*path,
			     twin_fixed_t	x,
			     twin_fixed_t	y,
			     twin_fixed_t	w,
			     twin_fixed_t	h,
			     twin_fixed_t	x_radius,
			     twin_fixed_t	y_radius);

void
twin_path_lozenge (twin_path_t	*path,
		   twin_fixed_t	x,
		   twin_fixed_t	y,
		   twin_fixed_t	w,
		   twin_fixed_t	h);

void
twin_path_tab (twin_path_t	*path,
	       twin_fixed_t	x,
	       twin_fixed_t	y,
	       twin_fixed_t	w,
	       twin_fixed_t	h,
	       twin_fixed_t	x_radius,
	       twin_fixed_t	y_radius);


void
twin_path_close (twin_path_t *path);

void
twin_path_empty (twin_path_t *path);

void
twin_path_bounds (twin_path_t *path, twin_rect_t *rect);

void
twin_path_append (twin_path_t *dst, twin_path_t *src);

twin_path_t *
twin_path_create (void);

void
twin_path_destroy (twin_path_t *path);

void
twin_path_identity (twin_path_t *path);

void
twin_path_translate (twin_path_t *path, twin_fixed_t tx, twin_fixed_t ty);

void
twin_path_scale (twin_path_t *path, twin_fixed_t sx, twin_fixed_t sy);

void
twin_path_rotate (twin_path_t *path, twin_angle_t a);

twin_matrix_t
twin_path_current_matrix (twin_path_t *path);

void
twin_path_set_matrix (twin_path_t *path, twin_matrix_t matrix);

twin_fixed_t
twin_path_current_font_size (twin_path_t *path);

void
twin_path_set_font_size (twin_path_t *path, twin_fixed_t font_size);

twin_style_t
twin_path_current_font_style (twin_path_t *path);

void
twin_path_set_font_style (twin_path_t *path, twin_style_t font_style);

void
twin_path_set_cap_style (twin_path_t *path, twin_cap_t cap_style);

twin_cap_t
twin_path_current_cap_style (twin_path_t *path);

twin_state_t
twin_path_save (twin_path_t *path);

void
twin_path_restore (twin_path_t *path, twin_state_t *state);

void
twin_composite_path (twin_pixmap_t	*dst,
		     twin_operand_t	*src,
		     twin_coord_t	src_x,
		     twin_coord_t	src_y,
		     twin_path_t	*path,
		     twin_operator_t	operator);
void
twin_paint_path (twin_pixmap_t	*dst,
		 twin_argb32_t	argb,
		 twin_path_t	*path);

void
twin_composite_stroke (twin_pixmap_t	*dst,
		       twin_operand_t	*src,
		       twin_coord_t	src_x,
		       twin_coord_t	src_y,
		       twin_path_t	*stroke,
		       twin_fixed_t	pen_width,
		       twin_operator_t	operator);

void
twin_paint_stroke (twin_pixmap_t    *dst,
		   twin_argb32_t    argb,
		   twin_path_t	    *stroke,
		   twin_fixed_t	    pen_width);

/*
 * twin_pattern.c
 */
twin_pixmap_t *
twin_make_pattern (void);

/*
 * twin_pixmap.c
 */

twin_pixmap_t *
twin_pixmap_create (twin_format_t   format,
		    twin_coord_t    width,
		    twin_coord_t    height);

twin_pixmap_t *
twin_pixmap_create_const (twin_format_t	    format,
			  twin_coord_t	    width,
			  twin_coord_t	    height,
			  twin_coord_t	    stride,
			  twin_pointer_t    pixels);

void
twin_pixmap_destroy (twin_pixmap_t *pixmap);

void
twin_pixmap_show (twin_pixmap_t *pixmap, 
		  twin_screen_t	*screen,
		  twin_pixmap_t *higher);

void
twin_pixmap_hide (twin_pixmap_t *pixmap);

void
twin_pixmap_enable_update (twin_pixmap_t *pixmap);

void
twin_pixmap_disable_update (twin_pixmap_t *pixmap);

void
twin_pixmap_clip (twin_pixmap_t *pixmap,
		  twin_coord_t	left,	twin_coord_t top,
		  twin_coord_t	right,	twin_coord_t bottom);

void
twin_pixmap_set_clip (twin_pixmap_t *pixmap, twin_rect_t clip);

twin_rect_t
twin_pixmap_current_clip (twin_pixmap_t *pixmap);

void
twin_pixmap_restore_clip (twin_pixmap_t *pixmap, twin_rect_t rect);

void
twin_pixmap_reset_clip (twin_pixmap_t *pixmap);

void
twin_pixmap_damage (twin_pixmap_t   *pixmap,
		    twin_coord_t    left,	twin_coord_t top,
		    twin_coord_t    right,	twin_coord_t bottom);

void
twin_pixmap_lock (twin_pixmap_t *pixmap);

void
twin_pixmap_unlock (twin_pixmap_t *pixmap);

void
twin_pixmap_move (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y);

twin_pointer_t
twin_pixmap_pointer (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y);

twin_bool_t
twin_pixmap_transparent (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y);

twin_bool_t
twin_pixmap_dispatch (twin_pixmap_t *pixmap, twin_event_t *event);

/*
 * twin_poly.c
 */
void
twin_fill_path (twin_pixmap_t *pixmap, twin_path_t *path,
		twin_coord_t dx, twin_coord_t dy);

/*
 * twin_screen.c
 */

twin_screen_t *
twin_screen_create (twin_coord_t	width,
		    twin_coord_t	height, 
		    twin_put_begin_t	put_begin,
		    twin_put_span_t	put_span,
		    void		*closure);

void
twin_screen_destroy (twin_screen_t *screen);

void
twin_screen_enable_update (twin_screen_t *screen);

void
twin_screen_disable_update (twin_screen_t *screen);

void
twin_screen_damage (twin_screen_t *screen,
		    twin_coord_t left, twin_coord_t top,
		    twin_coord_t right, twin_coord_t bottom);
		    
void
twin_screen_register_damaged (twin_screen_t *screen, 
			      void (*damaged) (void *),
			      void *closure);

void
twin_screen_resize (twin_screen_t *screen, 
		    twin_coord_t width, twin_coord_t height);

twin_bool_t
twin_screen_damaged (twin_screen_t *screen);

void
twin_screen_update (twin_screen_t *screen);

void
twin_screen_set_active (twin_screen_t *screen, twin_pixmap_t *pixmap);

twin_pixmap_t *
twin_screen_get_active (twin_screen_t *screen);

void
twin_screen_set_background (twin_screen_t *screen, twin_pixmap_t *pixmap);

twin_pixmap_t *
twin_screen_get_background (twin_screen_t *screen);

twin_bool_t
twin_screen_dispatch (twin_screen_t *screen,
		      twin_event_t  *event);

void
twin_screen_lock (twin_screen_t *screen);

void
twin_screen_unlock (twin_screen_t *screen);


/*
 * twin_spline.c
 */

void
twin_path_curve (twin_path_t	*path,
		 twin_fixed_t	x1, twin_fixed_t y1,
		 twin_fixed_t	x2, twin_fixed_t y2,
		 twin_fixed_t	x3, twin_fixed_t y3);

/*
 * twin_timeout.c
 */

#define twin_time_compare(a,op,b)	(((a) - (b)) op 0)

twin_timeout_t *
twin_set_timeout (twin_timeout_proc_t	timeout_proc,
		  twin_time_t		delay,
		  void			*closure);

void
twin_clear_timeout (twin_timeout_t *timeout);

twin_time_t
twin_now (void);

/*
 * twin_toplevel.c
 */
twin_toplevel_t *
twin_toplevel_create (twin_screen_t	    *screen,
		      twin_format_t	    format,
		      twin_window_style_t   style,
		      twin_coord_t	    x,
		      twin_coord_t	    y,
		      twin_coord_t	    width,
		      twin_coord_t	    height,
		      const char	    *name);

void
twin_toplevel_show (twin_toplevel_t *toplevel);

/*
 * twin_trig.c
 */

twin_fixed_t
twin_sin (twin_angle_t a);

twin_fixed_t
twin_cos (twin_angle_t a);

twin_fixed_t
twin_tan (twin_angle_t a);

/*
 * twin_widget.c
 */

twin_widget_t *
twin_widget_create (twin_box_t	    *parent,
		    twin_argb32_t   background,
		    twin_coord_t    width,
		    twin_coord_t    height,
		    twin_stretch_t  hstretch,
		    twin_stretch_t  vstretch);

void
twin_widget_set (twin_widget_t *widget, twin_argb32_t background);

/*
 * twin_window.c
 */

twin_window_t *
twin_window_create (twin_screen_t	*screen,
		    twin_format_t	format,
		    twin_window_style_t style,
		    twin_coord_t	x,
		    twin_coord_t	y,
		    twin_coord_t	width,
		    twin_coord_t	height);

void
twin_window_destroy (twin_window_t *window);

void
twin_window_show (twin_window_t *window);

void
twin_window_hide (twin_window_t *window);

void
twin_window_configure (twin_window_t	    *window,
		       twin_window_style_t  style,
		       twin_coord_t	    x,
		       twin_coord_t	    y,
		       twin_coord_t	    width,
		       twin_coord_t	    height);

void
twin_window_set_name (twin_window_t	*window,
		      const char	*name);

void
twin_window_style_size (twin_window_style_t style,
			twin_rect_t	    *size);

void
twin_window_draw (twin_window_t *window);

twin_bool_t
twin_window_dispatch (twin_window_t *window, twin_event_t *event);

/*
 * twin_work.c
 */

#define TWIN_WORK_REDISPLAY	0
#define TWIN_WORK_PAINT		1
#define TWIN_WORK_LAYOUT	2

twin_work_t *
twin_set_work (twin_work_proc_t	work_proc,
	       int		priority,
	       void		*closure);

void
twin_clear_work (twin_work_t *work);

#endif /* _TWIN_H_ */