예제 #1
0
    }//!DrawPresets


    bool DrawCell(Rect rect, Texture2D tex, string name, bool selected, ISupportedPostComponent component)
    {
      rect = Params.Shrink( rect, 2 );
      if (Event.current.type == EventType.Repaint) GUI.skin.window.Draw( rect, new GUIContent(), 0 );
      rect = Params.Shrink( rect, 2 );

      if (selected) EditorGUI.DrawRect( rect, Color.red );

      var tr = rect;
      var lr = tr;
      tr.height -= 16;
      tr = Params.Shrink( tr, 2 );
      if (tex) GUI.DrawTexture( tr, tex );
      else GUI.DrawTexture( tr, Texture2D.blackTexture );

      lr.y += lr.height -= 16;
      lr.height = 16;
      GUI.Label( lr, name );

      if (selected)
      {
        lr.width /= 2;
        lr.x += lr.width;
        lr.width -= 10;
        var newAmount = GUI.HorizontalSlider( lr, component.LutAmount,  0,1);
        if (newAmount != component.LutAmount)
        {
          component.CREATE_UNDO( "set post blend" );
          component.LutAmount = newAmount;
          component.SET_DIRTY();
          SceneView.RepaintAll();
        }
      }

#if !P128
      var favcontains = favorites.ContainsKey( name );
      var fav_r = rect;
      var SIZE = Math.Min(32,fav_r.height* 0.3f);
      fav_r.x += fav_r.width - SIZE - 5;
      fav_r.y += 5;
      fav_r.width = fav_r.height = SIZE;
      if (favcontains || selected || Event.current.control)
      {
        GUI.DrawTexture( fav_r, favorites.ContainsKey( name ) ? favicon_enable : favicon_disable );
        EditorGUIUtility.AddCursorRect( fav_r, MouseCursor.Link );
        if (GUI.Button( fav_r, favContent, Params.Button ))
        {
          if (favcontains) RemoveFavorite( name );
          else CreateFavorite( name );
        }
      }
#endif



      //  if (selected) GUI.DrawTexture( rect, Button.active.background );

      return GUI.Button( rect, "", Params.Button );
    }
