Exemplo n.º 1
0
    //static
    public static Color Get(string PaletteName, string ColorName, Color ifNull)
    {
        ColorPalette palette = null;

        if (!cache.TryGetValue(PaletteName, out palette))
        {
            if (AssetDBHelper.TryLoadAsset <ColorPalette>(PaletteName + " t: ColorPalette", out palette))
            {
                cache[PaletteName] = palette;
                return(palette.Get(ColorName, ifNull));
            }
            return(ifNull);
        }
        return(palette.Get(ColorName, ifNull));
    }
Exemplo n.º 2
0
        public void PaletteTest1()
        {
            var palette = new ColorPalette();

            palette.Add(0.0f, new RGB(255, 0, 0));
            palette.Add(1.0f, new RGB(0, 255, 0));

            // Before first stop
            Assert.AreEqual(new RGB(255, 0, 0), palette.Get(-1.0f));

            // At first stop
            Assert.AreEqual(new RGB(255, 0, 0), palette.Get(0.0f));

            // 25% between the two stops
            Assert.AreEqual(new RGB(191, 63, 0), palette.Get(0.25f));

            // 50% between the two stops
            Assert.AreEqual(new RGB(127, 127, 0), palette.Get(0.5f));

            // 75% between the two stops
            Assert.AreEqual(new RGB(63, 191, 0), palette.Get(0.75f));

            // At last stop
            Assert.AreEqual(new RGB(0, 255, 0), palette.Get(1.0f));

            // After last stop
            Assert.AreEqual(new RGB(0, 255, 0), palette.Get(2.0f));
        }
Exemplo n.º 3
0
        private void Set_ControlColor()
        {
            Tab_Month.BackColor    = Palette.Get(ColorPalette.Color_.CheeryPink);
            Tab_Week.BackColor     = Palette.Get(ColorPalette.Color_.Rhyme);
            Tab_Day.BackColor      = Palette.Get(ColorPalette.Color_.Cyan);
            Tab_Priority.BackColor = Palette.Get(ColorPalette.Color_.Gray);
            Tab_Project.BackColor  = Palette.Get(ColorPalette.Color_.Pink);

            Page_Month.BackgroundImage       = Properties.Resources.ControlTab_01;
            Page_Month.BackgroundImageLayout = ImageLayout.Stretch;

            Page_Week.BackgroundImage       = Properties.Resources.ControlTab_04;
            Page_Week.BackgroundImageLayout = ImageLayout.Stretch;

            Page_Day.BackgroundImage       = Properties.Resources.ControlTab_03;
            Page_Day.BackgroundImageLayout = ImageLayout.Stretch;

            Page_Priority.BackgroundImage       = Properties.Resources.ControlTab_02;
            Page_Priority.BackgroundImageLayout = ImageLayout.Stretch;

            Page_Project.BackgroundImage       = Properties.Resources.ControlTab_05;
            Page_Project.BackgroundImageLayout = ImageLayout.Stretch;
        }
