summaryrefslogtreecommitdiffstats
path: root/kjsembed/docs/examples/buttonmaker/pillbox.js
blob: 21621c19fa673f315d37e4f97f236e24f8fe6df4 (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
#!/usr/bin/env kjscmd

function BaseImage()
{
	this.a = new Image(this);
	this.b = new Image(this);
	this.c = new Image(this);
	this.d = new Image(this);
	this.e = new Image(this);
	this.f = new Image(this);
	this.g = new Image(this);
	this.h = new Image(this);
	this.i = new Image(this);
	
	this.height = function() {
		return this.a.height() + this.d.height() + this.g.height(); 
	}
	
	this.width = function() {
		return this.a.width() + this.b.width() + this.c.width(); 
	}

	this.loadImages = function() {
		return (
		this.a.load("01.png") &&
		this.b.load("02.png") &&
		this.c.load("03.png") &&
		this.d.load("04.png") &&
		this.e.load("05.png") &&
		this.f.load("06.png") &&
		this.g.load("07.png") &&
		this.h.load("08.png") &&
		this.i.load("09.png") );
	}

	this.colorize = function( color ) {
		var percent = 0.55;
		var imgfx = new ImageFX();
		
		this.a = imgfx.blendColor( color, this.a, percent);
		this.b = imgfx.blendColor( color, this.b, percent);
		this.c = imgfx.blendColor( color, this.c, percent);
		this.d = imgfx.blendColor( color, this.d, percent);
		this.e = imgfx.blendColor( color, this.e, percent);
		this.f = imgfx.blendColor( color, this.f, percent);
		this.g = imgfx.blendColor( color, this.g, percent);
		this.h = imgfx.blendColor( color, this.h, percent);
		this.i = imgfx.blendColor( color, this.i, percent);
	}

	this.resize = function( newW, newH ) {

		this.b.smoothScale( newW - ( this.a.width() + this.c.width() ), this.b.height() );
		this.h.smoothScale( newW - ( this.g.width() + this.i.width() ), this.h.height() );

		this.d.smoothScale( this.d.width(), newH - ( this.a.height() + this.g.height() ) );
		this.f.smoothScale( this.f.width(), newH - ( this.c.height() + this.i.height() ) );

		this.e.smoothScale( newW - ( this.a.width() + this.c.width() ),
			 newH - ( this.c.height() + this.i.height() ) );
	}

	this.test = function( parent ) {
		var box = new TQHBox(parent);
		var vbox1 = new TQVBox(box);
		var vbox2 = new TQVBox(box);
		var vbox3 = new TQVBox(box);
		var l1 = new TQLabel(vbox1);
		l1.pixmap = this.a.pixmap();

		var l2 = new TQLabel(vbox1);
		l2.pixmap = this.d.pixmap();

		var l3 = new TQLabel(vbox1);
		l3.pixmap = this.g.pixmap();

		var l4 = new TQLabel(vbox2);
		l4.pixmap = this.b.pixmap();

		var l5 = new TQLabel(vbox2);
		l5.pixmap = this.e.pixmap();

		var l6 = new TQLabel(vbox2);
		l6.pixmap = this.h.pixmap();

		var l7 = new TQLabel(vbox3);
		l7.pixmap = this.c.pixmap();

		var l8 = new TQLabel(vbox3);
		l8.pixmap = this.f.pixmap();

		var l9 = new TQLabel(vbox3);
		l9.pixmap = this.i.pixmap();
	}

	this.pixmap = function(width, height){
		var pix = new Pixmap(this);
		pix.resize(width,height);
		pix.fill("white");
		var painter = new Painter(this);
		if( painter.begin(pix) )
		{
			this.paint(painter);
			if( painter.end() )
				return painter.pixmap();
		}
		return pix;
	}
	
	this.paint = function(painter){
		
		painter.drawRect(0,0,this.width(), this.height());
		
		painter.drawImage(0, 0, this.a, 0, 0, -1, -1, 0);
		painter.drawImage(0, this.a.height(), this.d, 0, 0, -1, -1, 0);
		painter.drawImage(0, ( this.height() - this.g.height() ) ,this.g, 0, 0, -1, -1, 0);
		
		painter.drawImage(this.a.width(), 0, this.b, 0, 0, -1, -1, 0);
		painter.drawImage(this.d.width(), this.b.height(), this.e, 0, 0, -1, -1, 0);
		painter.drawImage(this.g.width(), ( this.height() - this.h.height() ) ,this.h, 0, 0, -1, -1, 0);
		
		painter.drawImage(this.a.width() + this.b.width(), 0, this.c, 0, 0, -1, -1, 0);
		painter.drawImage(this.d.width() + this.e.width(), this.c.height(), this.f, 0, 0, -1, -1, 0);
		painter.drawImage(this.g.width() + this.h.width(), ( this.height() - this.i.height() ) ,this.i, 0, 0, -1, -1, 0);
	}
	
	this.widget = function(canvas) {
	        var painter = new Painter(this);
		if( painter.begin(canvas) )
		{
			this.paint(painter);
			if( painter.end() )
				return true;
		}
		return false;
	}
}


var base = new BaseImage();
var label = new TQLabel(this);


if ( !base.loadImages() )
	alert("Error Loading Resources!");

base.colorize("blue");
var H = 128;
var W = 128;

base.resize(W,H);

var box = new TQHBox(this);
var label = new TQLabel(box);
label.resize(W,H);
label.paintEvent = function(ev)
{
	println("paint...");
	base.widget(label);
}

var label2 = new TQLabel(box);
label2.pixmap = base.pixmap(W,H);

base.test(box);

box.show();
box.resize(W*3, H)

application.exec();

//img.load("cl.png"); img.blendColor( "blue", 0.20); img.smoothScale(16,128); lab.pixmap = img.pixmap