public void checkLayerRectsForLeftMouseClick(Vector2 clickPos) { FizzikSprite sprite = editor.getWorkingSprite(); FizzikFrame frame = sprite.getCurrentFrame(); for (int i = 0; i < layerRects.Count; i++) { Rect layerRect = layerRects[i]; //Offset layerRect by its container's rect Vector2 offsetVec = layerRect.position + layersOffsetRect.position - scrollPosition; Rect relativeRect = new Rect(offsetVec.x, offsetVec.y, layerRect.width, layerRect.height); if (layersScrollRect.Contains(clickPos) && relativeRect.Contains(clickPos)) { //Debug.Log("Layer Subwindow Left Clicked : " + i); frame.setCurrentLayer(i); return; } } }
public override void handleGUI(int windowID) { base.handleGUI(windowID); Event e = Event.current; //Layer layouting variables FizzikSprite sprite = editor.getWorkingSprite(); FizzikFrame frame = sprite.getCurrentFrame(); List <FizzikLayer> layers = frame.layers; float w = currentRect.width; float h = currentRect.height; float hw = w / 2; float hh = h / 2; //Styles GUIStyle scrollViewStyle = new GUIStyle(GUI.skin.scrollView); GUIStyle layersStyle = new GUIStyle(); layersStyle.normal.background = layersBackgroundTex; GUIStyle layerStyle = new GUIStyle(GUI.skin.button); layerStyle.normal.background = layerBackgroundTex; GUIStyle layerSelectedStyle = new GUIStyle(layerStyle); layerSelectedStyle.normal.background = layerSelectedBackgroundTex; GUIStyle layerNameStyle = new GUIStyle(); layerNameStyle.fixedWidth = LAYER_NAME_WIDTH; layerNameStyle.clipping = TextClipping.Clip; GUIStyle layerOverallToolbarStyle = new GUIStyle(); //Begin GUI GUILayout.BeginVertical(); scrollPosition = GUILayout.BeginScrollView(scrollPosition, scrollViewStyle); //Begin Layers GUILayout.BeginVertical(layersStyle); layerRects.Clear(); for (int i = layers.Count() - 1; i >= 0; i--) { FizzikLayer layer = layers[i]; //Begin Layer if (frame.getCurrentLayer() == layer) { GUILayout.BeginHorizontal(layerSelectedStyle, GUILayout.Height(LAYER_HEIGHT)); } else { GUILayout.BeginHorizontal(layerStyle, GUILayout.Height(LAYER_HEIGHT)); } GUILayout.Box(layer.texture, new GUIStyle(GUI.skin.button), GUILayout.Width(LAYER_HEIGHT), GUILayout.Height(LAYER_HEIGHT)); GUILayout.Label(layer.name, layerNameStyle); GUILayout.EndHorizontal(); layerRects.Insert(0, GUILayoutUtility.GetLastRect()); //Insert to front so that the layerRects list is in correct layer order //End Layer } GUILayout.EndVertical(); //End Layers //Draw layerRects DEBUG TODO foreach (Rect rect in layerRects) { GUIUtility.DrawRectangle(rect, Color.cyan, true, pixel); } GUILayout.EndScrollView(); layersScrollRect = GUILayoutUtility.GetLastRect(); //Begin Layer Overall Toolbar GUILayout.BeginHorizontal(layerOverallToolbarStyle, GUILayout.Height(20)); GUILayout.FlexibleSpace(); if (GUILayout.Button("+", GUILayout.Width(16), GUILayout.Height(16))) { if (isGUIButtonClick()) { frame.createNewLayer(sprite); } } if (GUILayout.Button("-", GUILayout.Width(16), GUILayout.Height(16))) { if (isGUIButtonClick()) { frame.deleteCurrentLayer(sprite); } } GUILayout.Button("a", GUILayout.Width(16), GUILayout.Height(16)); GUILayout.Button("b", GUILayout.Width(16), GUILayout.Height(16)); GUILayout.EndHorizontal(); //End Layer Overall Toolbar GUILayout.EndVertical(); layersOffsetRect = GUILayoutUtility.GetLastRect(); //End GUI layoutting trackMouseClicksAndDrags(); handleCursors(); dragWindow(); }