Exemplo n.º 4
0
        private static void DrawData(MarkDownData data, Action <string> PageChange, Action <string> DocChange, Action Repaint)
        {
            var doc = data.doc;

            switch (data.type)
            {
            case KeyType.foldin:
                data.doc.InFoldout      = true;
                data.doc.CurrentFoldout = OnGUIUtility.Foldout(data.keyValue, doc.Styles.Foldout, GUILayout.ExpandWidth(true), GUILayout.Height(EditorGUIUtility.singleLineHeight * 1.3f));   // OnGUIUtility.EditorPrefsFoldoutGroup(data.keyValue);
                OnGUIUtility.Layout.IndentBegin(2);
                break;

            case KeyType.foldout:
                data.doc.InFoldout = false;
                OnGUIUtility.Layout.IndentEnd(2);
                break;
            }
            if (data.doc.InFoldout && !data.doc.CurrentFoldout)
            {
                return;
            }
            switch (data.type)
            {
            case KeyType.text:
                Rect position = GUILayoutUtility.GetRect(EditorGUIUtility.TrTextContent(data.Data), doc.Styles.Font, GUILayout.ExpandHeight(true));
                OnGUIUtility.Layout.IndentDisable();
                EditorGUI.SelectableLabel(position, data.Data, doc.Styles.Font);
                OnGUIUtility.Layout.IndentEnable();
                break;

            case KeyType.code:
                OnGUIUtility.Vision.BeginBackGroundColor(ColorPalette.Get(doc.ColorSetting, "Area_BackGround", EditorGUIUtility.isProSkin ? Color.white : Color.black));
                EditorGUILayout.TextArea(data.Data, doc.Styles.Area);
                OnGUIUtility.Vision.EndBackGroundColor();
                break;

            case KeyType.qa:
                OnGUIUtility.Vision.BeginBackGroundColor(ColorPalette.Get(doc.ColorSetting, "Area_BackGround", EditorGUIUtility.isProSkin ? Color.white : Color.black));

                EditorGUILayout.SelectableLabel(RichTextHelper.Color(data.keyValue, Color.green), doc.Styles.Font, GUILayout.ExpandWidth(true), GUILayout.Height(EditorGUIUtility.singleLineHeight));
                EditorGUILayout.TextArea(data.Data, doc.Styles.Area);
                OnGUIUtility.Vision.EndBackGroundColor();
                break;

            case KeyType.font:
                GUIStyle fontstyle = data.keyValue == "B" ? doc.Styles.FontB : data.keyValue == "I" ? doc.Styles.FontI : data.keyValue == "BI" ? doc.Styles.FontBI : doc.Styles.Font;
                EditorGUILayout.SelectableLabel(data.Data, fontstyle, GUILayout.Height(EditorGUIUtility.singleLineHeight));
                break;

            case KeyType.title:
                int      size  = int.Parse(data.keyValue);
                GUIStyle style = EditorStyles.boldLabel;
                switch (size)
                {
                case 1: style = doc.Styles.Title3; break;

                case 2: style = doc.Styles.Title2; break;

                case 3: style = doc.Styles.Title1; break;
                }
                EditorGUILayout.SelectableLabel(data.Data, style, GUILayout.Height(EditorGUIUtility.singleLineHeight * size * 1.3f), GUILayout.MinWidth(500));
                if (size == 3)
                {
                    OnGUIUtility.Layout.Line();
                }
                break;

            case KeyType.link:
                if (GUILayout.Button(data.Data, doc.Styles.Link))
                {
                    EditorGUIUtility.systemCopyBuffer = data.Data;
                    Application.OpenURL(data.Data);
                }
                if (Event.current.type == EventType.Repaint)
                {
                    var last = GUILayoutUtility.GetLastRect();
                    EditorGUIUtility.AddCursorRect(last, MouseCursor.Link);
                }
                break;

            case KeyType.image:
                if (data.texture)
                {
                    int w = data.texture.width;
                    int h = data.texture.height;
                    if (w > 1024)
                    {
                        h = (int)((float)h / w * 1024f);
                        w = 1024;
                    }
                    if (h > 1024)
                    {
                        w = (int)((float)w / h * 1024f);
                        h = 1024;
                    }
                    GUILayout.Box("", GUILayout.Width(w), GUILayout.Height(h));
                    if (Event.current.type == EventType.Repaint)
                    {
                        Rect rect = GUILayoutUtility.GetLastRect();

                        GUI.DrawTexture(rect, data.texture);
                    }
                }
                else if (data.gifDrawer != null && Repaint != null)
                {
                    data.gifDrawer.OnGUI(Repaint);
                }
                break;

            case KeyType.separator:
                OnGUIUtility.Layout.Line();
                break;

            case KeyType.page:
                if (GUILayout.Button("▶" + data.Data, doc.Styles.Page, GUILayout.ExpandWidth(false), GUILayout.Height(EditorGUIUtility.singleLineHeight * 1.3f)))
                {
                    PageChange?.Invoke(data.Data);
                }
                break;

            case KeyType.doc:
                if (GUILayout.Button("▶" + data.Data, doc.Styles.Doc, GUILayout.ExpandWidth(false), GUILayout.Height(EditorGUIUtility.singleLineHeight * 1.3f)))
                {
                    DocChange?.Invoke(data.Data);
                }
                break;

            case KeyType.table:
                GUILayout.BeginHorizontal();
                foreach (var item in data.subdatas)
                {
                    //OnGUIUtility.Debug.ButtonTest();
                    DrawData(item, PageChange, DocChange, Repaint);
                    //OnGUIUtility.Debug.DrawLastRect(Color.white);
                }
                GUILayout.EndHorizontal();
                break;
            }
        }
