Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7089 leency 1
/*
2
 * BACKGEN - Background generator
3
 * Author: Leency
4
 * Licence: GPL v2
5
*/
6
 
7
#define MEMSIZE 4096*10
8
 
9
#include "../lib/gui.h"
10
#include "../lib/patterns/rgb.h"
11
 
12
//===================================================//
13
//                                                   //
14
//                       DATA                        //
15
//                                                   //
16
//===================================================//
17
 
18
#define MAX_COLORS 10
19
 
20
more_less_box x_count = { 10, 220, NULL, 1, MAX_COLORS, 22, 23, "X count" };
21
more_less_box y_count = { 10, 250, NULL, 1, MAX_COLORS, 24, 25, "Y count" };
22
 
23
rect preview = { 10, 10, 200, 200 };
24
rect right_bar = { 230, 10, 280, 400 };
25
 
26
dword active_color = 0xFFFfff;
27
char active_color_string[11]="0x00111222\0";
28
 
29
enum {
30
	APPLY_BACKGROUND_BTN = 10
31
};
32
 
33
proc_info Form;
34
 
35
dword default_colors[] = {
36
0x330000,0x331900,0x333300,0x193300,0x003300,0x003319,0x003333,0x001933,0x000033,0x190033,0x330033,0x330019,0x000000,
37
0x660000,0x663300,0x666600,0x336600,0x006600,0x006633,0x006666,0x003366,0x000066,0x330066,0x660066,0x660033,0x202020,
38
0x990000,0x994C00,0x999900,0x4C9900,0x009900,0x00994C,0x009999,0x004C99,0x000099,0x4C0099,0x990099,0x99004C,0x404040,
39
0xCC0000,0xCC6600,0xCCCC00,0x66CC00,0x00CC00,0x00CC66,0x00CCCC,0x0066CC,0x0000CC,0x6600CC,0xCC00CC,0xCC0066,0x606060,
40
0xFF0000,0xFF8000,0xFFFF00,0x80FF00,0x00FF00,0x00FF80,0x00FFFF,0x0080FF,0x0000FF,0x7F00FF,0xFF00FF,0xFF007F,0x808080,
41
0xFF3333,0xFF9933,0xFFFF33,0x99FF33,0x33FF33,0x33FF99,0x33FFFF,0x3399FF,0x3333FF,0x9933FF,0xFF33FF,0xFF3399,0xA0A0A0,
42
0xFF6666,0xFFB266,0xFFFF66,0xB2FF66,0x66FF66,0x66FFB2,0x66FFFF,0x66B2FF,0x6666FF,0xB266FF,0xFF66FF,0xFF66B2,0xC0C0C0,
43
0xFF9999,0xFFCC99,0xFFFF99,0xCCFF99,0x99FF99,0x99FFCC,0x99FFFF,0x99CCFF,0x9999FF,0xCC99FF,0xFF99FF,0xFF99CC,0xE0E0E0,
44
0xFFCCCC,0xFFE5CC,0xFFFFCC,0xE5FFCC,0xCCFFCC,0xCCFFE5,0xCCFFFF,0xCCE5FF,0xCCCCFF,0xE5CCFF,0xFFCCFF,0xFFCCE5,0xFFFFFF
45
};
46
 
47
//===================================================//
48
//                                                   //
49
//                       CODE                        //
50
//                                                   //
51
//===================================================//
52
 
53
#include "colors_mas.h"
54
 
