From: dongsug.song Date: Thu, 23 Mar 2017 13:18:51 +0000 (+0900) Subject: move back VisualFactory to public X-Git-Tag: accepted/tizen/common/20170324.123341~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F56%2F120656%2F1;p=platform%2Fcore%2Fcsapi%2Fnui.git move back VisualFactory to public Change-Id: Iac982f92dbfdafb6bcc1a9014609998be215aa7c Signed-off-by: dongsug.song --- diff --git a/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj b/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj index 563a0a8..48dfb7a 100755 --- a/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj +++ b/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj @@ -70,6 +70,9 @@ + + + diff --git a/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/ContactData.cs b/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/ContactData.cs new file mode 100755 index 0000000..f5fc67c --- /dev/null +++ b/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/ContactData.cs @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2017 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. + * + */ + +using System; +using Tizen.NUI; +using Tizen.NUI.Constants; + +namespace VisualsUsingCustomView +{ + // The collection of contacts + static class ContactsList + { + private const string resources = "/home/owner/apps_rw/NUISamples.TizenTV/res"; + + public static readonly ContactItem[] s_contactData = new ContactItem[] + { + new ContactItem ("Emmett Yates", resources + "/images/gallery-small-43.jpg", + new Color((73.0f/255.0f),(182.0f/255.0f), (245.0f/255.0f), 1.0f), + (int)PrimitiveVisualShapeType.Cone), + new ContactItem ("Leslie Wong", resources+ "/images/gallery-2.jpg", + new Color((51.0f/255.0f), (51.0f/255.0f), (102.0f/255.0f), 1.0f), + (int)PrimitiveVisualShapeType.Sphere), + new ContactItem ("Walter Jensen", resources+ "/images/gallery-0.jpg", + new Color((151.0f/255.0f), (214.0f/255.0f), (240.0f/255.0f), 1.0f), + (int)PrimitiveVisualShapeType.Cylinder), + new ContactItem ("Dan Haynes", resources+"/images/gallery-1.jpg", + new Color((102.0f/255.0f), (251.0f/255.0f), (102.0f/255.0f), 1.0f), + (int)PrimitiveVisualShapeType.ConicalFrustrum), + new ContactItem ("Mable Hodges", resources+"/images/gallery-3.jpg", + new Color((255.0f/255.0f), (102.0f/255.0f), (102.0f/255.0f), 1.0f), + (int)PrimitiveVisualShapeType.Cube) + }; + } + + // The information for an individual contact + class ContactItem + { + private string _name; + private string _imageURL; + private Color _color; + private int _shape; + + public ContactItem(string name, string imageURL, Color color, int shape) + { + _name = name; + _imageURL = imageURL; + _color = color; + _shape = shape; + } + + public string ImageURL + { + get + { + return _imageURL; + } + set + { + _imageURL = value; + } + } + + public string Name + { + get + { + return _name; + } + set + { + _name = value; + } + } + + public Color Color + { + get + { + return _color; + } + set + { + _color = value; + } + } + + public int Shape + { + get + { + return _shape; + } + set + { + _shape = value; + } + } + } +} \ No newline at end of file diff --git a/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/ContactView.cs b/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/ContactView.cs new file mode 100755 index 0000000..96434fa --- /dev/null +++ b/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/ContactView.cs @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2017 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. + * + */ + +using System; +using Tizen.NUI; +using Tizen.NUI.Constants; + +// A ContactView is a Custom View which consists of four visuals (Image, Primitive, Text and Color). +// All of these visuals can be configured via properties - ImageURL (Image), Shape (Primitive), Name (Text) and Color. +// Tap gesture is also enabled on the ContactView which changes the color visual to some random color when ContactView is tapped. + +namespace VisualsUsingCustomView +{ + public class ContactView : CustomView + { + private const int ColorVisualPropertyIndex = 0; + private const int PrimitiveVisualPropertyIndex = 1; + private const int ImageVisualPropertyIndex = 2; + private const int TextVisualPropertyIndex = 3; + private VisualBase _imageVisual; + private VisualBase _colorVisual; + private VisualBase _primitiveVisual; + private VisualBase _textVisual; + private int _shape; + private string _imageURL; + private string _name; + private Color _color; + + public ContactView() : base(typeof(ContactView).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport) + { + } + + public string ImageURL + { + get + { + return _imageURL; + } + set + { + _imageURL = value; + + // Create and Register Image Visual + PropertyMap imageVisual = new PropertyMap(); + imageVisual.Add( Visual.Property.Type, new PropertyValue( (int)Visual.Type.Image )) + .Add( ImageVisualProperty.URL, new PropertyValue( _imageURL )); + _imageVisual = VisualFactory.Get().CreateVisual( imageVisual ); + RegisterVisual( ImageVisualPropertyIndex, _imageVisual ); + + // Set the depth index for Image visual + _imageVisual.DepthIndex = ImageVisualPropertyIndex; + } + } + + public string Name + { + get + { + return _name; + } + set + { + _name = value; + + // Create and Register Text Visual + PropertyMap textVisual = new PropertyMap(); + textVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Text)) + .Add(TextVisualProperty.Text, new PropertyValue(_name)) + .Add(TextVisualProperty.TextColor, new PropertyValue(Color.White)) + .Add(TextVisualProperty.PointSize, new PropertyValue(15)) + .Add( TextVisualProperty.HorizontalAlignment, new PropertyValue("CENTER")) + .Add( TextVisualProperty.VerticalAlignment, new PropertyValue("CENTER")); + _textVisual = VisualFactory.Get().CreateVisual( textVisual ); + RegisterVisual( TextVisualPropertyIndex, _textVisual ); + + // Set the depth index for Text visual + _textVisual.DepthIndex = TextVisualPropertyIndex; + } + } + + public Color Color + { + get + { + return _color; + } + set + { + _color = value; + + // Create and Register Color Visual + PropertyMap colorVisual = new PropertyMap(); + colorVisual.Add( Visual.Property.Type, new PropertyValue( (int)Visual.Type.Color )) + .Add( ColorVisualProperty.MixColor, new PropertyValue( _color )); + _colorVisual = VisualFactory.Get().CreateVisual( colorVisual ); + RegisterVisual( ColorVisualPropertyIndex, _colorVisual ); + + // Set the depth index for Color visual + _colorVisual.DepthIndex = ColorVisualPropertyIndex; + } + } + + public int Shape + { + get + { + return _shape; + } + set + { + _shape = value; + + // Create and Register Primitive Visual + PropertyMap primitiveVisual = new PropertyMap(); + primitiveVisual.Add( Visual.Property.Type, new PropertyValue( (int)Visual.Type.Primitive )) + .Add( PrimitiveVisualProperty.Shape, new PropertyValue(_shape)) + .Add( PrimitiveVisualProperty.BevelPercentage, new PropertyValue(0.3f)) + .Add( PrimitiveVisualProperty.BevelSmoothness, new PropertyValue(0.0f)) + .Add( PrimitiveVisualProperty.ScaleDimensions, new PropertyValue(new Vector3(1.0f,1.0f,0.3f))) + .Add( PrimitiveVisualProperty.MixColor, new PropertyValue(new Vector4((245.0f/255.0f), (188.0f/255.0f), (73.0f/255.0f), 1.0f))); + _primitiveVisual = VisualFactory.Get().CreateVisual( primitiveVisual ); + RegisterVisual( PrimitiveVisualPropertyIndex, _primitiveVisual ); + + // Set the depth index for Primitive visual + _primitiveVisual.DepthIndex = PrimitiveVisualPropertyIndex; + } + } + + public override void OnInitialize() + { + // Enable Tap gesture on ContactView + EnableGestureDetection(Gesture.GestureType.Tap); + } + + public override void OnTap(TapGesture tap) + { + // Change the Color visual of ContactView with some random color + Random random = new Random(); + Color = new Color((random.Next(0, 256) / 255.0f), (random.Next(0, 256) / 255.0f), (random.Next(0, 256) / 255.0f), 1.0f); + } + + public override void OnRelayout(Vector2 size, RelayoutContainer container) + { + // Configure the transform and size of Image visual. + PropertyMap imageVisualTransform = new PropertyMap(); + imageVisualTransform.Add((int)VisualTransformPropertyType.Offset, new PropertyValue(new Vector2(10.0f, 0.0f))) + .Add((int)VisualTransformPropertyType.OffsetPolicy, new PropertyValue(new Vector2((int)VisualTransformPolicyType.Absolute, (int)VisualTransformPolicyType.Absolute))) + .Add((int)VisualTransformPropertyType.SizePolicy, new PropertyValue(new Vector2((int)VisualTransformPolicyType.Absolute, (int)VisualTransformPolicyType.Absolute))) + .Add((int)VisualTransformPropertyType.Size, new PropertyValue(new Vector2(40.0f, 40.0f))) + .Add((int)VisualTransformPropertyType.Origin, new PropertyValue((int)AlignType.CenterBegin)) + .Add((int)VisualTransformPropertyType.AnchorPoint, new PropertyValue((int)AlignType.CenterBegin)); + _imageVisual.SetTransformAndSize(imageVisualTransform, size); + + // Configure the transform and size of Text visual. + PropertyMap textVisualTransform = new PropertyMap(); + textVisualTransform.Add((int)VisualTransformPropertyType.Offset, new PropertyValue(new Vector2(0.0f, 0.0f))) + .Add((int)VisualTransformPropertyType.OffsetPolicy, new PropertyValue(new Vector2((int)VisualTransformPolicyType.Relative, (int)VisualTransformPolicyType.Relative))) + .Add((int)VisualTransformPropertyType.SizePolicy, new PropertyValue(new Vector2((int)VisualTransformPolicyType.Absolute, (int)VisualTransformPolicyType.Absolute))) + .Add((int)VisualTransformPropertyType.Size, new PropertyValue(new Vector2(size.X - 100.0f, 50.0f))) + .Add((int)VisualTransformPropertyType.Origin, new PropertyValue((int)AlignType.Center)) + .Add((int)VisualTransformPropertyType.AnchorPoint, new PropertyValue((int)AlignType.Center)); + _textVisual.SetTransformAndSize(textVisualTransform, size); + + // Configure the transform and size of Primitive visual. + PropertyMap primitiveVisualTransform = new PropertyMap(); + primitiveVisualTransform.Add((int)VisualTransformPropertyType.Offset, new PropertyValue(new Vector2(size.X - 60.0f, 0.0f))) + .Add((int)VisualTransformPropertyType.OffsetPolicy, new PropertyValue(new Vector2((int)VisualTransformPolicyType.Absolute, (int)VisualTransformPolicyType.Absolute))) + .Add((int)VisualTransformPropertyType.SizePolicy, new PropertyValue(new Vector2((int)VisualTransformPolicyType.Absolute, (int)VisualTransformPolicyType.Absolute))) + .Add((int)VisualTransformPropertyType.Size, new PropertyValue(new Vector2(40.0f, 40.0f))) + .Add((int)VisualTransformPropertyType.Origin, new PropertyValue((int)AlignType.CenterBegin)) + .Add((int)VisualTransformPropertyType.AnchorPoint, new PropertyValue((int)AlignType.CenterBegin)); + _primitiveVisual.SetTransformAndSize(primitiveVisualTransform, size); + + // Configure the transform and size of Color visual. This is also the default value. + PropertyMap colorVisualTransform = new PropertyMap(); + colorVisualTransform.Add( (int)VisualTransformPropertyType.Offset, new PropertyValue(new Vector2(0.0f,0.0f))) + .Add((int)VisualTransformPropertyType.OffsetPolicy, new PropertyValue(new Vector2((int)VisualTransformPolicyType.Relative, (int)VisualTransformPolicyType.Relative))) + .Add((int)VisualTransformPropertyType.SizePolicy, new PropertyValue(new Vector2((int)VisualTransformPolicyType.Relative, (int)VisualTransformPolicyType.Relative))) + .Add( (int)VisualTransformPropertyType.Size, new PropertyValue(new Vector2(1.0f, 1.0f)) ) + .Add( (int)VisualTransformPropertyType.Origin, new PropertyValue((int)AlignType.TopBegin) ) + .Add( (int)VisualTransformPropertyType.AnchorPoint, new PropertyValue((int)AlignType.TopBegin) ); + _colorVisual.SetTransformAndSize(colorVisualTransform, size); + } + } +} \ No newline at end of file diff --git a/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/visuals-using-custom-view.cs b/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/visuals-using-custom-view.cs new file mode 100755 index 0000000..6057a2b --- /dev/null +++ b/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/visuals-using-custom-view.cs @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2017 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. + * + */ + +using System; +using Tizen.NUI; +using Tizen.NUI.Constants; + +namespace VisualsUsingCustomView +{ + class VisualsExample : NUIApplication + { + public VisualsExample() : base() + { + } + + public VisualsExample(string stylesheet) : base(stylesheet) + { + } + + public VisualsExample(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode) + { + } + + protected override void OnCreate() + { + base.OnCreate(); + Initialize(); + } + + private void Initialize() + { + Stage stage = Stage.Instance; + stage.BackgroundColor = Color.White; + + TableView contentLayout = new TableView(14, 1); + contentLayout.Name = "ContentLayout"; + contentLayout.WidthResizePolicy = ResizePolicyType.FillToParent; + contentLayout.HeightResizePolicy = ResizePolicyType.FillToParent; + contentLayout.SetCellPadding(new Size2D(5, 5)); + contentLayout.BackgroundColor = new Color(0.949f, 0.949f, 0.949f, 1.0f); + + stage.GetDefaultLayer().Add(contentLayout); + + TextLabel title = new TextLabel("Contacts List with Visuals"); + title.Name = "Title"; + title.StyleName = "Title"; + title.WidthResizePolicy = ResizePolicyType.FillToParent; + title.HeightResizePolicy = ResizePolicyType.UseNaturalSize; + title.HorizontalAlignment = "CENTER"; + contentLayout.Add(title); + contentLayout.SetFitHeight(0); + + // Create ContactView(s) from ContactItem(s) in ContactsList and add them to TableView + ContactView contactView; + foreach (ContactItem contact in ContactsList.s_contactData) + { + contactView = new ContactView(); + contactView.WidthResizePolicy = ResizePolicyType.FillToParent; + contactView.HeightResizePolicy = ResizePolicyType.FillToParent; + + // Configure visuals of ContactView via properties + contactView.Name = contact.Name; + contactView.ImageURL = contact.ImageURL; + contactView.Color = contact.Color; + contactView.Shape = contact.Shape; + contentLayout.Add(contactView); + } + } + + /// + /// The main entry point for the application. + /// + [STAThread] + static void _Main(string[] args) + { + VisualsExample visualsExample = new VisualsExample("/home/owner/apps_rw/NUISamples.TizenTV/res/json/control-dashboard-theme.json"); + visualsExample.Run(args); + } + } +} \ No newline at end of file diff --git a/Tizen.NUI/Tizen.NUI.csproj b/Tizen.NUI/Tizen.NUI.csproj index 53d75f2..a4c0e50 100755 --- a/Tizen.NUI/Tizen.NUI.csproj +++ b/Tizen.NUI/Tizen.NUI.csproj @@ -347,7 +347,7 @@ - + diff --git a/Tizen.NUI/src/internal/VisualFactory.cs b/Tizen.NUI/src/public/VisualFactory.cs similarity index 99% rename from Tizen.NUI/src/internal/VisualFactory.cs rename to Tizen.NUI/src/public/VisualFactory.cs index 5eae888..1ca74fb 100755 --- a/Tizen.NUI/src/internal/VisualFactory.cs +++ b/Tizen.NUI/src/public/VisualFactory.cs @@ -14,7 +14,7 @@ namespace Tizen.NUI /// /// VisualFactory is a singleton object that provides and shares visuals between views /// - internal class VisualFactory : BaseHandle + public class VisualFactory : BaseHandle { private global::System.Runtime.InteropServices.HandleRef swigCPtr;