private void changeModes(ref bool add_points_mode, ref bool edit_points_mode, HoudiniCurve.Mode mode) { switch (mode) { case HoudiniCurve.Mode.NONE: { add_points_mode = false; edit_points_mode = false; break; } case HoudiniCurve.Mode.ADD: { add_points_mode = true; edit_points_mode = false; break; } case HoudiniCurve.Mode.EDIT: { add_points_mode = false; edit_points_mode = true; break; } default: Debug.LogError("Invalid mode?"); break; } }
private void drawSceneUI() { string title_text = HoudiniConstants.HAPI_PRODUCT_SHORT_NAME + " Curve"; string add_hotkey_string = HoudiniHost.prAddingPointsModeHotKey.ToString(); string edit_hotkey_string = HoudiniHost.prEditingPointsModeHotKey.ToString(); string help_text = "" + add_hotkey_string + ": add points | " + edit_hotkey_string + ": edit points"; int skin = EditorPrefs.GetInt("UserSkin"); Color box_color = (skin == 0 ? mySceneUILightColour : mySceneUIDarkColour); Color text_color = Color.white; if (!myCurve.prEditable) { help_text = "This curve is not editable."; } if (myCurve.prIsAddingPoints) { help_text = "Click in space: add next point | Click a line segment: add midpoint | Backspace: delete last point | ESC or Enter: exit mode"; box_color = HoudiniHost.prAddingPointsModeColour; } else if (myCurve.prIsEditingPoints) { help_text = "Click or drag: select points | Delete: delete selected | Hold Control: toggle-based selection | ESC or Enter: exit mode"; box_color = HoudiniHost.prEditingPointsModeColour; } if (!mySceneWindowHasFocus && myCurve.prEditable) { help_text = "Scene window doesn't have focus. Hotkeys may not work. Right click anywhere in the scene to focus."; } Color original_color = GUI.color; float scene_width = myTempCamera.pixelWidth; float scene_height = myTempCamera.pixelHeight; float border_width = myActiveBorderWidth; float border_padding = mySceneUIBorderPadding; float border_total = border_width + border_padding; float line_height = mySceneUILineHeight; float line_padding = mySceneUILinePadding; float double_line_padding = 2.0f * line_padding; GUIStyle normal_text_style = new GUIStyle(GUI.skin.label); normal_text_style.alignment = TextAnchor.MiddleLeft; normal_text_style.fontStyle = FontStyle.Normal; normal_text_style.fontSize = (int)line_height - mySceneUIFontSizeFromLineHeightMod; GUIStyle bold_text_style = new GUIStyle(GUI.skin.label); bold_text_style.alignment = TextAnchor.MiddleLeft; bold_text_style.fontStyle = FontStyle.Bold; bold_text_style.fontSize = (int)line_height - mySceneUIFontSizeFromLineHeightMod; float box_height = line_height; float box_top = scene_height - border_total - box_height; float title_box_width = bold_text_style.CalcSize(new GUIContent(title_text)).x; title_box_width += double_line_padding; // The mode box should be nothing if the curve is static since there are no options for static curves. float mode_box_width = myCurve.prEditable ? mySceneUIModeIndicatorWidth : 0.0f; float help_box_width = scene_width - title_box_width - mode_box_width - (2.0f * border_total) - (2.0f * border_padding); float title_box_right = border_total; float mode_box_right = border_total + title_box_width + border_padding; float help_box_right = mode_box_right + mode_box_width + border_padding; // Create background boxes texture. Texture2D box_texture = new Texture2D(1, 1); box_texture.wrapMode = TextureWrapMode.Repeat; box_texture.SetPixel(0, 0, new Color(box_color.r - mySceneUIDarkeningFactor, box_color.g - mySceneUIDarkeningFactor, box_color.b - mySceneUIDarkeningFactor, 0.5f)); box_texture.Apply(); // Set up rectangles for the boxes and the labels. Rect title_box_rect = new Rect(title_box_right, box_top, title_box_width, box_height); Rect mode_box_rect = new Rect(mode_box_right, box_top, mode_box_width, box_height); Rect help_box_rect = new Rect(help_box_right, box_top, help_box_width, box_height); Rect title_text_rect = new Rect(title_box_right + line_padding, box_top, title_box_width - double_line_padding, box_height - double_line_padding); Rect mode_text_rect = new Rect(mode_box_right + line_padding, box_top, mode_box_width - double_line_padding, box_height - double_line_padding); Rect help_text_rect = new Rect(help_box_right + line_padding, box_top, help_box_width - double_line_padding, box_height - double_line_padding); // Start Drawing -------------------------------------------------------------------------------------------- Handles.BeginGUI(); GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height)); // Draw the background boxes for the Scene UI. GUI.color = box_color; GUI.DrawTexture(title_box_rect, box_texture, ScaleMode.StretchToFill); if (myCurve.prEditable) { GUI.DrawTexture(mode_box_rect, box_texture, ScaleMode.StretchToFill); } GUI.DrawTexture(help_box_rect, box_texture, ScaleMode.StretchToFill); // Draw the labels for the curve and the help. GUI.color = text_color; GUI.Label(title_text_rect, title_text, bold_text_style); GUI.Label(help_text_rect, help_text, normal_text_style); if (myCurve.prEditable) { // Set up mode selection toolbar. GUIStyle button_style = new GUIStyle(GUI.skin.button); button_style.alignment = TextAnchor.MiddleCenter; button_style.fontStyle = FontStyle.Normal; button_style.fontSize = (int)line_height - mySceneUIFontSizeFromLineHeightMod; Color toolbar_color = box_color; toolbar_color.r += mySceneUIBrightningFactor; toolbar_color.g += mySceneUIBrightningFactor; toolbar_color.b += mySceneUIBrightningFactor; GUI.color = toolbar_color; GUIContent[] modes = new GUIContent[3]; modes[0] = new GUIContent("View"); modes[1] = new GUIContent("Add"); modes[2] = new GUIContent("Edit"); // Draw the mode selection toolbar. // Note: We want to disable the toolbar if a mode key is being held down because // if a button is pressed the current mode will imidiatly switch back to the mode // whos key is being held down... GUI.enabled = !mySceneWindowHasFocus || ((myCurrentlyPressedKey != HoudiniHost.prAddingPointsModeHotKey) && (myCurrentlyPressedKey != HoudiniHost.prEditingPointsModeHotKey)); HoudiniCurve.Mode last_mode = myCurve.prCurrentMode; myCurve.prCurrentMode = (HoudiniCurve.Mode)GUI.Toolbar(mode_text_rect, (int)last_mode, modes); if (last_mode != myCurve.prCurrentMode) { clearSelection(); } GUI.enabled = true; // Draw selection rectangle. if (myCurve.prIsEditingPoints) { GUI.color = Color.white; GUI.Box(mySelectionArea, ""); } } // Draw yellow mode lines around the Scene view. if (mySceneWindowHasFocus) { // Create texture. Texture2D border_texture = new Texture2D(1, 1); border_texture.wrapMode = TextureWrapMode.Repeat; border_texture.SetPixel(0, 0, new Color(box_color.r, box_color.g, box_color.b, 0.6f)); border_texture.Apply(); float width = myTempCamera.pixelWidth; float height = myTempCamera.pixelHeight; if (myCurve.prCurrentMode == HoudiniCurve.Mode.NONE) { border_texture.SetPixel(0, 0, new Color(text_color.r, text_color.g, text_color.b, 0.6f)); border_texture.Apply(); border_width = myInactiveBorderWidth; } GUI.DrawTexture(new Rect(0, 0, width, border_width), // Top border_texture, ScaleMode.StretchToFill); GUI.DrawTexture(new Rect(0, border_width, border_width, height - border_width), // Right border_texture, ScaleMode.StretchToFill); GUI.DrawTexture(new Rect(border_width, height - border_width, width, height), // Bottom border_texture, ScaleMode.StretchToFill); GUI.DrawTexture(new Rect(width - border_width, border_width, // Left width, height - border_width - border_width), border_texture, ScaleMode.StretchToFill); } GUILayout.EndArea(); Handles.EndGUI(); // Stop Drawing --------------------------------------------------------------------------------------------- // Restore GUI colour. GUI.color = original_color; }