From: David Steele Date: Wed, 15 Feb 2017 13:18:46 +0000 (+0000) Subject: Added Control::SetSubState handling X-Git-Tag: dali_1.2.28~1^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=c67661e5069476a5ce720a31bb0b06e6c4be793e;ds=sidebyside Added Control::SetSubState handling Added a method to set the substate of a control (without transitions) Fixed a bug with entry/exit transitions ( needed to allow testing of this patch with new transitions-example in demo ) Change-Id: I31d4edc98be0b50d4ecad375cf64aff593a2d43d Signed-off-by: David Steele --- diff --git a/automated-tests/src/dali-toolkit-styling/default-theme.json b/automated-tests/src/dali-toolkit-styling/default-theme.json new file mode 100644 index 0000000..aea0422 --- /dev/null +++ b/automated-tests/src/dali-toolkit-styling/default-theme.json @@ -0,0 +1,338 @@ +{ + "constants": + { + "CONFIG_SCRIPT_LOG_LEVEL":"NoLogging" + }, + "styles": + { + "textlabel": + { + "pointSize":18 + }, + + "textlabelFontSize0": + { + "pointSize":8 + }, + "textlabelFontSize1": + { + "pointSize":10 + }, + "textlabelFontSize2": + { + "pointSize":15 + }, + "textlabelFontSize3": + { + "pointSize":19 + }, + "textlabelFontSize4": + { + "pointSize":25 + }, + + "textfield": + { + "pointSize":18, + "primaryCursorColor":[0.0,0.72,0.9,1.0], + "secondaryCursorColor":[0.0,0.72,0.9,1.0], + "cursorWidth":3, + "selectionHighlightColor":[0.75,0.96,1.0,1.0], + "grabHandleImage" : "{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png", + "selectionHandleImageLeft" : {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png" }, + "selectionHandleImageRight": {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png" } + }, + + "textfieldFontSize0": + { + "pointSize":10 + }, + "textfieldFontSize1": + { + "pointSize":10 + }, + "textfieldFontSize2": + { + "pointSize":10 + }, + "textfieldFontSize3": + { + "pointSize":10 + }, + "textfieldFontSize4": + { + "pointSize":10 + }, + "textselectionpopup": + { + "popupMaxSize":[656,72], + "optionDividerSize":[2,0], + "popupDividerColor":[0.23,0.72,0.8,0.11], + "popupIconColor":[1.0,1.0,1.0,1.0], + "popupPressedColor":[0.24,0.72,0.8,0.11], + "background": { + "rendererType": "nPatch", + "imageUrl": "{DALI_IMAGE_DIR}selection-popup-bg.9.png" + }, + "popupFadeInDuration":0.25, + "popupFadeOutDuration":0.25 + }, + "textselectionpopupbutton": + { + "label": + { + "pointSize":8, + "fontStyle": { "weight":"light" } + } + }, + "textselectiontoolbar": + { + "enableOvershoot":true, + "scrollView": + { + "overshootAnimationSpeed":360.0, + "overshootSize":[720.0,130.0] + } + }, + "scrollview": + { + "overshootEffectColor":"B018", + "overshootAnimationSpeed":360.0, + "overshootSize":[720.0,130.0] + }, + "itemview": + { + "overshootEffectColor":"B018", + "overshootAnimationSpeed":360.0, + "overshootSize":[720.0,130.0] + }, + "texteditor": + { + "pointSize":18, + "primaryCursorColor":[0.0,0.72,0.9,1.0], + "secondaryCursorColor":[0.0,0.72,0.9,1.0], + "cursorWidth":3, + "selectionHighlightColor":[0.75,0.96,1.0,1.0], + "grabHandleImage" : "{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png", + "selectionHandleImageLeft" : {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png" }, + "selectionHandleImageRight": {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png" } + }, + "ComplexControl": + { + "states": + { + "NORMAL": + { + "states": + { + "SELECTED": + { + "visuals": + { + "foregroundVisual": + { + "visualType":"GRADIENT", + "startPosition": [-1, -1], + "endPosition": [1, 1], + "spreadMethod": "REPEAT", + "stopOffset": [0.2, 0.8], + "stopColor": [ [ 1,0,0,1], [0,1,0,1] ] + } + } + }, + "UNSELECTED": + { + "visuals": + { + "foregroundVisual": + { + "visualType":"COLOR", + "mixColor": [ 1,0,0,1] + } + } + } + }, + "transitions": + { + "visualName":"*", + "effect":"CROSSFADE", + "animator": + { + "alphaFunction":"EASE_IN_OUT", + "duration":0.3 + } + } + }, + "FOCUSED": + { + "visuals": + { + "foregroundVisual": + { + "visualType":"GRADIENT", + "startPosition": [-1, -1], + "endPosition": [1, 1], + "spreadMethod": "REPEAT", + "stopOffset": [0.3, 0.9], + "stopColor": [ [ 0,0,1,1], [0,1,1,1] ] + }, + "focusVisual": + { + "visualType":"IMAGE", + "url": "focus.png" + } + }, + "entryTransition": + { + "target":"focusVisual", + "property":"mixColor", + "initialValue":[0,0,0,0], + "targetValue":[1,1,1,1], + "animator": + { + "alphaFunction":"EASE_IN_OUT_SINE", + "timePeriod": + { + "duration":0.5, + "delay":0 + } + } + }, + "exitTransition": + { + "target":"focusVisual", + "property":"mixColor", + "initialValue":[1,1,1,1], + "targetValue":[0,0,0,0], + "animator": + { + "alphaFunction":"EASE_IN_OUT_SINE", + "timePeriod": + { + "duration":0.5, + "delay":0 + } + } + } + }, + "DISABLED": + { + "visuals": + { + "foregroundVisual": + { + "visualType":"COLOR", + "mixColor": [1,0,0,1] + } + } + } + }, + "transitions": + [ + { + "effect":"CROSSFADE", + "animator": + { + "alphaFunction":"EASE_IN_OUT", + "duration":0.3 + } + } + ] + }, + "BasicControl": + { + "states": + { + "NORMAL": + { + "visuals": + { + "foregroundVisual": + { + "visualType":"GRADIENT", + "startPosition": [-1, -1], + "endPosition": [1, 1], + "spreadMethod": "REPEAT", + "stopOffset": [0.2, 0.8], + "stopColor": [ [ 1,0,0,1], [0,1,0,1] ] + } + } + }, + "FOCUSED": + { + "visuals": + { + "foregroundVisual": + { + "visualType":"GRADIENT", + "startPosition": [-1, -1], + "endPosition": [1, 1], + "spreadMethod": "REPEAT", + "stopOffset": [0.3, 0.9], + "stopColor": [ [ 0,0,1,1], [0,1,1,1] ] + }, + "focusVisual": + { + "visualType":"IMAGE", + "url": "focus.png" + } + }, + "entryTransition": + { + "target":"focusVisual", + "property":"mixColor", + "initialValue":[0,0,0,0], + "targetValue":[1,1,1,1], + "animator": + { + "alphaFunction":"EASE_IN_OUT_SINE", + "timePeriod": + { + "duration":0.5, + "delay":0 + } + } + }, + "exitTransition": + { + "target":"focusVisual", + "property":"mixColor", + "initialValue":[1,1,1,1], + "targetValue":[0,0,0,0], + "animator": + { + "alphaFunction":"EASE_IN_OUT_SINE", + "timePeriod": + { + "duration":0.5, + "delay":0 + } + } + } + }, + "DISABLED": + { + "visuals": + { + "foregroundVisual": + { + "visualType":"COLOR", + "mixColor": [1,0,0,1] + } + } + } + }, + "transitions": + [ + { + "effect":"CROSSFADE", + "animator": + { + "alphaFunction":"EASE_IN_OUT", + "duration":0.3 + } + } + ] + } + } +} diff --git a/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp b/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp index 6fe0fde..34f604a 100644 --- a/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp +++ b/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp @@ -17,6 +17,8 @@ #include #include +#include +#include #include #include #include @@ -34,345 +36,7 @@ using namespace Dali::Toolkit; namespace { -const char* defaultTheme = -"{\n" -" \"constants\":\n" -" {\n" -" \"CONFIG_SCRIPT_LOG_LEVEL\":\"NoLogging\"\n" -" },\n" -" \"styles\":\n" -" {\n" -" \"textlabel\":\n" -" {\n" -" \"pointSize\":18\n" -" },\n" -"\n" -" \"textlabelFontSize0\":\n" -" {\n" -" \"pointSize\":8\n" -" },\n" -" \"textlabelFontSize1\":\n" -" {\n" -" \"pointSize\":10\n" -" },\n" -" \"textlabelFontSize2\":\n" -" {\n" -" \"pointSize\":15\n" -" },\n" -" \"textlabelFontSize3\":\n" -" {\n" -" \"pointSize\":19\n" -" },\n" -" \"textlabelFontSize4\":\n" -" {\n" -" \"pointSize\":25\n" -" },\n" -"\n" -" \"textfield\":\n" -" {\n" -" \"pointSize\":18,\n" -" \"primaryCursorColor\":[0.0,0.72,0.9,1.0],\n" -" \"secondaryCursorColor\":[0.0,0.72,0.9,1.0],\n" -" \"cursorWidth\":3,\n" -" \"selectionHighlightColor\":[0.75,0.96,1.0,1.0],\n" -" \"grabHandleImage\" : \"{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png\",\n" -" \"selectionHandleImageLeft\" : {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png\" },\n" -" \"selectionHandleImageRight\": {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png\" }\n" -" },\n" -"\n" -" \"textfieldFontSize0\":\n" -" {\n" -" \"pointSize\":10\n" -" },\n" -" \"textfieldFontSize1\":\n" -" {\n" -" \"pointSize\":10\n" -" },\n" -" \"textfieldFontSize2\":\n" -" {\n" -" \"pointSize\":10\n" -" },\n" -" \"textfieldFontSize3\":\n" -" {\n" -" \"pointSize\":10\n" -" },\n" -" \"textfieldFontSize4\":\n" -" {\n" -" \"pointSize\":10\n" -" },\n" -" \"textselectionpopup\":\n" -" {\n" -" \"popupMaxSize\":[656,72],\n" -" \"optionDividerSize\":[2,0],\n" -" \"popupDividerColor\":[0.23,0.72,0.8,0.11],\n" -" \"popupIconColor\":[1.0,1.0,1.0,1.0],\n" -" \"popupPressedColor\":[0.24,0.72,0.8,0.11],\n" -" \"background\": {\n" -" \"rendererType\": \"nPatch\",\n" -" \"imageUrl\": \"{DALI_IMAGE_DIR}selection-popup-bg.9.png\"\n" -" },\n" -" \"popupFadeInDuration\":0.25,\n" -" \"popupFadeOutDuration\":0.25\n" -" },\n" -" \"textselectionpopupbutton\":\n" -" {\n" -" \"label\":\n" -" {\n" -" \"pointSize\":8,\n" -" \"fontStyle\":\"{\\\\""weight\\\\"":\\\\""light\\\\""}\"\n" -" }\n" -" },\n" -" \"textselectiontoolbar\":\n" -" {\n" -" \"enableOvershoot\":true,\n" -" \"scrollView\":\n" -" {\n" -" \"overshootAnimationSpeed\":360.0,\n" -" \"overshootSize\":[720.0,130.0]\n" -" }\n" -" },\n" -" \"scrollview\":\n" -" {\n" -" \"overshootEffectColor\":\"B018\",\n" -" \"overshootAnimationSpeed\":360.0,\n" -" \"overshootSize\":[720.0,130.0]\n" -" },\n" -" \"itemview\":\n" -" {\n" -" \"overshootEffectColor\":\"B018\",\n" -" \"overshootAnimationSpeed\":360.0,\n" -" \"overshootSize\":[720.0,130.0]\n" -" },\n" -" \"texteditor\":\n" -" {\n" -" \"pointSize\":18,\n" -" \"primaryCursorColor\":[0.0,0.72,0.9,1.0],\n" -" \"secondaryCursorColor\":[0.0,0.72,0.9,1.0],\n" -" \"cursorWidth\":3,\n" -" \"selectionHighlightColor\":[0.75,0.96,1.0,1.0],\n" -" \"grabHandleImage\" : \"{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png\",\n" -" \"selectionHandleImageLeft\" : {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png\" },\n" -" \"selectionHandleImageRight\": {\"filename\":\"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png\" }\n" -" },\n" -" \"ComplexControl\":\n" -" {\n" -" \"states\":\n" -" {\n" -" \"NORMAL\":\n" -" {\n" -" \"states\":\n" -" {\n" -" \"SELECTED\":\n" -" {\n" -" \"visuals\":\n" -" {\n" -" \"foregroundVisual\":\n" -" {\n" -" \"visualType\":\"GRADIENT\",\n" -" \"startPosition\": [-1, -1],\n" -" \"endPosition\": [1, 1],\n" -" \"spreadMethod\": \"REPEAT\",\n" -" \"stopOffset\": [0.2, 0.8],\n" -" \"stopColor\": [ [ 1,0,0,1], [0,1,0,1] ]\n" -" }\n" -" }\n" -" },\n" -" \"UNSELECTED\":\n" -" {\n" -" \"visuals\":\n" -" {\n" -" \"foregroundVisual\":\n" -" {\n" -" \"visualType\":\"COLOR\",\n" -" \"mixColor\": [ 1,0,0,1]\n" -" }\n" -" }\n" -" }\n" -" },\n" -" \"transitions\":\n" -" {\n" -" \"visualName\":\"*\",\n" -" \"effect\":\"CROSSFADE\",\n" -" \"animator\":\n" -" {\n" -" \"alphaFunction\":\"EASE_IN_OUT\",\n" -" \"duration\":0.3\n" -" }\n" -" }\n" -" },\n" -" \"FOCUSED\":\n" -" {\n" -" \"visuals\":\n" -" {\n" -" \"foregroundVisual\":\n" -" {\n" -" \"visualType\":\"GRADIENT\",\n" -" \"startPosition\": [-1, -1],\n" -" \"endPosition\": [1, 1],\n" -" \"spreadMethod\": \"REPEAT\",\n" -" \"stopOffset\": [0.3, 0.9],\n" -" \"stopColor\": [ [ 0,0,1,1], [0,1,1,1] ]\n" -" },\n" -" \"focusVisual\":\n" -" {\n" -" \"visualType\":\"IMAGE\",\n" -" \"url\": \"focus.png\"\n" -" }\n" -" },\n" -" \"entryTransition\":\n" -" {\n" -" \"target\":\"focusVisual\",\n" -" \"property\":\"mixColor\",\n" -" \"initialValue\":[0,0,0,0],\n" -" \"targetValue\":[1,1,1,1],\n" -" \"animator\":\n" -" {\n" -" \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n" -" \"timePeriod\": \n" -" {\n" -" \"duration\":0.5,\n" -" \"delay\":0\n" -" }\n" -" }\n" -" },\n" -" \"exitTransition\":\n" -" {\n" -" \"target\":\"focusVisual\",\n" -" \"property\":\"mixColor\",\n" -" \"initialValue\":[1,1,1,1],\n" -" \"targetValue\":[0,0,0,0],\n" -" \"animator\":\n" -" {\n" -" \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n" -" \"timePeriod\": \n" -" {\n" -" \"duration\":0.5,\n" -" \"delay\":0\n" -" }\n" -" }\n" -" }\n" -" },\n" -" \"DISABLED\":\n" -" {\n" -" \"visuals\":\n" -" {\n" -" \"foregroundVisual\":\n" -" {\n" -" \"visualType\":\"COLOR\",\n" -" \"mixColor\": [1,0,0,1]\n" -" }\n" -" }\n" -" }\n" -" },\n" -" \"transitions\":\n" -" [\n" -" {\n" -" \"effect\":\"CROSSFADE\",\n" -" \"animator\":\n" -" {\n" -" \"alphaFunction\":\"EASE_IN_OUT\",\n" -" \"duration\":0.3\n" -" }\n" -" }\n" -" ]\n" -" },\n" -" \"BasicControl\":\n" -" {\n" -" \"states\":\n" -" {\n" -" \"NORMAL\":\n" -" {\n" -" \"visuals\":\n" -" {\n" -" \"foregroundVisual\":\n" -" {\n" -" \"visualType\":\"GRADIENT\",\n" -" \"startPosition\": [-1, -1],\n" -" \"endPosition\": [1, 1],\n" -" \"spreadMethod\": \"REPEAT\",\n" -" \"stopOffset\": [0.2, 0.8],\n" -" \"stopColor\": [ [ 1,0,0,1], [0,1,0,1] ]\n" -" }\n" -" }\n" -" },\n" -" \"FOCUSED\":\n" -" {\n" -" \"visuals\":\n" -" {\n" -" \"foregroundVisual\":\n" -" {\n" -" \"visualType\":\"GRADIENT\",\n" -" \"startPosition\": [-1, -1],\n" -" \"endPosition\": [1, 1],\n" -" \"spreadMethod\": \"REPEAT\",\n" -" \"stopOffset\": [0.3, 0.9],\n" -" \"stopColor\": [ [ 0,0,1,1], [0,1,1,1] ]\n" -" },\n" -" \"focusVisual\":\n" -" {\n" -" \"visualType\":\"IMAGE\",\n" -" \"url\": \"focus.png\"\n" -" }\n" -" },\n" -" \"entryTransition\":\n" -" {\n" -" \"target\":\"focusVisual\",\n" -" \"property\":\"mixColor\",\n" -" \"initialValue\":[0,0,0,0],\n" -" \"targetValue\":[1,1,1,1],\n" -" \"animator\":\n" -" {\n" -" \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n" -" \"timePeriod\": \n" -" {\n" -" \"duration\":0.5,\n" -" \"delay\":0\n" -" }\n" -" }\n" -" },\n" -" \"exitTransition\":\n" -" {\n" -" \"target\":\"focusVisual\",\n" -" \"property\":\"mixColor\",\n" -" \"initialValue\":[1,1,1,1],\n" -" \"targetValue\":[0,0,0,0],\n" -" \"animator\":\n" -" {\n" -" \"alphaFunction\":\"EASE_IN_OUT_SINE\",\n" -" \"timePeriod\": \n" -" {\n" -" \"duration\":0.5,\n" -" \"delay\":0\n" -" }\n" -" }\n" -" }\n" -" },\n" -" \"DISABLED\":\n" -" {\n" -" \"visuals\":\n" -" {\n" -" \"foregroundVisual\":\n" -" {\n" -" \"visualType\":\"COLOR\",\n" -" \"mixColor\": [1,0,0,1]\n" -" }\n" -" }\n" -" }\n" -" },\n" -" \"transitions\":\n" -" [\n" -" {\n" -" \"effect\":\"CROSSFADE\",\n" -" \"animator\":\n" -" {\n" -" \"alphaFunction\":\"EASE_IN_OUT\",\n" -" \"duration\":0.3\n" -" }\n" -" }\n" -" ]\n" -" }\n" -" }\n" -"}\n"; +std::string defaultTheme; } // anonymous namespace @@ -382,6 +46,9 @@ const char* defaultTheme = void dali_style_manager_startup(void) { test_return_value = TET_UNDEF; + + std::ifstream t("src/dali-toolkit-styling/default-theme.json"); + defaultTheme = std::string((std::istreambuf_iterator(t)), std::istreambuf_iterator()); } void dali_style_manager_cleanup(void) @@ -1200,7 +867,7 @@ int UtcDaliStyleManagerStyleChangedSignalFontSizeTextEditor(void) } -int UtcDaliStyleManagerVisualTransitionParsing(void) +int UtcDaliStyleManagerSetState01(void) { tet_infoline("Instantiate dummy control and test state/visual/transition capture" ); Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", @@ -1244,8 +911,7 @@ int UtcDaliStyleManagerVisualTransitionParsing(void) END_TEST; } - -int UtcDaliStyleManagerVisualTransitionParsing02(void) +int UtcDaliStyleManagerSetState02(void) { tet_infoline("Instantiate dummy control and test state/visual/transition capture" ); Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", @@ -1258,25 +924,130 @@ int UtcDaliStyleManagerVisualTransitionParsing02(void) StyleManager styleManager = StyleManager::Get(); DummyControl actor = DummyControl::New(true); - actor.SetProperty(DevelControl::Property::STATE, "FOCUSED"); - - actor.SetStyleName("ComplexControl"); + actor.SetStyleName("BasicControl"); Stage::GetCurrent().Add(actor); Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); + int state = actor.GetProperty( DevelControl::Property::STATE ); + DALI_TEST_EQUALS( state, (int) DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION); Visual::Base visual1 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL); + + actor.SetProperty( DevelControl::Property::STATE, + Property::Map().Add( "state", "FOCUSED" ).Add("withTransitions", false)); + + state = actor.GetProperty( DevelControl::Property::STATE ); + DALI_TEST_EQUALS( state, (int) DevelControl::FOCUSED, TEST_LOCATION ); + + DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION); + DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOCUS_VISUAL), true, TEST_LOCATION); + + Visual::Base visual2 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL); + DALI_TEST_CHECK( visual1 != visual2 ); + + actor.SetProperty( DevelControl::Property::STATE, + Property::Map().Add( "state", "DISABLED" ).Add("withTransitions", false)); + + state = actor.GetProperty( DevelControl::Property::STATE ); + DALI_TEST_EQUALS( state, (int) DevelControl::DISABLED, TEST_LOCATION ); + + DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION); + + Visual::Base visual3 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL); + Visual::Base focusVisual = dummyImpl.GetVisual(DummyControl::Property::FOCUS_VISUAL); + DALI_TEST_CHECK( !focusVisual ); + DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOCUS_VISUAL), false, TEST_LOCATION); + + DALI_TEST_CHECK( visual1 != visual3 ); + DALI_TEST_CHECK( visual2 != visual3 ); + + actor.SetProperty( DevelControl::Property::STATE, + Property::Map().Add( "state", "NORMAL" ).Add("withTransitions", false)); + + state = actor.GetProperty( DevelControl::Property::STATE ); + DALI_TEST_EQUALS( state, (int) DevelControl::NORMAL, TEST_LOCATION ); + + DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION); + + visual1 = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL); DALI_TEST_CHECK( visual1 ); - Property::Map map; - visual1.CreatePropertyMap( map ); - Property::Value* value = map.Find( Visual::Property::TYPE ); - DALI_TEST_CHECK( value ); - int visualType; - value->Get( visualType ); + focusVisual = dummyImpl.GetVisual(DummyControl::Property::FOCUS_VISUAL); + DALI_TEST_CHECK( !focusVisual ); + DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOCUS_VISUAL), false, TEST_LOCATION); + + + END_TEST; +} + + +int UtcDaliStyleManagerSetSubState(void) +{ + tet_infoline("Instantiate dummy control and test state/visual/transition capture" ); + Test::StyleMonitor::SetThemeFileOutput( DALI_STYLE_DIR "dali-toolkit-default-theme.json", + defaultTheme ); + + ToolkitTestApplication application; + + StyleChangedSignalChecker styleChangedSignalHandler; + Dali::StyleMonitor styleMonitor = Dali::StyleMonitor::Get(); + StyleManager styleManager = StyleManager::Get(); + + DummyControl actor = DummyControl::New(true); + actor.SetProperty(DevelControl::Property::STATE, "NORMAL"); + actor.SetProperty(DevelControl::Property::SUB_STATE, "SELECTED"); + actor.SetStyleName("ComplexControl"); + Stage::GetCurrent().Add(actor); + + Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); + + { + DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION); + Visual::Base visual = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL); + DALI_TEST_CHECK( visual ); + Property::Map map; + visual.CreatePropertyMap( map ); + Property::Value* value = map.Find( Visual::Property::TYPE ); + DALI_TEST_CHECK( value ); + + int visualType; + value->Get( visualType ); + DALI_TEST_EQUALS( visualType, (int)Toolkit::Visual::GRADIENT, TEST_LOCATION ); + } + + actor.SetProperty(DevelControl::Property::SUB_STATE, "UNSELECTED"); + + { + DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION); + Visual::Base visual = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL); + DALI_TEST_CHECK( visual ); + Property::Map map; + visual.CreatePropertyMap( map ); + Property::Value* value = map.Find( Visual::Property::TYPE ); + DALI_TEST_CHECK( value ); + + int visualType; + value->Get( visualType ); + DALI_TEST_EQUALS( visualType, (int)Toolkit::Visual::COLOR, TEST_LOCATION ); + } - DALI_TEST_EQUALS( visualType, (int)Toolkit::Visual::GRADIENT, TEST_LOCATION ); + actor.SetProperty(DevelControl::Property::SUB_STATE, "SELECTED"); + { + Impl::DummyControl& dummyImpl = static_cast(actor.GetImplementation()); + DALI_TEST_EQUALS(dummyImpl.IsVisualEnabled(DummyControl::Property::FOREGROUND_VISUAL), true, TEST_LOCATION); + Visual::Base visual = dummyImpl.GetVisual(DummyControl::Property::FOREGROUND_VISUAL); + DALI_TEST_CHECK( visual ); + Property::Map map; + visual.CreatePropertyMap( map ); + Property::Value* value = map.Find( Visual::Property::TYPE ); + DALI_TEST_CHECK( value ); + + int visualType; + value->Get( visualType ); + DALI_TEST_EQUALS( visualType, (int)Toolkit::Visual::GRADIENT, TEST_LOCATION ); + } END_TEST; } diff --git a/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp b/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp index a480204..054aaad 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp @@ -952,7 +952,7 @@ int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void) DALI_TEST_CHECK(focusChangedCallback.mSignalVerified); DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == Actor()); DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first); - DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), "FOCUSED", TEST_LOCATION ); + DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION ); focusChangedCallback.Reset(); // Move the focus towards right @@ -971,8 +971,8 @@ int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void) DALI_TEST_CHECK(focusChangedCallback.mSignalVerified); DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first); DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second); - DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), "FOCUSED", TEST_LOCATION ); + DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION ); focusChangedCallback.Reset(); // Move the focus towards up @@ -1011,8 +1011,8 @@ int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void) DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second); DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first); - DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), "FOCUSED", TEST_LOCATION ); - DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); + DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION ); + DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); focusChangedCallback.Reset(); @@ -1022,8 +1022,8 @@ int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void) DALI_TEST_CHECK(focusChangedCallback.mSignalVerified); DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first); DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == second); - DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), "FOCUSED", TEST_LOCATION ); + DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION ); focusChangedCallback.Reset(); @@ -1034,10 +1034,10 @@ int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void) DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == second); DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth); - DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), "FOCUSED", TEST_LOCATION ); + DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION ); focusChangedCallback.Reset(); @@ -1048,10 +1048,10 @@ int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void) DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == fourth); DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == third); - DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), "FOCUSED", TEST_LOCATION ); - DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); + DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION ); + DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); focusChangedCallback.Reset(); @@ -1061,10 +1061,10 @@ int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void) DALI_TEST_CHECK(focusChangedCallback.mSignalVerified); DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == third); DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == first); - DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), "FOCUSED", TEST_LOCATION ); - DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); + DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION ); + DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); focusChangedCallback.Reset(); // Move the focus towards left. The focus move will fail as no way to move it upwards @@ -1074,10 +1074,10 @@ int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void) DALI_TEST_CHECK(preFocusChangeCallback.mCurrentFocusedActor == first); DALI_TEST_CHECK(preFocusChangeCallback.mProposedActorToFocus == Actor()); DALI_TEST_CHECK(preFocusChangeCallback.mDirection == Control::KeyboardFocus::LEFT); - DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), "FOCUSED", TEST_LOCATION ); - DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); + DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION ); + DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); preFocusChangeCallback.Reset(); DALI_TEST_CHECK(!focusChangedCallback.mSignalVerified); @@ -1093,19 +1093,19 @@ int UtcDaliKeyboardFocusManagerMoveFocusTestStateChange(void) DALI_TEST_CHECK(focusChangedCallback.mOriginalFocusedActor == first); DALI_TEST_CHECK(focusChangedCallback.mCurrentFocusedActor == fourth); - DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), "FOCUSED", TEST_LOCATION ); + DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), (int)DevelControl::FOCUSED, TEST_LOCATION ); focusChangedCallback.Reset(); // Clear the focus manager.ClearFocus(); - DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); - DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), "NORMAL", TEST_LOCATION ); + DALI_TEST_EQUALS(first.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(second.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(third.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); + DALI_TEST_EQUALS(fourth.GetProperty(DevelControl::Property::STATE), (int)DevelControl::NORMAL, TEST_LOCATION ); END_TEST; diff --git a/dali-toolkit/internal/builder/builder-impl.cpp b/dali-toolkit/internal/builder/builder-impl.cpp index ac5ea3e..48d2e2b 100644 --- a/dali-toolkit/internal/builder/builder-impl.cpp +++ b/dali-toolkit/internal/builder/builder-impl.cpp @@ -345,7 +345,7 @@ bool Builder::LookupStyleName( const std::string& styleName ) const StylePtr Builder::GetStyle( const std::string& styleName ) { - const StylePtr* style = mStyles.FindCaseInsensitiveC( styleName ); + const StylePtr* style = mStyles.FindConst( styleName ); if( style==NULL ) { @@ -1092,7 +1092,7 @@ void Builder::ApplyAllStyleProperties( const TreeNode& root, const TreeNode& nod StylePtr* matchedStyle = NULL; if( styleName ) { - matchedStyle = mStyles.FindCaseInsensitive( styleName ); + matchedStyle = mStyles.Find( styleName ); if( ! matchedStyle ) { OptionalChild styleNodes = IsChild(root, KEYNAME_STYLES); @@ -1180,7 +1180,7 @@ void Builder::RecordStyle( StylePtr style, continue; } - StylePtr* stylePtr = style->subStates.FindCaseInsensitive( stateName ); + StylePtr* stylePtr = style->subStates.Find( stateName ); if( stylePtr ) { StylePtr style(*stylePtr); @@ -1203,12 +1203,12 @@ void Builder::RecordStyle( StylePtr style, Dali::Property::Value property(Property::MAP); if( DeterminePropertyFromNode( visual.second, Property::MAP, property, replacements ) ) { - Property::Map* mapPtr = style->visuals.FindCaseInsensitive( visual.first ); + Property::Map* mapPtr = style->visuals.Find( visual.first ); if( mapPtr ) { // Override existing visuals mapPtr->Clear(); - mapPtr->Merge(*property.GetMap()); + mapPtr->Merge( *property.GetMap() ); } else { @@ -1219,47 +1219,15 @@ void Builder::RecordStyle( StylePtr style, } else if( key == KEYNAME_ENTRY_TRANSITION ) { - Dali::Property::Value property(Property::MAP); - if( DeterminePropertyFromNode( keyValue.second, Property::MAP, property, replacements ) ) - { - style->entryTransition = Toolkit::TransitionData::New( *property.GetMap() ); - } + RecordTransitionData( keyValue, style->entryTransition, replacements ); } else if( key == KEYNAME_EXIT_TRANSITION ) { - Dali::Property::Value property(Property::MAP); - if( DeterminePropertyFromNode( keyValue.second, Property::MAP, property, replacements ) ) - { - style->exitTransition = Toolkit::TransitionData::New( *property.GetMap() ); - } + RecordTransitionData( keyValue, style->exitTransition, replacements ); } else if( key == KEYNAME_TRANSITIONS ) { - //@todo add new transitions to style.transitions - // override existing transitions. A transition matches on target & property name - const TreeNode& node = keyValue.second; - if( node.GetType() == TreeNode::ARRAY ) - { - Dali::Property::Value property(Property::ARRAY); - if( DeterminePropertyFromNode( node, Property::ARRAY, property, replacements ) ) - { - style->transitions = *property.GetArray(); - } - } - else if( node.GetType() == TreeNode::OBJECT ) - { - Dali::Property::Value property(Property::MAP); - if( DeterminePropertyFromNode( node, Property::MAP, property, replacements ) ) - { - Property::Array propertyArray; - propertyArray.Add( property ); - style->transitions = propertyArray; - } - } - else - { - DALI_LOG_WARNING( "RecordStyle() Node \"%s\" is not a JSON array or object\n", key.c_str() ); - } + RecordTransitions( keyValue, style->transitions, replacements ); } else if( key == KEYNAME_TYPE || key == KEYNAME_ACTORS || @@ -1290,6 +1258,63 @@ void Builder::RecordStyle( StylePtr style, } } +void Builder::RecordTransitions( + const TreeNode::KeyNodePair& keyValue, + Property::Array& value, + const Replacement& replacements ) +{ + //@todo add new transitions to style.transitions + // override existing transitions. A transition matches on target & property name + const TreeNode& node = keyValue.second; + if( node.GetType() == TreeNode::ARRAY ) + { + Dali::Property::Value property(Property::ARRAY); + if( DeterminePropertyFromNode( node, Property::ARRAY, property, replacements ) ) + { + value = *property.GetArray(); + } + } + else if( node.GetType() == TreeNode::OBJECT ) + { + Dali::Property::Value property(Property::MAP); + if( DeterminePropertyFromNode( node, Property::MAP, property, replacements ) ) + { + Property::Array propertyArray; + propertyArray.Add( property ); + value = propertyArray; + } + } + else + { + DALI_LOG_WARNING( "RecordStyle() Node \"%s\" is not a JSON array or object\n", keyValue.first ); + } +} + +void Builder::RecordTransitionData( + const TreeNode::KeyNodePair& keyValue, + Toolkit::TransitionData& transitionData, + const Replacement& replacements ) +{ + const TreeNode& node = keyValue.second; + if( node.GetType() == TreeNode::ARRAY ) + { + Dali::Property::Value property(Property::ARRAY); + if( DeterminePropertyFromNode( keyValue.second, Property::ARRAY, property, replacements ) ) + { + transitionData = Toolkit::TransitionData::New( *property.GetArray() ); + } + } + else if( node.GetType() == TreeNode::OBJECT ) + { + Dali::Property::Value property(Property::MAP); + if( DeterminePropertyFromNode( keyValue.second, Property::MAP, property, replacements ) ) + { + transitionData = Toolkit::TransitionData::New( *property.GetMap() ); + } + } +} + + // Set properties from node on handle. void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node, Dali::Handle& handle, const Replacement& constant ) diff --git a/dali-toolkit/internal/builder/builder-impl.h b/dali-toolkit/internal/builder/builder-impl.h index b6db52d..ea0b635 100644 --- a/dali-toolkit/internal/builder/builder-impl.h +++ b/dali-toolkit/internal/builder/builder-impl.h @@ -292,6 +292,14 @@ private: Dali::Handle& handle, const Replacement& replacements ); + void RecordTransitions( const TreeNode::KeyNodePair& keyValue, + Property::Array& transitions, + const Replacement& replacements ); + + void RecordTransitionData( const TreeNode::KeyNodePair& keyNode, + Toolkit::TransitionData& transitionData, + const Replacement& replacements ); + void ApplyProperties( const TreeNode& root, const TreeNode& node, Dali::Handle& handle, diff --git a/dali-toolkit/internal/builder/dictionary.h b/dali-toolkit/internal/builder/dictionary.h index 22d2afe..ccccf2c 100644 --- a/dali-toolkit/internal/builder/dictionary.h +++ b/dali-toolkit/internal/builder/dictionary.h @@ -106,45 +106,9 @@ public: /** * Find the element in the dictionary pointed at by key, and - * return a pointer to it, or NULL. - */ - EntryType* Find( const std::string& key ) const - { - EntryType* result=NULL; - - if( ! key.empty() ) - { - for( typename Elements::iterator iter = container.begin(); iter != container.end(); ++iter ) - { - if( iter->key == key ) - { - result = &(iter->entry); - break; - } - } - } - return result; - } - - /** - * Find the element in the dictionary pointed at by key, and - * return a pointer to it, or NULL - */ - EntryType* Find( const char* key ) const - { - if( key != NULL ) - { - std::string theKey(key); - return Find(theKey); - } - return NULL; - } - - /** - * Find the element in the dictionary pointed at by key using a case * insensitive search, and return a const pointer to it, or NULL */ - const EntryType* FindCaseInsensitiveC( const std::string& key ) const + const EntryType* FindConst( const std::string& key ) const { if( ! key.empty() ) { @@ -164,7 +128,7 @@ public: * Find the element in the dictionary pointed at by key using a case * insensitive search, and return a non-const pointer to it, or NULL */ - EntryType* FindCaseInsensitive( const std::string& key ) const + EntryType* Find( const std::string& key ) const { EntryType* result = NULL; if( ! key.empty() ) @@ -185,12 +149,12 @@ public: * Find the element in the dictionary pointed at by key using a case * insensitive search, and return a const pointer to it, or NULL */ - const EntryType* FindCaseInsensitiveC( const char* key ) const + const EntryType* FindConst( const char* key ) const { if( key != NULL ) { std::string theKey(key); - return FindCaseInsensitiveC( theKey ); + return FindConst( theKey ); } return NULL; } @@ -199,16 +163,15 @@ public: * Find the element in the dictionary pointed at by key using a case * insensitive search, and return a non-const pointer to it, or NULL */ - EntryType* FindCaseInsensitive( const char* key ) const + EntryType* Find( const char* key ) const { if( key != NULL ) { std::string theKey(key); - return FindCaseInsensitive( theKey ); + return Find( theKey ); } return NULL; } - /** * Return an iterator pointing at the first entry in the dictionary */ diff --git a/dali-toolkit/internal/builder/style.cpp b/dali-toolkit/internal/builder/style.cpp index eaf59dc..515ddd9 100644 --- a/dali-toolkit/internal/builder/style.cpp +++ b/dali-toolkit/internal/builder/style.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -23,9 +24,13 @@ namespace Dali { namespace Toolkit { + namespace Internal { +extern const Dali::Scripting::StringEnum ControlStateTable[]; +extern const unsigned int ControlStateTableCount; + StylePtr Style::New() { StylePtr stylePtr( new Style() ); @@ -40,12 +45,15 @@ void Style::ApplyVisualsAndPropertiesRecursively( Handle handle ) const Toolkit::Control control = Toolkit::Control::DownCast(handle); if( control ) { - Property::Value value = control.GetProperty(DevelControl::Property::STATE); std::string stateName; - if( value.Get( stateName ) ) + Property::Value value = control.GetProperty(DevelControl::Property::STATE); + Dali::Toolkit::DevelControl::State state = static_cast(value.Get()); + stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( state, ControlStateTable, ControlStateTableCount ); + + if( ! stateName.empty() ) { // Look up state in states table: - const StylePtr* stylePtr = subStates.FindCaseInsensitiveC( stateName ); + const StylePtr* stylePtr = subStates.FindConst( stateName ); if( stylePtr ) { const StylePtr statePtr(*stylePtr); @@ -59,7 +67,7 @@ void Style::ApplyVisualsAndPropertiesRecursively( Handle handle ) const std::string subStateName; if( value.Get( subStateName ) && ! subStateName.empty() ) { - const StylePtr* stylePtr = statePtr->subStates.FindCaseInsensitiveC( subStateName ); + const StylePtr* stylePtr = statePtr->subStates.FindConst( subStateName ); if( stylePtr ) { const StylePtr subStatePtr(*stylePtr); @@ -103,7 +111,6 @@ void Style::ApplyProperties( Handle handle ) const Style::Style() { } - Style::~Style() { } diff --git a/dali-toolkit/internal/builder/style.h b/dali-toolkit/internal/builder/style.h index 2fb4e83..bd26a6d 100644 --- a/dali-toolkit/internal/builder/style.h +++ b/dali-toolkit/internal/builder/style.h @@ -58,8 +58,6 @@ public: */ void ApplyVisualsAndPropertiesRecursively( Handle handle ) const; - -private: /** * Apply the visuals of the style to the control pointed at by * handle. diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index 3f58064..e77c28b 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -59,6 +59,22 @@ extern bool CaseInsensitiveStringCompare( const std::string& a, const std::strin namespace Toolkit { +namespace Internal +{ + +extern const Dali::Scripting::StringEnum ControlStateTable[]; +extern const unsigned int ControlStateTableCount; + + +// Not static or anonymous - shared with other translation units +const Scripting::StringEnum ControlStateTable[] = { + { "NORMAL", Toolkit::DevelControl::NORMAL }, + { "FOCUSED", Toolkit::DevelControl::FOCUSED }, + { "DISABLED", Toolkit::DevelControl::DISABLED }, +}; const unsigned int ControlStateTableCount = sizeof( ControlStateTable ) / sizeof( ControlStateTable[0] ); + +} // Internal namespace + namespace { @@ -218,12 +234,6 @@ static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra return connected; } -const Scripting::StringEnum ControlStateTable[] = { - { "NORMAL", Toolkit::DevelControl::NORMAL }, - { "FOCUSED", Toolkit::DevelControl::FOCUSED }, - { "DISABLED", Toolkit::DevelControl::DISABLED }, -}; const unsigned int ControlStateTableCount = sizeof( ControlStateTable ) / sizeof( ControlStateTable[0] ); - // Setup signals and actions using the type-registry. DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create ); @@ -254,7 +264,7 @@ public: Impl(Control& controlImpl) : mControlImpl( controlImpl ), mState( Toolkit::DevelControl::NORMAL ), - mSubState(""), + mSubStateName(""), mStyleName(""), mBackgroundColor(Color::TRANSPARENT), mStartingPinchScale( NULL ), @@ -323,11 +333,27 @@ public: case Toolkit::DevelControl::Property::STATE: { - Toolkit::DevelControl::State state( controlImpl.mImpl->mState ); + bool withTransitions=true; + const Property::Value* valuePtr=&value; + Property::Map* map = value.GetMap(); + if(map) + { + Property::Value* value2 = map->Find("withTransitions"); + if( value2 ) + { + withTransitions = value2->Get(); + } + + valuePtr = map->Find("state"); + } - if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( value, ControlStateTable, ControlStateTableCount, state ) ) + if( valuePtr ) { - controlImpl.mImpl->SetState( state ); + Toolkit::DevelControl::State state( controlImpl.mImpl->mState ); + if( Scripting::GetEnumerationProperty< Toolkit::DevelControl::State >( *valuePtr, ControlStateTable, ControlStateTableCount, state ) ) + { + controlImpl.mImpl->SetState( state, withTransitions ); + } } } break; @@ -443,7 +469,13 @@ public: case Toolkit::DevelControl::Property::STATE: { - value = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( controlImpl.mImpl->mState, ControlStateTable, ControlStateTableCount ); + value = controlImpl.mImpl->mState; + break; + } + + case Toolkit::DevelControl::Property::SUB_STATE: + { + value = controlImpl.mImpl->mSubStateName; break; } @@ -503,7 +535,7 @@ public: return value; } - void SetState( DevelControl::State state ) + void SetState( DevelControl::State state, bool withTransitions=true ) { if( mState != state ) { @@ -531,13 +563,57 @@ public: } } - void SetSubState( const std::string& state ) + void SetSubState( const std::string& subStateName, bool withTransitions=true ) { - if( mSubState != state ) + if( mSubStateName != subStateName ) { - mSubState = state; - // Trigger transitions + // Get existing sub-state visuals, and unregister them + Dali::CustomActor handle( mControlImpl.GetOwner() ); + + Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get(); + if( styleManager ) + { + const StylePtr stylePtr = GetImpl( styleManager ).GetRecordedStyle( Toolkit::Control( mControlImpl.GetOwner() ) ); + if( stylePtr ) + { + // Stringify state + std::string stateName = Scripting::GetEnumerationName< Toolkit::DevelControl::State >( mState, ControlStateTable, ControlStateTableCount ); + + const StylePtr* state = stylePtr->subStates.Find( stateName ); + if( state ) + { + StylePtr stateStyle(*state); + + // Unregister existing visuals of this substate + const StylePtr* subState = stateStyle->subStates.Find( mSubStateName ); + if( subState ) + { + StylePtr subStateStyle(*subState); + + for( Dictionary::iterator iter = subStateStyle->visuals.Begin(); iter != subStateStyle->visuals.End(); ++iter ) + { + const std::string& visualName = (*iter).key; + Dali::Property::Index index = handle.GetPropertyIndex( visualName ); + if( index != Property::INVALID_INDEX ) + { + mControlImpl.UnregisterVisual( index ); + } + } + } + + // Register visuals of the new substate + const StylePtr* newSubState = stateStyle->subStates.Find( subStateName ); + if( newSubState ) + { + StylePtr newSubStateStyle(*newSubState); + newSubStateStyle->ApplyVisuals( handle ); + newSubStateStyle->ApplyProperties( handle ); + } + } + } + } + mSubStateName = subStateName; } } @@ -545,7 +621,7 @@ public: Control& mControlImpl; DevelControl::State mState; - std::string mSubState; + std::string mSubStateName; RegisteredVisualContainer mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used. std::string mStyleName;