55
void main()
56
{
57
	word btn;
58
 
59
	colors.set_default_values();
60
	x_count.value = colors.columns;
61
	y_count.value = colors.rows;
62
 
63
	loop() switch(WaitEvent())
64
	{
65
		case evButton:
66
			btn = GetButtonID();
67
			if (btn == CLOSE_BTN) ExitProcess();
68
			if (btn == APPLY_BACKGROUND_BTN) {
69
				SetBackgroundImage(colors.columns, colors.rows, colors.get_image(), DRAW_DESKTOP_BG_STRETCH);
70
			}
71
			if (x_count.click(btn)) EventChangeFieldSize();
72
			if (y_count.click(btn)) EventChangeFieldSize();
73
			if (btn >= 100) && (btn < 228)
74
			{
75
				active_color = default_colors[btn-100];
76
				DrawActiveColor(NULL);
77
			}
78
			if (btn >= 300) && (btn < 401)
79
			{
80
				btn-=300;
81
				debugval("\n\nid",btn);
82
				colors.set_color(btn/colors.columns, btn%colors.columns, active_color);
83
				DrawColorsField();
84
			}
85
			break;
86
 
87
		case evKey:
88
			GetKeys();
89
			if (key_scancode == SCAN_CODE_ESC) ExitProcess();
90
			break;
91
 
92
		case evReDraw:
93
			draw_window();
94
			break;
95
	}
96
}
97
 
98
void draw_window()
99
{
100
	system.color.get();
101
	DefineAndDrawWindow(215, 100, right_bar.x+right_bar.w+9,
102
		right_bar.y+right_bar.h+skin_height+5,
103
		0x34, system.color.work, "Background generator",0
104
		);
105
	GetProcessInfo(#Form, SelfInfo);
106
 
107
	x_count.draw();
108
	y_count.draw();
109
 
110
	DrawColorsField();
111
 
112
	DrawStandartCaptButton(10, 320, APPLY_BACKGROUND_BTN, "Fill background");
113
 
114
	DrawRightBar();
115
}
116
 
117
void DrawColorsField()
118
{
119
	DrawRectangle(preview.x, preview.y, preview.w, preview.h, 0x808080);
120
	DrawBar(preview.x+1, preview.y+1, preview.w-1, preview.h-1, 0xBFCAD2); //F3F3F3
121
 
122
	colors.x = -colors.cell_size*colors.columns+preview.w/2 + preview.x;
123
	colors.y = -colors.cell_size*colors.rows+preview.h/2 + preview.y;
124
	colors.draw_all_cells();
125
}
126
 
127
void DrawRightBar()
128
{
129
	int i;
130
	incn y;
131
	y.n = right_bar.y;
132
	EDI = system.color.work;
133
	WriteTextB(right_bar.x, y.inc(3), 0x90, system.color.work_text, "Active color");
134
	DrawActiveColor(y.inc(22));
135
	WriteTextB(right_bar.x, y.inc(34), 0x90, system.color.work_text, "Default colors");
136
	DrawDefaultColors(right_bar.x, y.inc(22));
137
}
138
 
139
void DrawActiveColor(dword iny)
140
{
141
	static dword outy;
142
	if (iny != NULL) outy = iny;
143
	colors.draw_cell(right_bar.x, outy, active_color);
144
	sprintf(#active_color_string, "%A", active_color);
145
	EDI = system.color.work;
146
	WriteText(right_bar.x + 30, outy + 3, 0xD0, system.color.work_text, #active_color_string+4);
147
}
148
 
149
void DrawDefaultColors(dword _x, _y)
150
{
151
	int r, c, i;
152
	i = 0;
153
	for (r = 0; r < 9; r++)
154
	{
155
		for (c = 0; c < 13; c++)
156
		{
157
			colors.draw_cell(c*colors.cell_size + _x, r*colors.cell_size + _y, default_colors[i]);
158
			DefineHiddenButton(c*colors.cell_size + _x, r*colors.cell_size + _y, colors.cell_size, colors.cell_size, 100+i);
159
			i++;
160
		}
161
	}
162
}
163
 
164
 
165
//===================================================//
166
//                                                   //
167
//                      EVENTS                       //
168
//                                                   //
169
//===================================================//
170
 
171
void EventChangeFieldSize()
172
{
173
	colors.columns = x_count.value;
174
	colors.rows = y_count.value;
175
	DrawColorsField();
176
}