Exemplo n.º 5
0
        public override void OnGUI()
        {
            base.OnGUI();
            //CheckDoc
            MarkDownDoc doc = null;

            if (string.IsNullOrEmpty(CurrentDocName))
            {
                if (Docs.TryGetValue("Index", out doc))
                {
                    CurrentDocName = "Index";
                }
            }
            else
            {
                doc = Docs[CurrentDocName];
                if (Event.current.type == EventType.Layout)
                {
                    if (DocPages.Count > 0)
                    {
                        var oldDoc = Docs[DocPages.Peek()];
                        if (oldDoc.datas.Count > 0)
                        {
                            oldDoc.Release();
                        }
                    }
                    if (doc.datas.Count == 0)
                    {
                        doc.Load();
                    }
                    else
                    {
                        if (AutoRefresh && doc.RawDoc.text != doc.rawDoc)
                        {
                            doc.Release();
                            doc.rawDoc = doc.RawDoc.text;
                            doc.Load();
                        }
                    }
                }
            }
            //DrawDoc
            if (doc != null)
            {
                //ToolBar
                ToolBar();
                //DocContent
                EditorGUI.DrawRect(DrawRect, ColorPalette.Get(ColorSettings, "BackGround", Color.white));
                v = GUILayout.BeginScrollView(v);
                {
                    if (searched != null)
                    {
                        if (Event.current.type == EventType.Repaint)
                        {
                            EditorGUI.DrawRect(searched.drawRect, ColorPalette.Get(ColorSettings, "HightLight", Color.white));
                        }
                        if (Search.Current.IsNullOrEmpty())
                        {
                            searched = null;
                        }
                    }
                    EditorMarkDownDrawer.DrawDoc(doc, changePage, changeDoc, window.Repaint);
                }
                GUILayout.EndScrollView();
                if (Event.current.type == EventType.Repaint)
                {
                    DrawRect = GUILayoutUtility.GetLastRect();
                }
            }
            else
            {
                EditorGUILayout.SelectableLabel("Can't find Index.md Document at :" + PathTools.RelativeAssetPath(this.GetType(), RelativePath));
                EditorGUILayout.SelectableLabel("First you should create default page");
                if (GUILayout.Button("CreateReadMe"))
                {
                    if (EditorUtility.DisplayDialog("CreateIndex.md", "After create .md file,you have to reopen this editorwindow.", "OK", "Cancel"))
                    {
                        //Template
                        string[]  assets = AssetDatabase.FindAssets("TMP_ReadMe");
                        TextAsset text   = AssetDatabase.LoadAssetAtPath <TextAsset>(AssetDatabase.GUIDToAssetPath(assets[0]));
                        //
                        var DirRoot     = PathTools.RelativeAssetPath(this.GetType(), RelativePath);
                        var FileDirRoot = Directory.GetParent(DirRoot).FullName + @"\" + Path.GetFileName(DirRoot);
                        if (!Directory.Exists(FileDirRoot))
                        {
                            Directory.CreateDirectory(FileDirRoot);
                        }
                        FileTools.WriteAllText(FileDirRoot + "/Index.md", text.text);

                        AssetDatabase.Refresh();
                        window.Close();
                    }
                }
            }
            //PingDocScript
            if (EditScript)
            {
                GUILayout.BeginHorizontal();
                {
                    AutoRefresh = GUILayout.Toggle(AutoRefresh, "自动刷新");
                    OnGUIUtility.ScriptField("Editor Script", this.GetType());
                }
                GUILayout.EndHorizontal();
            }
        }
