// dialer.edc
// this is a theme for epydial, a pyneo dialer
//
// TODO: make the font colors shinier :)
//
// Signal1: "dialer_send"
//  Parameter1.1: $"keynumber"
//  Parameter1.2: "backspace"
//  Parameter1.3: "clear"
//  Parameter1.4: "dial"
//  Parameter1.5: "#"
//  Parameter1.6: "screen_locked"

data {
	item: "author" "thomasg [thomas (a) gstaedtner (.) net]";
	item: "version" "prototype";
	item: "name" "epydial_default";
}

images {
	image: "bg.png" COMP;
}

color_classes {
	color_class {
		name: "button_inactive";
		color: 255 255 255 128;
		color2: 128 128 128 255;
		color3: 128 128 128 255;;
	}
	color_class {
		name: "battvolt_active";
		color: 255 255 255 128;
		color2: 128 128 128 255;
		color3: 128 128 128 255;;
	}
	color_class {
		name: "button_active";
		color: 0 0 0 255;
		color2: 0 0 0 255;
		color3: 0 0 0 255;
	}
	color_class {
		name: "unvisible";
		color: 0 0 0 0;
		color2: 128 128 128 255;
		color3: 128 128 128 255;
	}
}

spectra {
	spectrum {
		name: "background";
		color: 80 80 80 255 1;
		color: 210 210 210 255 1;
	}
	spectrum {
		name: "button";
		color: 5 5 5 255 1;
		color: 110 110 110 255 1;
		color: 10 10 10 255 1;
	}
	spectrum {
		name: "button_active";
		color: 15 170 0 255 1;
		color: 130 255 0 255 1;
		color: 20 200 0 255 1;
	}
}

#define BUTTON(button_number, rel1x, rel1y, rel2x, rel2y, button_caption) \
part { \
	name: "button_"button_number; \
	type: RECT; \
	description { \
		state: "default" 0; \
		color_class: "unvisible"; \
		rel1 { relative: rel1x rel1y; offset: 0 0; }; \
		rel2 { relative: rel2x rel2y; offset: 0 0; }; \
	} \
	description { \
		state: "default" 0.5; \
		inherit: "default" 0; \
		color_class: "unvisible"; \
		rel1.offset: 0 -5; \
		rel2.offset: 0 5; \
	} \
	description { \
		state: "default" 1; \
		inherit: "default" 0; \
	} \
} \
part { \
	name: "button_"button_number"_caption"; \
	type: TEXT; \
	mouse_events: 0; \
	description { \
		state: "default" 0; \
		color_class: "button_inactive"; \
		rel1 { \
			to: "button_"button_number; \
			relative: 0 0; \
		} \
		rel2 { \
			to: "button_"button_number; \
			relative: 1 1; \
		} \
		text { \
			text: button_caption; \
			size: 18; \
			font: "Sans:style=Bold,Edje-Vera"; \
			fit: 1 1; \
		} \
	} \
} \
program { \
	name: "button_"button_number"_signal_emit"; \
	signal: "mouse,down,*"; \
	source: "button_"button_number; \
	action: SIGNAL_EMIT "dialer_send" button_caption; \
} \
program { \
	name: "button_"button_number"_animation"; \
	signal: "mouse,down,*"; \
	source: "button_"button_number; \
	action: STATE_SET "default" 0.5; \
	target: "button_"button_number; \
} \
program { \
	name: "button_"button_number"_animation_end"; \
	signal: "mouse,up,*"; \
	source: "button_"button_number; \
	action: STATE_SET "default" 1; \
	target: "button_"button_number; \
	transition: DECELERATE 0.1; \
}

