/* * efl-theme-tizen * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ group { name: "elm/toggle/base/style1"; images { image: "switch_btn.png" COMP; image: "switch_bg.png" COMP; image: "switch_left_padding.png" COMP; image: "switch_right_padding.png" COMP; } script { public timer_on(val) { new Float:x, Float:y; get_drag(PART:"button", x, y); if (x >= 1.0) { set_state(PART:"bg", "on", 0.0); x = 1.0; set_drag(PART:"button", x, y); emit("elm,action,toggle,on", ""); } else if (x <= 0.5) { x = x + 0.2; set_drag(PART:"button", x, y); timer(0.01, "timer_on", 0); } else { x = x + 0.1; set_drag(PART:"button", x, y); timer(0.01, "timer_on", 0); } return 0; } public timer_off(val) { new Float:x, Float:y; get_drag(PART:"button", x, y); if (x <= 0.0) { set_state(PART:"bg", "off", 0.0); x = 0.0; set_drag(PART:"button", x, y); emit("elm,action,toggle,off", ""); } else if (x >= 0.5) { x = x - 0.2; set_drag(PART:"button", x, y); timer(0.01, "timer_off", 0); } else { x = x - 0.1; set_drag(PART:"button", x, y); timer(0.01, "timer_off", 0); } return 0; } } parts { part { name: "bg"; type: RECT; mouse_events: 1; scale: 1; description { state: "default" 0.0; min: 142 41; max: 142 41; fixed: 1 1; align: 1.0 0.5; color: 255 255 255 255; } description { state: "on" 0.0; inherit: "default" 0.0; } } part { name: "left_padding"; mouse_events: 0; scale: 1; description { state: "default" 0.0; min: 5 0; fixed: 1 0; rel1.to: "bg"; rel2 { relative: 0 1; to: "bg"; } align: 0 0.5; image.normal: "switch_left_padding.png"; } } part { name: "right_padding"; mouse_events: 0; scale: 1; description { state: "default" 0.0; min: 5 0; fixed: 1 0; rel1 { relative: 1 0; to: "bg"; } rel2.to: "bg"; align: 1 0.5; image.normal: "switch_right_padding.png"; } } part { name: "button_clipper"; type: RECT; mouse_events: 0; description { state: "default" 0.0; rel1.to: "left_padding"; rel2.to: "right_padding"; } } part { name: "clipper"; type: RECT; mouse_events: 0; description { state: "default" 0.0; rel1 { relative: 1 0; to_x: "left_padding"; to_y: "bg"; } rel2 { relative: 0 1; to_x: "right_padding"; to_y: "bg"; } } } part { name: "button"; type: RECT; scale: 1; clip_to: "clipper"; dragable { x: 1 1 0; y: 0 0 0; confine: "bg"; } description { state: "default" 0.0; rel1.to: "bg"; rel2.to: "bg"; min: 58 41; max: 58 41; fixed: 1 1; color: 0 0 0 0; } } part { name: "button_events"; type: RECT; dragable { events: "button"; } description { state: "default" 0.0; rel1.to_x: "bg"; rel2.to_x: "bg"; color: 0 0 0 0; } } part { name: "onrect"; type: RECT; scale: 1; clip_to: "clipper"; mouse_events: 0; description { state: "default" 0.0; rel1.to: "button"; rel1.relative: -2.0 0.0; rel2.to: "button"; rel2.relative: 0.0 1.0; color: 0 0 0 0; } } part { name: "offrect"; type: RECT; scale: 1; clip_to: "clipper"; mouse_events: 0; description { state: "default" 0.0; rel1.to: "button"; rel1.relative: 1.0 0.0; rel2.to: "button"; rel2.relative: 3.0 1.0; color: 0 0 0 0; } } part { name: "togbase"; mouse_events: 0; clip_to: "clipper"; description { state: "default" 0.0; rel1.to: "onrect"; rel2.to: "offrect"; image.normal: "switch_bg.png"; } } part { name: "button2"; mouse_events: 0; clip_to: "button_clipper"; description { state: "default" 0.0; rel1.to: "button"; rel2.to: "button"; image { normal: "switch_btn.png"; border: 4 4 7 7; border_scale: 1; } image.middle: SOLID; } } part { name: "disabler"; type: RECT; description { state: "default" 0.0; color: 0 0 0 0; visible: 0; } description { state: "disabled" 0.0; inherit: "default" 0.0; visible: 1; } } } programs { program { name: "drag_end"; signal: "mouse,up,1"; source: "button"; script { new st[30]; new Float:vl; get_state(PART:"bg", st, 30, vl) if (!strncmp(st, "default", 7)) { set_state(PART:"bg", "on", 0.0); timer_on(0); } else { set_state(PART:"bg", "off", 0.0); timer_off(0); } } } program { name: "toggle_on"; signal: "elm,state,toggle,on"; source: "elm"; script { set_state(PART:"bg", "on", 0.0); timer_on(0); } } program { name: "toggle_off"; signal: "elm,state,toggle,off"; source: "elm"; script { set_state(PART:"bg", "off", 0.0); timer_off(0); } } program { name: "disable"; signal: "elm,state,disabled"; source: "elm"; action: STATE_SET "disabled" 0.0; target: "togbase"; target: "disabler"; } program { name: "enable"; signal: "elm,state,enabled"; source: "elm"; action: STATE_SET "default" 0.0; target: "disabler"; } } } /////////////////////////////////////////////////////////////////////////////////////// group { name: "elm/toggle/base/default"; images { image: "00_button_on.png" COMP; image: "00_button_on_press.png" COMP; image: "00_button_off.png" COMP; image: "00_button_off_press.png" COMP; image: "00_button_onoff_handle.png" COMP; image: "00_button_onoff_handle_press.png" COMP; } script { public toggle_move_state = 0; //0:no movement, 1: moved public toggle_is_down = 0; //0:not down, 1: down } parts { part { name: "bg"; type: RECT; mouse_events: 1; scale: 1; description { state: "default" 0.0; min: 122 40; max: 122 40; rel1.relative: 1.0 0.0; fixed: 1 0; color: 0 0 0 0; align: 1.0 0.5; } } part { name: "padding_left"; type: RECT; scale: 1; mouse_events: 0; description { state: "default" 0.0; align: 0.0 0.0; rel1{ relative: 0.0 0.0; to: "bg"; } rel2{ relative: 0.0 1.0; to: "bg"; } min: 4 4; fixed: 1 0; color: 0 0 0 0; } } part { name: "padding_right"; type: RECT; scale: 1; mouse_events: 0; description { state: "default" 0.0; align: 1.0 0.0; rel1{ relative: 1.0 0.0; to: "bg"; } rel2{ relative: 1.0 1.0; to: "bg"; } min: 4 4; fixed: 1 0; color: 0 0 0 0; } } part { name: "padding_top"; type: RECT; scale: 1; mouse_events: 0; description { state: "default" 0.0; align: 0.0 0.0; rel1{ relative: 0.0 0.0; to: "bg"; } rel2{ relative: 1.0 0.0; to: "bg"; } min: 4 4; fixed: 0 1; color: 0 0 0 0; } } part { name: "padding_bottom"; type: RECT; scale: 1; mouse_events: 0; description { state: "default" 0.0; align: 1.0 1.0; rel1{ relative: 0.0 1.0; to: "bg"; } rel2{ relative: 1.0 1.0; to: "bg"; } min: 4 4; fixed: 0 1; color: 0 0 0 0; } } part { name: "bg_image"; type: IMAGE; mouse_events: 0; scale: 1; description { state: "default" 0.0; align: 0.0 0.0; rel1{ relative: 0.0 1.0; to_x: "bg"; to_y: "padding_top"; } rel2{ relative: 1.0 0.0; to_x: "bg"; to_y: "padding_bottom"; } image.normal: "00_button_off.png"; } description { state: "off_pressed" 0.0; inherit: "default" 0.0; image.normal: "00_button_off_press.png"; } description { state: "on_pressed" 0.0; inherit: "default" 0.0; image.normal: "00_button_on_press.png"; } description { state: "on" 0.0; inherit: "default" 0.0; image.normal: "00_button_on.png"; } } part { name: "drag_container"; type: RECT; scale: 1; mouse_events: 0; description { state: "default" 0.0; rel1{ relative: 1.0 0.0; to_x: "padding_left"; to_y: "bg_image"; } rel2{ relative: 0.0 1.0; to_x: "padding_right"; to_y: "bg_image"; } color: 0 0 0 0; } } part { name: "clipper"; type: RECT; mouse_events: 0; description { state: "default" 0.0; rel1.to: "bg_image"; rel2.to: "bg_image"; color: 255 255 255 255; } } part { name: "clipper_inner"; type: RECT; mouse_events: 0; description { state: "default" 0.0; rel1.to: "bg_image"; rel2.to: "bg_image"; rel1.offset: 2 0; rel2.offset: -2 0; color: 255 255 255 255; } } part { name: "button"; type: IMAGE; scale: 1; clip_to: "clipper"; mouse_events: 1; dragable { x: 1 1 0; y: 0 0 0; confine: "drag_container"; } description { state: "default" 0.0; min: 56 32; max: 56 32; image.normal: "00_button_onoff_handle.png"; } description { state: "pressed" 0.0; inherit: "default" 0.0; image.normal: "00_button_onoff_handle_press.png"; } } part { name: "button_events"; type: RECT; dragable { events: "button"; } description { state: "default" 0.0; rel1.to_x: "bg"; rel2.to_x: "bg"; color: 0 0 0 0; } } part { name: "onrect"; type: RECT; scale: 1; clip_to: "clipper"; mouse_events: 0; description { state: "default" 0.0; rel1{ relative: -1.0 0.0; to: "button"; } rel2{ relative: 0.0 1.0; to: "button"; } align: 1.0 0.5; color: 0 0 0 0; } } part { name: "offrect"; type: RECT; scale: 1; clip_to: "clipper"; mouse_events: 0; description { state: "default" 0.0; rel1{ relative: 1.0 0.0; to: "button"; } rel2{ relative: 2.0 1.0; to: "button"; } color: 0 0 0 0; } } part { name: "elm.offtext"; type: TEXT; mouse_events: 0; scale: 1; clip_to: "clipper_inner"; description { state: "default" 0.0; rel1.to: "offrect"; rel2.to: "offrect"; color: 255 255 255 255; text { font: "Tizen:style=Medium"; size: 20; min: 0 1; align: 0.5 0.5; text: "OFF"; text_class: "tizen"; } } description { state: "disabled" 0.0; inherit: "default" 0.0; color: 128 128 128 128; } } part { name: "elm.ontext"; type: TEXT; mouse_events: 0; scale: 1; clip_to: "clipper_inner"; description { state: "default" 0.0; rel1.to: "onrect"; rel2.to: "onrect"; color: 255 255 255 255; text { font: "Tizen:style=Medium"; size: 20; min: 0 1; align: 0.5 0.5; text: "ON"; text_class: "tizen"; } } description { state: "disabled" 0.0; inherit: "default" 0.0; color: 128 128 128 128; color3: 0 0 0 24; } } part { name: "elm.swallow.content"; type: SWALLOW; description { state: "default" 0.0; fixed: 1 0; visible: 0; align: 0.0 0.5; rel1.offset: 4 4; rel2.relative: 0.0 1.0; rel2.offset: 3 -5; } description { state: "visible" 0.0; inherit: "default" 0.0; fixed: 1 1; visible: 1; aspect: 1.0 1.0; aspect_preference: VERTICAL; rel2.offset: 4 -5; } description { state: "disabled" 0.0; inherit: "default" 0.0; color: 128 128 128 128; } description { state: "disabled_visible" 0.0; inherit: "default" 0.0; color: 128 128 128 128; fixed: 1 1; visible: 1; aspect: 1.0 1.0; } } part { name: "elm.text"; type: TEXT; mouse_events: 0; scale: 1; description { state: "default" 0.0; visible: 0; rel1.to_x: "elm.swallow.content"; rel1.relative: 1.0 0.0; rel1.offset: 0 4; rel2.to_x: "bg"; rel2.relative: 0.0 1.0; rel2.offset: -5 -5; color: 0 0 0 255; text { font: "Tizen:style=Medium"; size: 10; min: 0 0; align: 0.0 0.5; text_class: "tizen"; } } description { state: "visible" 0.0; inherit: "default" 0.0; visible: 1; text.min: 1 1; } description { state: "disabled" 0.0; inherit: "default" 0.0; color: 128 128 128 128; } description { state: "disabled_visible" 0.0; inherit: "default" 0.0; color: 128 128 128 128; visible: 1; } } part { name: "disabler"; type: RECT; description { state: "default" 0.0; color: 0 0 0 0; visible: 0; } description { state: "disabled" 0.0; inherit: "default" 0.0; visible: 1; } } } programs { program { name: "drag_end"; signal: "mouse,up,1"; source: "button"; script { new Float:dx, Float:dy; new st[30]; new Float:vl; get_drag(PART:"button", dx, dy); set_int(toggle_is_down, 0); get_state(PART:"bg_image", st, 30, vl) if(get_int(toggle_move_state) == 0) //no movement { if(dx > 0.5) { set_drag(PART:"button", 0.0, 0.0); emit("elm,action,toggle,off", ""); set_state(PART:"bg_image", "default", 0.0); } else { set_drag(PART:"button", 1.0, 0.0); emit("elm,action,toggle,on", ""); set_state(PART:"bg_image", "on", 0.0); } } else { if (dx > 0.5) { set_drag(PART:"button", 1.0, 0.0); if (!strcmp(st, "off_pressed")) { emit("elm,action,toggle,on", ""); } set_state(PART:"bg_image", "on", 0.0); } else { set_drag(PART:"button", 0.0, 0.0); if (!strcmp(st, "on_pressed")) { emit("elm,action,toggle,off", ""); } set_state(PART:"bg_image", "default", 0.0); } } set_state(PART:"button", "default", 0.0); set_int(toggle_move_state,0); } } program { name: "toggle_on"; signal: "elm,state,toggle,on"; source: "elm"; script { set_drag(PART:"button", 100.0, 0.0); set_state(PART:"bg_image", "on", 0.0); } } program { name: "toggle_off"; signal: "elm,state,toggle,off"; source: "elm"; script { set_drag(PART:"button", 0.0, 0.0); set_state(PART:"bg_image", "default", 0.0); } } program { name: "mouse_press,"; signal: "mouse,down,1"; source: "button"; script { new st[30]; new Float:vl; set_int(toggle_is_down, 1); get_state(PART:"bg_image", st, 30, vl) if (!strcmp(st, "default")) { set_state(PART:"bg_image", "off_pressed", 0.0); } else { set_state(PART:"bg_image", "on_pressed", 0.0); } set_state(PART:"button", "pressed", 0.0); } } program { name: "mouse_move,"; signal: "mouse,move"; source: "button"; script { if(get_int(toggle_is_down) == 0) { set_int(toggle_move_state,0); } else { set_int(toggle_move_state,1); } } } program { name: "text_show"; signal: "elm,state,text,visible"; source: "elm"; action: STATE_SET "visible" 0.0; target: "elm.text"; } program { name: "text_hide"; signal: "elm,state,text,hidden"; source: "elm"; action: STATE_SET "default" 0.0; target: "elm.text"; } program { name: "icon_show"; signal: "elm,state,icon,visible"; source: "elm"; action: STATE_SET "visible" 0.0; target: "elm.swallow.content"; } program { name: "icon_hide"; signal: "elm,state,icon,hidden"; source: "elm"; action: STATE_SET "default" 0.0; target: "elm.swallow.content"; } program { name: "disable"; signal: "elm,state,disabled"; source: "elm"; action: STATE_SET "disabled" 0.0; target: "elm.ontext"; target: "elm.offtext"; target: "disabler"; after: "disable_text"; } program { name: "disable_text"; script { new st[31]; new Float:vl; get_state(PART:"elm.text", st, 30, vl); if (!strcmp(st, "visible")) set_state(PART:"elm.text", "disabled_visible", 0.0); else set_state(PART:"elm.text", "disabled", 0.0); get_state(PART:"elm.swallow.content", st, 30, vl); if (!strcmp(st, "visible")) set_state(PART:"elm.swallow.content", "disabled_visible", 0.0); else set_state(PART:"elm.swallow.content", "disabled", 0.0); } } program { name: "enable"; signal: "elm,state,enabled"; source: "elm"; action: STATE_SET "default" 0.0; target: "elm.ontext"; target: "elm.offtext"; target: "disabler"; after: "enable_text"; } program { name: "enable_text"; script { new st[31]; new Float:vl; get_state(PART:"elm.text", st, 30, vl); if (!strcmp(st, "disabled_visible")) set_state(PART:"elm.text", "visible", 0.0); else set_state(PART:"elm.text", "default", 0.0); get_state(PART:"elm.swallow.content", st, 30, vl); if (!strcmp(st, "visible")) set_state(PART:"elm.swallow.content", "visible", 0.0); else set_state(PART:"elm.swallow.content", "default", 0.0); } } } }