Exemplo n.º 6
0
            public MDStyles(string ColorSetting)
            {
                Title1                  = new GUIStyle(OnGUIUtility.Fonts.RichText);
                Title1.fontStyle        = FontStyle.Bold;
                Title1.fontSize         = (int)EditorGUIUtility.singleLineHeight * 3;
                Title1.normal.textColor = ColorPalette.Get(ColorSetting, "Title1", EditorGUIUtility.isProSkin ? Color.white : Color.black);
                Title1.hover.textColor  = Title1.normal.textColor;

                Title2                  = new GUIStyle(OnGUIUtility.Fonts.RichText);
                Title2.fontStyle        = FontStyle.Bold;
                Title2.fontSize         = (int)EditorGUIUtility.singleLineHeight * 2;
                Title2.normal.textColor = ColorPalette.Get(ColorSetting, "Title2", EditorGUIUtility.isProSkin ? Color.white : Color.black);
                Title2.hover.textColor  = Title2.normal.textColor;

                Title3                  = new GUIStyle(OnGUIUtility.Fonts.RichText);
                Title3.fontStyle        = FontStyle.Bold;
                Title3.fontSize         = (int)EditorGUIUtility.singleLineHeight * 1;
                Title3.normal.textColor = ColorPalette.Get(ColorSetting, "Title3", EditorGUIUtility.isProSkin ? Color.white : Color.black);
                Title3.hover.textColor  = Title3.normal.textColor;
                Title3.active.textColor = Title3.normal.textColor;

                Foldout                     = new GUIStyle(EditorStyles.foldout);
                Foldout.richText            = true;
                Foldout.normal.textColor    = ColorPalette.Get(ColorSetting, "Foldout", EditorGUIUtility.isProSkin ? Color.white : Color.black);
                Foldout.hover.textColor     = Foldout.normal.textColor;
                Foldout.active.textColor    = Foldout.normal.textColor;
                Foldout.focused.textColor   = Foldout.normal.textColor;
                Foldout.onActive.textColor  = Foldout.normal.textColor;
                Foldout.onHover.textColor   = Foldout.normal.textColor;
                Foldout.onFocused.textColor = Foldout.normal.textColor;
                Foldout.onNormal.textColor  = Foldout.normal.textColor;


                Page = new GUIStyle(Title3);
                Page.normal.textColor = ColorPalette.Get(ColorSetting, "Page", EditorGUIUtility.isProSkin ? Color.cyan : Color.cyan / 2);

                Doc = new GUIStyle(Title3);
                Doc.normal.textColor = ColorPalette.Get(ColorSetting, "Doc", EditorGUIUtility.isProSkin ? Color.green : Color.green / 2);

                Font                  = new GUIStyle(OnGUIUtility.Fonts.RichText);
                Font.alignment        = TextAnchor.MiddleLeft;
                Font.normal.textColor = ColorPalette.Get(ColorSetting, "Font", EditorGUIUtility.isProSkin ? Color.white : Color.black);
                Font.hover.textColor  = Font.normal.textColor;
                Font.stretchWidth     = false;
                Font.wordWrap         = true;

                FontI           = new GUIStyle(Font);
                FontI.fontStyle = FontStyle.Italic;

                FontB           = new GUIStyle(Font);
                FontB.fontStyle = FontStyle.Bold;

                FontBI           = new GUIStyle(Font);
                FontBI.fontStyle = FontStyle.BoldAndItalic;

                Link = new GUIStyle("PR PrefabLabel");
                Link.normal.textColor = ColorPalette.Get(ColorSetting, "Link", EditorGUIUtility.isProSkin ? OnGUIUtility.Colors.blue_light : OnGUIUtility.Colors.blue);

                Area                   = new GUIStyle(EditorStyles.textArea);
                Area.richText          = true;
                Area.normal.textColor  = ColorPalette.Get(ColorSetting, "Area", EditorGUIUtility.isProSkin ? Color.white : Color.black);
                Area.hover.textColor   = Area.normal.textColor;
                Area.active.textColor  = Area.normal.textColor;
                Area.focused.textColor = Area.normal.textColor;
            }