collections {
	group {
		name: "pyneo/dialer/main";
		min: 100 100;
		max: 1000 1000;
		script {
			public flag_timer_running;
			public flag_backspace_sent;
			public timer_id;

			public clear_timer() {
				set_int(flag_backspace_sent, 0);
				set_int(flag_timer_running, 1);
				timer_id = timer(2, "clear_send", 1);
			}

			public clear_send() {
				if (get_int(flag_backspace_sent) == 0) {
					set_int(flag_timer_running, 0);
					run_program(PROGRAM:"numberdisplay_backspace_emit_signal_clear");
				}
			}

			public backspace_send() {
				if (get_int(flag_timer_running) == 1) {
					cancel_timer(get_int(timer_id));
					set_int(flag_backspace_sent, 1);
					run_program(PROGRAM:"numberdisplay_backspace_emit_signal_backspace");
				}	
			}
			public flag_timer_running_hash_key;
			public flag_hash_key_sent;
			public timer_id_hash_key;

			public clear_timer_hash_key() {
				set_int(flag_hash_key_sent, 0);
				set_int(flag_timer_running_hash_key, 1);
				timer_id_hash_key = timer(2, "clear_send_hash_key", 1);
			}

			public clear_send_hash_key() {
				if (get_int(flag_hash_key_sent) == 0) {
					set_int(flag_timer_running_hash_key, 0);
					run_program(PROGRAM:"hash_key_emit_signal_screen_locked");
				}
			}

			public hash_key_send() {
				if (get_int(flag_timer_running_hash_key) == 1) {
					cancel_timer(get_int(timer_id_hash_key));
					set_int(flag_hash_key_sent, 1);
					run_program(PROGRAM:"hash_key_emit_signal_#");
				}	
			}
		}

		parts {
			part {
				name: "background";
				type: IMAGE;
				description {
					state: "default" 0;
					rel1 { relative: 0 0; offset: 0 0; };
					rel2 { relative: 1 1; offset: 0 0; };
					image { normal: "bg.png"; };
				}
			}
			part {
				name: "operater_text";
				type: TEXT;
				mouse_events: 0;
				description {
					color_class: "button_inactive";
					state: "default" 0.0;
					rel1 { relative: 0 0; }
					rel2 { relative: 1/3 1/20; }
					text { text, "operator"; font: "Sans"; size, 1; align, 0 0.5; fit, 0 1; }
				}
			} /* end operator_text */
			part {
				name: "time_text";
				type: TEXT;
				mouse_events: 0;
				description {
					color_class: "button_inactive";
					state: "default" 0.0;
					rel1 { relative: 1/3 0; }
					rel2 { relative: 2/3 1/20; }
					text { text, "time"; font: "sans.bold"; size, 1; align, 0.5 0.5; fit, 0 1; }
				}
			} /* end time_text */
			part {
				name: "signalq_text";
				type: TEXT;
				mouse_events: 0;
				description {
					color_class: "button_inactive";
					state: "default" 0.0;
					rel1 { relative: 1/2 0; }
					rel2 { relative: 5/6 1/20; }
					text { text, "signal"; font: "Sans"; size, 1; align, 1 0.5; fit, 0 1; }
				}
			} /* end signalq_battvolt_text */
			part {
				name: "battvolt_text";
				type: TEXT;
				mouse_events: 0;
				description {
					color_class: "battvolt_active";
					state: "default" 0.0;
					rel1 { relative: 5/6 0; }
					rel2 { relative: 1 1/20; }
					text { text, "batt"; font: "Sans"; size, 1; align, 1 0.5; fit, 0 1; }
				}
			} /* end battvolt_text */
			part {
				name: "numberdisplay_background";
				type: RECT;
				description {
					state: "default" 0;
					color_class: "unvisible";
					/*color: 0 0 0 255;*/
					rel1 { relative: 0.02 0.06; offset: 0 0; };
					rel2 { relative: 0.9 0.3; offset: 0 0; };
				}
			}
			part {
				name: "numberdisplay_foreground";
				type: RECT;
				description {
					state: "default" 0;
					color_class: "unvisible";
					rel1 {
						to: "numberdisplay_background";
						offset: 2 2;
					}
					rel2 {
						to: "numberdisplay_background";
						offset: -7 -7;
					}
				}
				description {
					state: "default" 0.5;
					inherit: "default" 0;
					color: 150 255 60 255;
					rel1.offset: -10 -10;
					rel2.offset: 10 10;
				}
				description {
					state: "default" 1;
					inherit: "default" 0;
				}

			}
			program {
				name: "numberdisplay_forground_signal_emit";
				signal: "mouse,down,*";
				source: "numberdisplay_foreground";
				action: SIGNAL_EMIT "dialer_send" "dial";
			}
			program {
				name: "numberdisplay_foreground_animation";
				signal: "mouse,down,*";
				source: "numberdisplay_foreground";
				action: STATE_SET "default" 0.5;
				target: "numberdisplay_foreground";
				transition: LINEAR 0.25;
			}
			program {
				name: "numberdisplay_foreground_animation_end";
				signal: "mouse,up,*";
				source: "numberdisplay_foreground";
				action: STATE_SET "default" 1;;
				target: "numberdisplay_foreground";
				transition: LINEAR 0.25;
			}
			part {
				name: "numberdisplay_text";
				type: TEXT;
				mouse_events: 0;
				description {
					state: "default" 0;
					color_class: "button_inactive";
					rel1 {
						to: "numberdisplay_foreground";
						relative: 0.02 0;
					}
					rel2 {
						to: "numberdisplay_foreground";
						relative: 0.75 1;
					}
					text {
						text: "testmode";
						size: 32;
						font: "Sans:style=Bold,Edje-Vera";
						fit: 0 0;
						align: 0 1/2;
					}
				}	
			}
			part {
				name: "numberdisplay_backspace";
				type: TEXT;
				mouse_events: 0;
				description {
					state: "default" 0;
					color_class: "button_inactive";
					rel1 {
						to: "numberdisplay_foreground";
						relative: 0.77 0;
					}
					rel2 {
						to: "numberdisplay_foreground";
						relative: 1 1;
					}
					text {
						text: "<";
						size: 18;
						font: "Sans:style=Bold,Edje-Vera";
						fit: 1 1;
					}
				}
			}
			part {
				name: "numberdisplay_backspace_area";
				type: RECT;
				description {
					state: "default" 0;
					color: 0 0 0 0;
					rel1 { relative: 2/3 0; offset: 0 0; };
					rel2 { relative: 3/3 22/70; offset: 0 0; };
				}
				description {
					state: "default" 0.3;
					rel1.to: "numberdisplay_foreground";
					rel2.to: "numberdisplay_foreground";
				}
				description {
					state: "default" 0.6;
					inherit: "default" 0.3;
					color: 255 0 0 100;
				}
				description {
					state: "default" 1;
					inherit: "default" 0;
				}
			}
			program {
				name: "numberdisplay_backspace_area_signal_emit";
				signal: "mouse,down,*";
				source: "numberdisplay_backspace_area";
				script {
					clear_timer();
				}
			}
			program {
				name: "numberdisplay_backspace_area_signal_stop";
				signal: "mouse,up,*";
				source: "numberdisplay_backspace_area";
				script {
					backspace_send();
				}
			}
			program {
				name: "numberdisplay_backspace_emit_signal_backspace";
				action: SIGNAL_EMIT "dialer_send" "backspace";
			}
			program {
				name: "numberdisplay_backspace_emit_signal_clear";
				action: SIGNAL_EMIT "dialer_send" "clear";
			}
			program {
				name: "numberdisplay_backspace_area_animation_start";
				signal: "mouse,down,*";
				source: "numberdisplay_backspace_area";
				action: STATE_SET "default" 0.3;
				target: "numberdisplay_backspace_area";
				transition: LINEAR 0;
				after: "numberdisplay_backspace_area_animation_continue";
			}
			program {
				name: "numberdisplay_backspace_area_animation_continue";
				action: STATE_SET "default" 0.6;
				target: "numberdisplay_backspace_area";
				transition: LINEAR 0.3;
				after: "numberdisplay_backspace_area_animation_stop";
			}
			program {
				name: "numberdisplay_backspace_area_animation_stop";
				action: STATE_SET "default" 1;
				target: "numberdisplay_backspace_area";
				transition: LINEAR 0;
			}

			/* row 1 */
			BUTTON(1, 0, 25/70, 1/3, 35/70, 1);
			BUTTON(2, 1/3, 25/70, 2/3, 35/70, 2);
			BUTTON(3, 2/3, 25/70, 3/3, 35/70, 3);
			/*DESIGN_SEPERATOR(1, 1/3, 25/70, 1/3, 35/70);
			DESIGN_SEPERATOR(2, 2/3, 25/70, 2/3, 35/70);*/

			/* row 2 */
			BUTTON(4, 0, 36/70, 1/3, 46/70, 4);
			BUTTON(5, 1/3, 36/70, 2/3, 46/70, 5);
			BUTTON(6, 2/3, 36/70, 3/3, 46/70, 6);
			/*DESIGN_SEPERATOR(4, 1/3, 36/70, 1/3, 46/70);
			DESIGN_SEPERATOR(5, 2/3, 36/70, 2/3, 46/70);*/

			/* row 3 */
			BUTTON(7, 0, 47/70, 1/3, 57/70, 7);
			BUTTON(8, 1/3, 47/70, 2/3, 57/70, 8);
			BUTTON(9, 2/3, 47/70, 3/3, 57/70, 9);
			/*DESIGN_SEPERATOR(7, 1/3, 47/70, 1/3, 57/70);
			DESIGN_SEPERATOR(8, 2/3, 47/70, 2/3, 57/70);*/

			/* row 4 */
			BUTTON(10, 0, 58/70 , 1/3, 68/70, "*");
			BUTTON(11, 1/3, 58/70, 2/3, 68/70, 0);
			/*#define BUTTON(button_number, rel1x, rel1y, rel2x, rel2y, button_caption)*/
			/*BUTTON(12, 2/3, 58/70, 3/3, 68/70, "#");*/
			part {
				name: "button_12";
				type: RECT;
				description {
					state: "default" 0;
					color_class: "unvisible";
					rel1 { relative: 2/3 58/70; offset: 0 0; };
					rel2 { relative: 3/3 68/70; offset: 0 0; };
				}
				description {
					state: "default" 0.5;
					inherit: "default" 0;
					color_class: "button_active";
					rel1.offset: 0 -5;
					rel2.offset: 0 5;
				}
				description {
					state: "default" 1;
					inherit: "default" 0;
				}
			}
			part {
				name: "button_12_caption";
				type: TEXT;
				mouse_events: 0;
				description { \
					state: "default" 0;
					color_class: "button_inactive";
					rel1 {
						to: "button_12";
						relative: 0 0;
					}
					rel2 {
						to: "button_12";
						relative: 1 1;
					}
					text {
						text: "#";
						size: 18;
						font: "Sans:style=Bold,Edje-Vera";
						fit: 1 1;
					}
				}
			}
			program {
				name: "button_12_animation";
				signal: "mouse,down,*";
				source: "button_12";
				action: STATE_SET "default" 0.5;
				target: "button_12";
			}
			program {
				name: "button_12_animation_end";
				signal: "mouse,up,*";
				source: "button_12";
				action: STATE_SET "default" 1;
				target: "button_12";
				transition: DECELERATE 0.1;
			}
			program {
				name: "hash_key_signal_emit";
				signal: "mouse,down,*";
				source: "button_12";
				script {
					clear_timer_hash_key();
				}
			}
			program {
				name: "hash_key_signal_stop";
				signal: "mouse,up,*";
				source: "button_12";
				script {
					hash_key_send();
				}
			}
			program {
				name: "hash_key_emit_signal_#";
				action: SIGNAL_EMIT "dialer_send" "#";
			}
			program {
				name: "hash_key_emit_signal_screen_locked";
				action: SIGNAL_EMIT "dialer_send" "screen_locked";
			}
		}
	}
}	