예제 #2
0
        void DrawPresets(ISupportedPostComponent component)
        {
            var zoom          = (int)Mathf.Clamp(Params.zoomFactor + 1, 1, 3);
            int cellHeight    = (int)((125 + 16) / ((zoom - 1) / 2f + 1));
            int CAPTUREHeight = (int)((125) / ((zoom - 1) / 2f + 1));
            var WIN_HEIGHT    = position.height - (40 + 20 + 24 + 20);


            var sortNotInverse = ((int)Params.sortInverse & (1 << (int)Params.sortMode)) == 0;
            var targetArray    = default_gradients;

            switch ((int)Params.sortMode)
            {
            case 0: targetArray = sortNotInverse ? default_gradients : inverse_default_gradients; break;

            case 1: targetArray = sortNotInverse ? bright_gradients : inverse_bright_gradients; break;

            case 2: targetArray = sortNotInverse ? hue_gradients : inverse_hue_gradients; break;

            case 3: targetArray = sortNotInverse ? compareToFirst_gradients : inverse_compareToFirst_gradients; break;
            }//sort type

            var l                   = component.LutTexture;
            int selectIndex         = -1;
            int filteredSelectIndex = -1;
            var __i                 = -1;
            var __M                 = -1;

            for (__i = 0; __i < targetArray.Count; __i++)
            {
                if (!SeartchValidate(targetArray[__i].name))
                {
                    continue;
                }
                if (Params.showFav == 1 && !favorites.ContainsKey(targetArray[__i].name))
                {
                    continue;
                }
                __M++;
                if (selectIndex == -1 && l == targetArray[__i].gradientTexture)
                {
                    filteredSelectIndex = __M;
                    selectIndex         = __i;
                }
            }

            // var XXX = Math.Min(3 * zoom, Math.Max(1, M + 1));
            var XXX            = 3 * zoom;
            int displaingCount = Mathf.CeilToInt(WIN_HEIGHT / cellHeight + 1) * XXX;

            var scrollX = Params.presetScrollX;
            var scrollY = Params.presetScrollY;

            if (Params.showFav == 1)
            {
                scrollX = Params.favScrollX;
                scrollY = Params.favScrollY;
            }

            if (mayResetScroll)
            {
                mayResetScroll = false;
                if (filteredSelectIndex != -1)
                {
                    var fixedcellHeight = cellHeight;
                    //(float)Params.presetScrollY + " " + filteredSelectIndex / XXX * cellHeight + " " + WIN_HEIGHT + " " + (filteredSelectIndex / XXX * cellHeight +
                    //Debug.Log( fixedcellHeight > Params.presetScrollY + WIN_HEIGHT );
                    if (filteredSelectIndex / XXX * fixedcellHeight < scrollY)
                    {
                        scrollY.Set(filteredSelectIndex / XXX * fixedcellHeight);
                    }
                    else if (filteredSelectIndex / XXX * fixedcellHeight + fixedcellHeight > scrollY + WIN_HEIGHT)
                    {
                        scrollY.Set(filteredSelectIndex / XXX * fixedcellHeight + fixedcellHeight - WIN_HEIGHT);
                    }
                }
            }//frame scroll


            Params.scroll.x = scrollX;
            Params.scroll.y = scrollY;
            Params.scroll   = GUILayout.BeginScrollView(Params.scroll);
            scrollX.Set(Params.scroll.x);
            scrollY.Set(Params.scroll.y);



            GUILayout.BeginVertical();
            var  height           = Mathf.Ceil(gradients.Length / (float)XXX);
            int  wasRender        = 0;
            int  __FirstRenderInc = -1;
            bool needRepaint      = false;

            var newCheck = component.GetHashString();

            if (Params.AutoRefresh == 1 && !string.Equals(newCheck, oldCheck, StringComparison.Ordinal))
            {
                oldCheck = newCheck;
                ClearImages(false);
                currentWindow.Repaint();
            }//refrest if changed



            __i = -1;
            Rect line          = new Rect();
            bool renderTexture = false;
            bool newLine       = false;

            if (__M == -1)
            {
                if (Params.showFav == 1)
                {
                    GUILayout.Label("No Favorite Elements", Params.Label);
                }
                else
                {
                    GUILayout.Label("No elements '" + (string)Params.filtres + "' found", Params.Label);
                }
            }
            else
            {
                line        = EditorGUILayout.GetControlRect(GUILayout.Height((__M / XXX + 1) * cellHeight));
                line.height = cellHeight;
                line.y     -= line.height;
                int __renderInc = -1;

                for (int y = 0; y < height; y++)
                {
                    newLine = true;


                    for (int x = 0; x < XXX; x++)
                    {
                        __i++;
                        //var i = x + y * XXX;
                        if (__i >= targetArray.Count)
                        {
                            break;
                        }

                        if (!SeartchValidate(targetArray[__i].name))
                        {
                            x--;
                            continue;
                        }
                        if (Params.showFav == 1 && !favorites.ContainsKey(targetArray[__i].name))
                        {
                            x--;
                            continue;
                        }

                        if (newLine)
                        {
                            newLine = false;
                            //line = EditorGUILayout.GetControlRect( GUILayout.Height( cellHeight ) );
                            line.y       += line.height;
                            renderTexture = line.y + line.height >= Params.scroll.y && line.y - line.height <= Params.scroll.y + WIN_HEIGHT;
                        }



                        var rect = line;
                        rect.width = line.width / XXX;
                        rect.x     = rect.width * x;

                        if (!renderTexture)
                        {
                            continue;
                        }
                        __renderInc++;

                        if (__FirstRenderInc == -1)
                        {
                            __FirstRenderInc = __renderInc;
                        }

                        if (renderedScreen.Length != targetArray.Count)
                        {
                            System.Array.Resize(ref renderedScreen, targetArray.Count);
                            ClearImages(false);
                            currentWindow.Repaint();
                        }

                        if (renderedIndex < __FirstRenderInc)
                        {
                            renderedIndex = __FirstRenderInc;
                        }

                        /* if (Params.showFav == 1)
                         * Debug.Log( (wasRender < (Params.zoomFactor + 1) * IMAGE_RENDER_PER_FRAME) + " " + (renderedIndex % displaingCount) + " " + __renderInc + " " + __FirstRenderInc );*/

                        if (wasRender < (Params.zoomFactor + 1) * IMAGE_RENDER_PER_FRAME && renderedIndex % displaingCount == (__renderInc - __FirstRenderInc))
                        {
                            if ((int)rect.width - 10 > 0 && !renderedDoubleCheck[__i])
                            {
                                renderedIndex++;

                                component.CameraPredrawAction(); // PRE

                                //memory
                                var oldLutEnable  = component.LutEnable;
                                var oldLutTexture = component.LutTexture;
                                var oldAmount     = component.LutAmount;
                                //change
                                component.LutEnable  = true;
                                component.LutTexture = (targetArray[__i]).gradientTexture;
                                component.LutAmount  = (1);

                                var oldAnti = component.AntiAliasEnable;
                                component.AntiAliasEnable = false;
                                //draw
                                if (renderedScreen[__i])
                                {
                                    DestroyImmediate(renderedScreen[__i], true);
                                }
                                renderedDoubleCheck[__i]  = renderedScreen[__i] = TakeScreen(Camera.main, (int)rect.width - 10, CAPTUREHeight);
                                component.AntiAliasEnable = oldAnti;

                                //restore
                                component.LutEnable  = oldLutEnable;
                                component.LutTexture = (oldLutTexture);
                                component.LutAmount  = (oldAmount);

                                component.CameraPostDrawAction(); // POST

                                wasRender++;
                            }
                        }

                        var screen = renderedScreen[__i];

                        if (!renderedDoubleCheck[__i])
                        {
                            needRepaint = true;
                        }

                        if (DrawCell(rect, screen, targetArray[__i].name, selectIndex == __i, component))
                        {
                            WasElementsChanged = true;
                            component.CREATE_UNDO("set " + targetArray[__i].name);
                            component.LutTexture = (targetArray[__i].gradientTexture);
                            if (!component.LutEnable)
                            {
                                component.LutAmount = (1);
                            }
                            component.LutEnable = true;
                            component.SET_DIRTY();
                            UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
                        }
                    }
                }
            }


            GUILayout.EndVertical();


            if (wasRender < (Params.zoomFactor + 1) * IMAGE_RENDER_PER_FRAME)
            {
                // renderedIndex = firstI;
                renderedIndex += (int)(Params.zoomFactor + 1) * IMAGE_RENDER_PER_FRAME - wasRender;
                //needRepaint = true;
            }
            if (needRepaint)
            {
                Repaint();
            }
            GUILayout.EndScrollView();
        }//!DrawPresets