File: x_gc.c

package info (click to toggle)
mlterm 3.1.2-1.3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 23,168 kB
  • sloc: ansic: 102,795; sh: 9,676; java: 2,018; perl: 1,601; makefile: 1,595; cpp: 771; sed: 16
file content (152 lines) | stat: -rw-r--r-- 1,859 bytes parent folder | download | duplicates (3)
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
/*
 *	$Id$
 */

#include  "../x_gc.h"

#include  <kiklib/kik_mem.h>	/* malloc */

#include  "../x_color.h"

#define  ARGB_TO_RGB(pixel)  ((pixel) & 0x00ffffff)


/* --- global functions --- */

x_gc_t *
x_gc_new(
	Display *  display ,
	Drawable  drawable
	)
{
	x_gc_t *  gc ;

	if( ( gc = calloc( 1 , sizeof( x_gc_t))) == NULL)
	{
		return  NULL ;
	}

	gc->display = display ;

	/* Default value of GC. */
	gc->fg_color = RGB(0,0,0) ;
	gc->bg_color = RGB(0xff,0xff,0xff) ;

	return  gc ;
}

int
x_gc_delete(
	x_gc_t *  gc
	)
{
	free( gc) ;

	return  1 ;
}

int
x_set_gc(
	x_gc_t *  gc,
	GC  _gc
	)
{
	gc->gc = _gc ;

	SetTextAlign( gc->gc, TA_LEFT|TA_BASELINE) ;

	gc->fg_color = RGB(0,0,0) ;	/* black */
#if  0
	/* black is default value */
	SetTextColor( gc->gc, gc->fg_color) ;
#endif

	gc->bg_color = RGB(0xff,0xff,0xff) ;	/* white */
#if  0
	/* white is default value */
	SetBkColor( gc->gc, gc->bg_color) ;
#endif

	gc->fid = None ;
	gc->pen = None ;
	gc->brush = None ;

	return  1 ;
}

int
x_gc_set_fg_color(
	x_gc_t *  gc ,
	u_long  fg_color
	)
{
	if( ARGB_TO_RGB(fg_color) != gc->fg_color)
	{
		SetTextColor( gc->gc,
			(gc->fg_color = ARGB_TO_RGB(fg_color))) ;
	}

	return  1 ;
}

int
x_gc_set_bg_color(
	x_gc_t *  gc ,
	u_long  bg_color
	)
{
	if( ARGB_TO_RGB(bg_color) != gc->bg_color)
	{
		SetBkColor( gc->gc,
			(gc->bg_color = ARGB_TO_RGB(bg_color))) ;
	}

	return  1 ;
}

int
x_gc_set_fid(
	x_gc_t *  gc,
	Font  fid
	)
{
	if( gc->fid != fid)
	{
		SelectObject( gc->gc, fid) ;
		gc->fid = fid ;
	}

	return  1 ;
}

HPEN
x_gc_set_pen(
	x_gc_t *  gc,
	HPEN  pen
	)
{
	if( gc->pen != pen)
	{
		gc->pen = pen ;
		
		return  SelectObject( gc->gc, pen) ;
	}

	return  None ;
}

HBRUSH
x_gc_set_brush(
	x_gc_t *  gc,
	HBRUSH  brush
	)
{
	if( gc->brush != brush)
	{
		gc->brush = brush ;

		return  SelectObject( gc->gc, brush) ;
	}

	return  None ;
}