Here are the examples of the csharp api UnityEngine.GUI.DrawTextureWithTexCoords(UnityEngine.Rect, UnityEngine.Texture, UnityEngine.Rect, bool) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
22 Examples
19
Source : NGUIEditorTools.cs
with Apache License 2.0
from 365082218
with Apache License 2.0
from 365082218
public static void DrawSprite (Texture2D tex, Rect rect, Rect outer, Rect inner, Rect uv, Color color, Material mat)
{
// Create the texture rectangle that is centered inside rect.
Rect outerRect = rect;
outerRect.width = outer.width;
outerRect.height = outer.height;
if (outerRect.width > 0f)
{
float f = rect.width / outerRect.width;
outerRect.width *= f;
outerRect.height *= f;
}
if (rect.height > outerRect.height)
{
outerRect.y += (rect.height - outerRect.height) * 0.5f;
}
else if (outerRect.height > rect.height)
{
float f = rect.height / outerRect.height;
outerRect.width *= f;
outerRect.height *= f;
}
if (rect.width > outerRect.width) outerRect.x += (rect.width - outerRect.width) * 0.5f;
// Draw the background
NGUIEditorTools.DrawTiledTexture(outerRect, NGUIEditorTools.backdropTexture);
// Draw the sprite
GUI.color = color;
if (mat == null)
{
GUI.DrawTextureWithTexCoords(outerRect, tex, uv, true);
}
else
{
// NOTE: There is an issue in Unity that prevents it from clipping the drawn preview
// using BeginGroup/EndGroup, and there is no way to specify a UV rect... le'suq.
UnityEditor.EditorGUI.DrawPreviewTexture(outerRect, tex, mat);
}
// Draw the border indicator lines
GUI.BeginGroup(outerRect);
{
tex = NGUIEditorTools.contrastTexture;
GUI.color = Color.white;
if (inner.xMin != outer.xMin)
{
float x0 = (inner.xMin - outer.xMin) / outer.width * outerRect.width - 1;
NGUIEditorTools.DrawTiledTexture(new Rect(x0, 0f, 1f, outerRect.height), tex);
}
if (inner.xMax != outer.xMax)
{
float x1 = (inner.xMax - outer.xMin) / outer.width * outerRect.width - 1;
NGUIEditorTools.DrawTiledTexture(new Rect(x1, 0f, 1f, outerRect.height), tex);
}
if (inner.yMin != outer.yMin)
{
float y0 = (inner.yMin - outer.yMin) / outer.height * outerRect.height - 1;
NGUIEditorTools.DrawTiledTexture(new Rect(0f, y0, outerRect.width, 1f), tex);
}
if (inner.yMax != outer.yMax)
{
float y1 = (inner.yMax - outer.yMin) / outer.height * outerRect.height - 1;
NGUIEditorTools.DrawTiledTexture(new Rect(0f, y1, outerRect.width, 1f), tex);
}
}
GUI.EndGroup();
// Draw the lines around the sprite
Handles.color = Color.black;
Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMin), new Vector3(outerRect.xMin, outerRect.yMax));
Handles.DrawLine(new Vector3(outerRect.xMax, outerRect.yMin), new Vector3(outerRect.xMax, outerRect.yMax));
Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMin), new Vector3(outerRect.xMax, outerRect.yMin));
Handles.DrawLine(new Vector3(outerRect.xMin, outerRect.yMax), new Vector3(outerRect.xMax, outerRect.yMax));
// Sprite size label
string text = string.Format("Sprite Size: {0}x{1}",
Mathf.RoundToInt(Mathf.Abs(outer.width)),
Mathf.RoundToInt(Mathf.Abs(outer.height)));
EditorGUI.DropShadowLabel(GUILayoutUtility.GetRect(Screen.width, 18f), text);
}
19
Source : SpriteSelector.cs
with Apache License 2.0
from 365082218
with Apache License 2.0
from 365082218
void OnGUI ()
{
EditorGUIUtility.LookLikeControls(80f);
if (mAtlas == null)
{
GUILayout.Label("No Atlas selected.", "LODLevelNotifyText");
}
else
{
bool close = false;
GUILayout.Label(mAtlas.name + " Sprites", "LODLevelNotifyText");
NGUIEditorTools.DrawSeparator();
GUILayout.BeginHorizontal();
GUILayout.Space(84f);
string before = NGUISettings.partialSprite;
string after = EditorGUILayout.TextField("", before, "SearchTextField");
NGUISettings.partialSprite = after;
if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
{
NGUISettings.partialSprite = "";
GUIUtility.keyboardControl = 0;
}
GUILayout.Space(84f);
GUILayout.EndHorizontal();
Texture2D tex = mAtlas.texture as Texture2D;
if (tex == null)
{
GUILayout.Label("The atlas doesn't have a texture to work with");
return;
}
BetterList<string> sprites = mAtlas.GetListOfSprites(NGUISettings.partialSprite);
float size = 80f;
float padded = size + 10f;
int columns = Mathf.FloorToInt(Screen.width / padded);
if (columns < 1) columns = 1;
int offset = 0;
Rect rect = new Rect(10f, 0, size, size);
GUILayout.Space(10f);
mPos = GUILayout.BeginScrollView(mPos);
while (offset < sprites.size)
{
GUILayout.BeginHorizontal();
{
int col = 0;
rect.x = 10f;
for (; offset < sprites.size; ++offset)
{
UIAtlas.Sprite sprite = mAtlas.GetSprite(sprites[offset]);
if (sprite == null) continue;
// Button comes first
if (GUI.Button(rect, ""))
{
float delta = Time.realtimeSinceStartup - mClickTime;
mClickTime = Time.realtimeSinceStartup;
if (spriteName != sprite.name)
{
if (mSprite != null)
{
NGUIEditorTools.RegisterUndo("Atlas Selection", mSprite);
mSprite.spriteName = sprite.name;
mSprite.MakePixelPerfect();
EditorUtility.SetDirty(mSprite.gameObject);
}
else if (mCallback != null)
{
mName = sprite.name;
mCallback(sprite.name);
}
}
else if (delta < 0.5f) close = true;
}
if (Event.current.type == EventType.Repaint)
{
// On top of the button we have a checkboard grid
NGUIEditorTools.DrawTiledTexture(rect, NGUIEditorTools.backdropTexture);
Rect uv = sprite.outer;
if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
uv = NGUIMath.ConvertToTexCoords(uv, tex.width, tex.height);
// Calculate the texture's scale that's needed to display the sprite in the clipped area
float scaleX = rect.width / uv.width;
float scaleY = rect.height / uv.height;
// Stretch the sprite so that it will appear proper
float aspect = (scaleY / scaleX) / ((float)tex.height / tex.width);
Rect clipRect = rect;
if (aspect != 1f)
{
if (aspect < 1f)
{
// The sprite is taller than it is wider
float padding = size * (1f - aspect) * 0.5f;
clipRect.xMin += padding;
clipRect.xMax -= padding;
}
else
{
// The sprite is wider than it is taller
float padding = size * (1f - 1f / aspect) * 0.5f;
clipRect.yMin += padding;
clipRect.yMax -= padding;
}
}
GUI.DrawTextureWithTexCoords(clipRect, tex, uv);
// Draw the selection
if (spriteName == sprite.name)
{
NGUIEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f));
}
}
if (++col >= columns)
{
++offset;
break;
}
rect.x += padded;
}
}
GUILayout.EndHorizontal();
GUILayout.Space(padded);
rect.y += padded;
}
GUILayout.EndScrollView();
if (close) Close();
}
}
19
Source : SpriteInfoDrawer.cs
with MIT License
from ashishgopalhattimare
with MIT License
from ashishgopalhattimare
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
//SerializedProperty prop_fileID = property.FindPropertyRelative("fileID");
SerializedProperty prop_id = property.FindPropertyRelative("id");
SerializedProperty prop_name = property.FindPropertyRelative("name");
SerializedProperty prop_hashCode = property.FindPropertyRelative("hashCode");
SerializedProperty prop_unicode = property.FindPropertyRelative("unicode");
SerializedProperty prop_x = property.FindPropertyRelative("x");
SerializedProperty prop_y = property.FindPropertyRelative("y");
SerializedProperty prop_width = property.FindPropertyRelative("width");
SerializedProperty prop_height = property.FindPropertyRelative("height");
SerializedProperty prop_xOffset = property.FindPropertyRelative("xOffset");
SerializedProperty prop_yOffset = property.FindPropertyRelative("yOffset");
SerializedProperty prop_xAdvance = property.FindPropertyRelative("xAdvance");
SerializedProperty prop_scale = property.FindPropertyRelative("scale");
SerializedProperty prop_sprite = property.FindPropertyRelative("sprite");
// Get a reference to the sprite texture
Texture tex = (property.serializedObject.targetObject as TMP_Spritereplacedet).spriteSheet;
// Return if we don't have a texture replacedigned to the sprite replacedet.
if (tex == null)
{
Debug.LogWarning("Please replacedign a valid Sprite Atlas texture to the [" + property.serializedObject.targetObject.name + "] Sprite replacedet.", property.serializedObject.targetObject);
return;
}
Vector2 spriteTexPosition = new Vector2(position.x, position.y);
Vector2 spriteSize = new Vector2(65, 65);
if (prop_width.floatValue >= prop_height.floatValue)
{
spriteSize.y = prop_height.floatValue * spriteSize.x / prop_width.floatValue;
spriteTexPosition.y += (spriteSize.x - spriteSize.y) / 2;
}
else
{
spriteSize.x = prop_width.floatValue * spriteSize.y / prop_height.floatValue;
spriteTexPosition.x += (spriteSize.y - spriteSize.x) / 2;
}
// Compute the normalized texture coordinates
Rect texCoords = new Rect(prop_x.floatValue / tex.width, prop_y.floatValue / tex.height, prop_width.floatValue / tex.width, prop_height.floatValue / tex.height);
GUI.DrawTextureWithTexCoords(new Rect(spriteTexPosition.x + 5, spriteTexPosition.y + 2.5f, spriteSize.x, spriteSize.y), tex, texCoords, true);
// We get Rect since a valid position may not be provided by the caller.
Rect rect = new Rect(position.x, position.y, position.width, 49);
rect.x += 70;
bool isEnabled = GUI.enabled;
GUI.enabled = true;
EditorGUIUtility.labelWidth = 30f;
EditorGUI.LabelField(new Rect(rect.x + 5f, rect.y, 65f, 18), new GUIContent("ID:"), new GUIContent(prop_id.intValue.ToString()));
GUI.enabled = isEnabled;
EditorGUI.BeginChangeCheck();
EditorGUIUtility.labelWidth = 55f;
GUI.SetNextControlName("Unicode Input");
string unicode = EditorGUI.TextField(new Rect(rect.x + 75f, rect.y, 105, 18), "Unicode:", prop_unicode.intValue.ToString("X"));
if (GUI.GetNameOfFocusedControl() == "Unicode Input")
{
//Filter out unwanted characters.
char chr = Event.current.character;
if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F'))
{
Event.current.character = '\0';
}
if (EditorGUI.EndChangeCheck())
{
prop_unicode.intValue = TMP_TextUtilities.StringToInt(unicode);
property.serializedObject.ApplyModifiedProperties();
TMP_Spritereplacedet spritereplacedet = property.serializedObject.targetObject as TMP_Spritereplacedet;
spritereplacedet.UpdateLookupTables();
}
}
EditorGUIUtility.labelWidth = 45f;
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(new Rect(rect.x + 185f, rect.y, rect.width - 260, 18), prop_name, new GUIContent("Name: " + prop_name.stringValue));
if (EditorGUI.EndChangeCheck())
{
Sprite sprite = prop_sprite.objectReferenceValue as Sprite;
if (sprite != null)
sprite.name = prop_name.stringValue;
// Recompute hashCode for new name
prop_hashCode.intValue = TMP_TextUtilities.GetSimpleHashCode(prop_name.stringValue);
// Check to make sure for duplicates
property.serializedObject.ApplyModifiedProperties();
// Dictionary needs to be updated since HashCode has changed.
//TMP_StyleSheet.Instance.LoadStyleDictionary();
}
EditorGUIUtility.labelWidth = 30f;
EditorGUIUtility.fieldWidth = 10f;
//GUI.enabled = false;
float width = (rect.width - 75f) / 4;
EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 0, rect.y + 22, width - 5f, 18), prop_x, new GUIContent("X:"));
EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 1, rect.y + 22, width - 5f, 18), prop_y, new GUIContent("Y:"));
EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 2, rect.y + 22, width - 5f, 18), prop_width, new GUIContent("W:"));
EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 3, rect.y + 22, width - 5f, 18), prop_height, new GUIContent("H:"));
//GUI.enabled = true;
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 0, rect.y + 44, width - 5f, 18), prop_xOffset, new GUIContent("OX:"));
EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 1, rect.y + 44, width - 5f, 18), prop_yOffset, new GUIContent("OY:"));
EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 2, rect.y + 44, width - 5f, 18), prop_xAdvance, new GUIContent("Adv."));
EditorGUI.PropertyField(new Rect(rect.x + 5f + width * 3, rect.y + 44, width - 5f, 18), prop_scale, new GUIContent("SF."));
if (EditorGUI.EndChangeCheck())
{
//Sprite sprite = prop_sprite.objectReferenceValue as Sprite;
//sprite = Sprite.Create(sprite.texture, sprite.rect, new Vector2(0.1f, 0.8f));
//prop_sprite.objectReferenceValue = sprite;
//Debug.Log(sprite.bounds);
}
}
19
Source : TMP_SpriteCharacterPropertyDrawer.cs
with MIT License
from BattleDawnNZ
with MIT License
from BattleDawnNZ
void DrawSpriteGlyph(Rect position, SerializedProperty property)
{
// Get a reference to the sprite glyph table
TMP_Spritereplacedet spritereplacedet = property.serializedObject.targetObject as TMP_Spritereplacedet;
if (spritereplacedet == null)
return;
int glyphIndex = property.FindPropertyRelative("m_GlyphIndex").intValue;
// Lookup glyph and draw glyph (if available)
int elementIndex = spritereplacedet.spriteGlyphTable.FindIndex(item => item.index == glyphIndex);
if (elementIndex != -1)
{
// Get a reference to the Sprite Glyph Table
SerializedProperty prop_SpriteGlyphTable = property.serializedObject.FindProperty("m_SpriteGlyphTable");
SerializedProperty prop_SpriteGlyph = prop_SpriteGlyphTable.GetArrayElementAtIndex(elementIndex);
SerializedProperty prop_GlyphRect = prop_SpriteGlyph.FindPropertyRelative("m_GlyphRect");
// Get a reference to the sprite texture
Texture tex = spritereplacedet.spriteSheet;
// Return if we don't have a texture replacedigned to the sprite replacedet.
if (tex == null)
{
Debug.LogWarning("Please replacedign a valid Sprite Atlas texture to the [" + spritereplacedet.name + "] Sprite replacedet.", spritereplacedet);
return;
}
Vector2 spriteTexPosition = new Vector2(position.x, position.y);
Vector2 spriteSize = new Vector2(48, 48);
Vector2 alignmentOffset = new Vector2((58 - spriteSize.x) / 2, (58 - spriteSize.y) / 2);
float x = prop_GlyphRect.FindPropertyRelative("m_X").intValue;
float y = prop_GlyphRect.FindPropertyRelative("m_Y").intValue;
float spriteWidth = prop_GlyphRect.FindPropertyRelative("m_Width").intValue;
float spriteHeight = prop_GlyphRect.FindPropertyRelative("m_Height").intValue;
if (spriteWidth >= spriteHeight)
{
spriteSize.y = spriteHeight * spriteSize.x / spriteWidth;
spriteTexPosition.y += (spriteSize.x - spriteSize.y) / 2;
}
else
{
spriteSize.x = spriteWidth * spriteSize.y / spriteHeight;
spriteTexPosition.x += (spriteSize.y - spriteSize.x) / 2;
}
// Compute the normalized texture coordinates
Rect texCoords = new Rect(x / tex.width, y / tex.height, spriteWidth / tex.width, spriteHeight / tex.height);
GUI.DrawTextureWithTexCoords(new Rect(spriteTexPosition.x + alignmentOffset.x, spriteTexPosition.y + alignmentOffset.y, spriteSize.x, spriteSize.y), tex, texCoords, true);
}
}
19
Source : TMP_SpriteGlyphPropertyDrawer.cs
with MIT License
from BattleDawnNZ
with MIT License
from BattleDawnNZ
void DrawGlyph(Rect position, SerializedProperty property)
{
// Get a reference to the sprite texture
Texture tex = (property.serializedObject.targetObject as TMP_Spritereplacedet).spriteSheet;
// Return if we don't have a texture replacedigned to the sprite replacedet.
if (tex == null)
{
Debug.LogWarning("Please replacedign a valid Sprite Atlas texture to the [" + property.serializedObject.targetObject.name + "] Sprite replacedet.", property.serializedObject.targetObject);
return;
}
Vector2 spriteTexPosition = new Vector2(position.x, position.y);
Vector2 spriteSize = new Vector2(65, 65);
SerializedProperty prop_GlyphRect = property.FindPropertyRelative("m_GlyphRect");
int spriteImageX = prop_GlyphRect.FindPropertyRelative("m_X").intValue;
int spriteImageY = prop_GlyphRect.FindPropertyRelative("m_Y").intValue;
int spriteImageWidth = prop_GlyphRect.FindPropertyRelative("m_Width").intValue;
int spriteImageHeight = prop_GlyphRect.FindPropertyRelative("m_Height").intValue;
if (spriteImageWidth >= spriteImageHeight)
{
spriteSize.y = spriteImageHeight * spriteSize.x / spriteImageWidth;
spriteTexPosition.y += (spriteSize.x - spriteSize.y) / 2;
}
else
{
spriteSize.x = spriteImageWidth * spriteSize.y / spriteImageHeight;
spriteTexPosition.x += (spriteSize.y - spriteSize.x) / 2;
}
// Compute the normalized texture coordinates
Rect texCoords = new Rect((float)spriteImageX / tex.width, (float)spriteImageY / tex.height, (float)spriteImageWidth / tex.width, (float)spriteImageHeight / tex.height);
GUI.DrawTextureWithTexCoords(new Rect(spriteTexPosition.x + 5, spriteTexPosition.y + 32f, spriteSize.x, spriteSize.y), tex, texCoords, true);
}
19
Source : SteamVR_LoadLevel.cs
with GNU General Public License v3.0
from brandonmousseau
with GNU General Public License v3.0
from brandonmousseau
void OnGUI()
{
if (_active != this)
return;
// Optionally create an overlay for our progress bar to use, separate from the loading screen.
if (progressBarEmpty != null && progressBarFull != null)
{
if (progressBarOverlayHandle == OpenVR.k_ulOverlayHandleInvalid)
progressBarOverlayHandle = GetOverlayHandle("progressBar", progressBarTransform != null ? progressBarTransform : transform, progressBarWidthInMeters);
if (progressBarOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
{
var progress = (async != null) ? async.progress : 0.0f;
// Use the full bar size for everything.
var w = progressBarFull.width;
var h = progressBarFull.height;
// Create a separate render texture so we can composite the full image on top of the empty one.
if (renderTexture == null)
{
renderTexture = new RenderTexture(w, h, 0);
renderTexture.Create();
}
var prevActive = RenderTexture.active;
RenderTexture.active = renderTexture;
if (Event.current.type == EventType.Repaint)
GL.Clear(false, true, Color.clear);
GUILayout.BeginArea(new Rect(0, 0, w, h));
GUI.DrawTexture(new Rect(0, 0, w, h), progressBarEmpty);
// Reveal the full bar texture based on progress.
GUI.DrawTextureWithTexCoords(new Rect(0, 0, progress * w, h), progressBarFull, new Rect(0.0f, 0.0f, progress, 1.0f));
GUILayout.EndArea();
RenderTexture.active = prevActive;
// Texture needs to be set every frame after it is updated since SteamVR makes a copy internally to a shared texture.
var overlay = OpenVR.Overlay;
if (overlay != null)
{
var texture = new Texture_t();
texture.handle = renderTexture.GetNativeTexturePtr();
texture.eType = SteamVR.instance.textureType;
texture.eColorSpace = EColorSpace.Auto;
overlay.SetOverlayTexture(progressBarOverlayHandle, ref texture);
}
}
}
#if false
// Draw loading screen and progress bar to 2d companion window as well.
if (loadingScreen != null)
{
var screenAspect = (float)Screen.width / Screen.height;
var textureAspect = (float)loadingScreen.width / loadingScreen.height;
float w, h;
if (screenAspect < textureAspect)
{
// Clamp horizontally
w = Screen.width * 0.9f;
h = w / textureAspect;
}
else
{
// Clamp vertically
h = Screen.height * 0.9f;
w = h * textureAspect;
}
GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
var x = Screen.width / 2 - w / 2;
var y = Screen.height / 2 - h / 2;
GUI.DrawTexture(new Rect(x, y, w, h), loadingScreen);
GUILayout.EndArea();
}
if (renderTexture != null)
{
var x = Screen.width / 2 - renderTexture.width / 2;
var y = Screen.height * 0.9f - renderTexture.height;
GUI.DrawTexture(new Rect(x, y, renderTexture.width, renderTexture.height), renderTexture);
}
#endif
}
19
Source : TextureEditorWindow.cs
with MIT License
from Crazy-Marvin
with MIT License
from Crazy-Marvin
protected void DrawTexture()
{
int num = Mathf.Max(this.m_Texture.width, 1);
float num2 = Mathf.Min(this.m_MipLevel, (float)(m_Texture.mipmapCount - 1));
//float mipMapBias = this.m_Texture.mipMapBias;
m_Texture.mipMapBias = (num2 - this.Log2((float)num / this.m_TextureRect.width));
//FilterMode filterMode = this.m_Texture.filterMode;
//m_Texture.filterMode = FilterMode.Point;
Rect r = m_TextureRect;
r.position -= m_ScrollPosition;
if (this.m_ShowAlpha)
{
EditorGUI.DrawTextureAlpha(r, this.m_Texture);
}
else
{
GUI.DrawTextureWithTexCoords(r, transparentCheckerTexture,
new Rect(r.width * -0.5f / (float)transparentCheckerTexture.width,
r.height * -0.5f / (float)transparentCheckerTexture.height,
r.width / (float)transparentCheckerTexture.width,
r.height / (float)transparentCheckerTexture.height), false);
GUI.color = textureColor;
GUI.DrawTexture(r, this.m_Texture);
}
//m_Texture.filterMode = filterMode;
//m_Texture.mipMapBias = mipMapBias;
}
19
Source : PixelKit.cs
with MIT License
from liangxiegame
with MIT License
from liangxiegame
void OnGUI ()
{
this.wantsMouseMove = true;
if (waitingFile) return; // we are waiting for save
if (needsUpdate) {Repaint(); needsUpdate=false;} // we need to update
if (!isInitialized) InitializeCanvas();
// ** GUI **
GUIToolbar();
if (toolbarMode==6)
{
GUISettingsTab();
return;
}
GUILayout.Space(19);
GUICurrentImageInfo();
// background canvas
GUI.DrawTextureWithTexCoords(new Rect(leftOffsetX,topOffsetY,imageSize*pixelSizeAdjust,imageSize*pixelSizeAdjust), canvasBackground, new Rect(0f,0f,1f,1f),true);
// drawing canvas
GUI.DrawTextureWithTexCoords(new Rect(leftOffsetX,topOffsetY,imageSize*pixelSizeAdjust,imageSize*pixelSizeAdjust), canvas, new Rect(0f,0f,1f,1f),true);
// outline canvas
if (automaticOutline)
{
GUI.DrawTextureWithTexCoords(new Rect(leftOffsetX,topOffsetY,imageSize*pixelSizeAdjust,imageSize*pixelSizeAdjust), canvasOutlineBG, new Rect(0f,0f,1f,1f),true);
}
// parts of the GUI
GUIMouseInfo();
GUIDrawPreviews();
GUICurrentColors();
GUILayout.BeginHorizontal();
GUILayout.BeginVertical();
//GUIUndoRedo(); // not working properly yet
//GUILayout.Space(8);
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.BeginVertical(GUILayout.Width(leftOffsetX-4));
GUILayout.Space(0); // dummy
GUILayout.EndVertical();
GUILayout.BeginVertical();
GUILoadBuffer();
GUILayout.EndVertical();
GUIPalette();
GUILayout.EndHorizontal();
GUILayout.BeginArea(new Rect(527,585,182,73));
GUIAutomaticOutlines();
GUIMirrorToggles();
GUIMovePanTools();
GUILayout.EndArea();
GUIInfoAndStatus();
GUIEvents();
}
19
Source : PixelKit.cs
with MIT License
from liangxiegame
with MIT License
from liangxiegame
void GUIDrawPreviews()
{
// preview 1
GUI.DrawTextureWithTexCoords(new Rect(imageSize*pixelSizeAdjust+24+leftOffsetX,topOffsetY+64,imageSize,imageSize), canvas, new Rect(0f,0f,1f,1f),true);
// preview 2 (black bg)
GUI.DrawTextureWithTexCoords(new Rect(imageSize*pixelSizeAdjust+24+leftOffsetX,topOffsetY+64+48,imageSize,imageSize), blackPixel, new Rect(0f,0f,1f,1f),true);
GUI.DrawTextureWithTexCoords(new Rect(imageSize*pixelSizeAdjust+24+leftOffsetX,topOffsetY+64+48,imageSize,imageSize), canvas, new Rect(0f,0f,1f,1f),true);
// preview 3 (white bg)
GUI.DrawTextureWithTexCoords(new Rect(imageSize*pixelSizeAdjust+24+leftOffsetX,topOffsetY+64+48+48,imageSize,imageSize), whitePixel, new Rect(0f,0f,1f,1f),true);
GUI.DrawTextureWithTexCoords(new Rect(imageSize*pixelSizeAdjust+24+leftOffsetX,topOffsetY+64+48+48,imageSize,imageSize), canvas, new Rect(0f,0f,1f,1f),true);
// TODO: preview 4 (main camera bg color), take main cam bg color, create temp texture at init, adjust color if it changes..show here as bg
//GUI.DrawTextureWithTexCoords(new Rect(size*zoom+24+leftOffsetX,topOffsetY + (size+16)*4,size,size), whitePixel, new Rect(0f,0f,1f,1f),true);
//GUI.DrawTextureWithTexCoords(new Rect(size*zoom+24+leftOffsetX,topOffsetY + (size+16)*4,size,size), canvas, new Rect(0f,0f,1f,1f),true);
}
19
Source : PixelKit.cs
with MIT License
from liangxiegame
with MIT License
from liangxiegame
void GUIEvents()
{
Event current = Event.current;
bool altDown=false;
// bool ctrlDown=false;
// bool shiftDown=false;
if (Event.current.alt) altDown = true;
//if (Event.current.shift) shiftDown = true;
//if (Event.current.control) ctrlDown = true;
if (current.type == EventType.ScrollWheel)
{
if (altDown) // adjust alpha only
{
paintColor1.a -= Mathf.Sign(current.delta.y)*mouseWheelSpeed;
paintColor1.a = Mathf.Clamp01(paintColor1.a);
}else{ // darken/lighten color
paintColor1.r -= Mathf.Sign(current.delta.y)*mouseWheelSpeed;
paintColor1.g -= Mathf.Sign(current.delta.y)*mouseWheelSpeed;
paintColor1.b -= Mathf.Sign(current.delta.y)*mouseWheelSpeed;
paintColor1.r = Mathf.Clamp01(paintColor1.r);
paintColor1.g = Mathf.Clamp01(paintColor1.g);
paintColor1.b = Mathf.Clamp01(paintColor1.b);
CurrentCellOutlineRebuild();
}
HandleUtility.Repaint();
}
if (current.type == EventType.KeyDown)
{
switch(current.keyCode)
{
case KeyCode.X: // x key, swap colors
Color tempColor = paintColor1;
paintColor1 = paintColor2;
paintColor2 = tempColor;
current.Use();
CurrentCellOutlineRebuild();
break;
case KeyCode.D: // d key, restore default colors
paintColor1 = Color.black;
paintColor2 = Color.white;
current.Use();
CurrentCellOutlineRebuild();
break;
case KeyCode.I: // i key, invert color1
paintColor1.r = 1-paintColor1.r;
paintColor1.g = 1-paintColor1.g;
paintColor1.b = 1-paintColor1.b;
current.Use();
CurrentCellOutlineRebuild();
break;
case KeyCode.B: // b key, brush
toolbarMode=defaultToolBarMode;
current.Use();
break;
case KeyCode.F: // f key, fill
toolbarMode=2;
current.Use();
break;
case KeyCode.Alpha1: // 1 = quick color slot 1
paintColor1 = quickColor1;
current.Use();
CurrentCellOutlineRebuild();
break;
case KeyCode.Alpha2: // 2 = quick color slot 2
paintColor1 = quickColor2;
current.Use();
CurrentCellOutlineRebuild();
break;
case KeyCode.Alpha3: // 3 = quick color slot 3
paintColor1 = quickColor3;
current.Use();
CurrentCellOutlineRebuild();
break;
}
} // keypress
// repaint after undo
if (Event.current.type == EventType.ValidateCommand)
{
switch (Event.current.commandName)
{
case "UndoRedoPerformed":
HandleUtility.Repaint();
break;
}
}
current = Event.current;
// mouse buttons
if (current.type == EventType.MouseDrag || current.type == EventType.MouseDown)
{
int x = (int) (current.mousePosition.x-leftOffsetX);
int y = (int) (current.mousePosition.y-topOffsetY);
int px = (int) (x/pixelSizeAdjust);
int py = (int) ((imageSize*pixelSizeAdjust-y)/pixelSizeAdjust);
// check canvas bounds
if (x>=0 && x < imageSize*pixelSizeAdjust && y>=0 && y < imageSize*pixelSizeAdjust)
{
if (toolbarMode==1) // Brush
{
switch (current.button)
{
case 0: // left mouse button (paint)
Undo.RecordObject(canvas, "Paint " + px +","+py);
canvas.SetPixel(px,py,paintColor1);
if (mirrorX)
{
canvas.SetPixel(imageSize-mirrorXOffset-px,py,paintColor1);
}
if (mirrorY)
{
canvas.SetPixel(px,imageSize-py,paintColor1);
}
if (mirrorX && mirrorY)
{
canvas.SetPixel(imageSize-mirrorXOffset-px,imageSize-1-py,paintColor1);
}
break;
case 2: // middle mouse button (color pick)
paintColor1 = canvas.GetPixel(px,py);
break;
case 1: // right mouse button (clear)
Undo.RecordObject(canvas, "Erase " + px +","+py);
if (altDown) // smart erase
{
if (Compare4Neighbours(px,py))
{
Color32 smartEraseColor = canvas.GetPixel(px,py+1);
canvas.SetPixel(px,py,smartEraseColor);
if (mirrorX)
{
canvas.SetPixel(imageSize-mirrorXOffset-px,py,smartEraseColor);
}
if (mirrorY)
{
canvas.SetPixel(px,imageSize-mirrorXOffset-py,smartEraseColor);
}
if (mirrorX && mirrorY)
{
canvas.SetPixel(imageSize-mirrorXOffset-px,imageSize-1-py,smartEraseColor);
}
}else{ // use average instead
Color32 smartEraseColor = GetAverageNeighbourColor4(px,py);
canvas.SetPixel(px,py,smartEraseColor);
if (mirrorX)
{
canvas.SetPixel(imageSize-mirrorXOffset-px,py,smartEraseColor);
}
if (mirrorY)
{
canvas.SetPixel(px,imageSize-mirrorXOffset-py,smartEraseColor);
}
if (mirrorX && mirrorY)
{
canvas.SetPixel(imageSize-mirrorXOffset-px,imageSize-1-py,smartEraseColor);
}
}
}else{
canvas.SetPixel(px,py,clearColor);
if (mirrorX)
{
canvas.SetPixel(imageSize-mirrorXOffset-px,py,clearColor);
}
if (mirrorY)
{
canvas.SetPixel(px,imageSize-1-py,clearColor);
}
if (mirrorX && mirrorY)
{
canvas.SetPixel(imageSize-mirrorXOffset-px,imageSize-1-py,clearColor);
}
}
break;
}
}
if (toolbarMode==2) // floodfill
{
switch (current.button)
{
case 0: // left mouse button
Undo.RecordObject(canvas, "Floodfill " + px +","+py);
floodFill(px,py,canvas.GetPixel(px,py),paintColor1);
break;
case 2: // middle mouse button
paintColor1 = canvas.GetPixel(px,py);
break;
case 1: // right mouse button erase
Undo.RecordObject(canvas, "Erase " + px +","+py);
canvas.SetPixel(px,py,paintColor2);
break;
}
}
canvas.Apply(false);
if (!wasModified) {}
{
if (!window) window = (PixelKit)EditorWindow.GetWindow (typeof (PixelKit));
window.replacedleContent = new GUIContent(appName+"*");
wasModified = true;
}
if (automaticOutline) DrawOutline();
HandleUtility.Repaint();
}
}
// show mouse cursor pixel preview
if (mouseCursorPixel)
{
int x = (int)current.mousePosition.x-leftOffsetX;
int y = (int)current.mousePosition.y-topOffsetY;
int y2 = (int)current.mousePosition.y;
if (x>=0 && x < imageSize*pixelSizeAdjust && y>=0 && y < imageSize*pixelSizeAdjust)
{
// get pixel coords
mouseX = x/pixelSizeAdjust;
mouseY = (imageSize*pixelSizeAdjust-y)/pixelSizeAdjust;
if (x!=mouseCursorPixelPosX || y!=mouseCursorPixelPosY || paintColor1.ToString()!=oldpaintColor1.ToString())
{
HandleUtility.Repaint();
}
mouseCursorPixelPosX = x;
mouseCursorPixelPosY = y;
oldpaintColor1 = paintColor1;
int gridX = (x)/pixelSizeAdjust*pixelSizeAdjust+leftOffsetX;
int gridY = (y2/pixelSizeAdjust)*pixelSizeAdjust;
GUI.DrawTextureWithTexCoords(new Rect(gridX-1,gridY-1,pixelSizeAdjust+2,pixelSizeAdjust+2), gridCellOutLine, new Rect(0f,0f,1f,1f),true);
}else{
// TODO: repaint only once..?
HandleUtility.Repaint();
}
}
}
19
Source : OldGUIExamplesCS.cs
with MIT License
from PacktPublishing
with MIT License
from PacktPublishing
void OnGUI () {
GUI.DrawTexture( grumpyRect.rect, grumpy);
Rect staticRect = new Rect(0.0f*w, 0.0f*h, 0.2f*w, 0.14f*h);
if(GUI.Button( staticRect, "Move Cat")){
if(LeanTween.isTweening(grumpyRect)==false){ // Check to see if the cat is already tweening, so it doesn't freak out
Vector2 orig = new Vector2( grumpyRect.rect.x, grumpyRect.rect.y );
LeanTween.move( grumpyRect, new Vector2( 1.0f*Screen.width - grumpy.width, 0.0f*Screen.height ), 1.0f).setEase(LeanTweenType.easeOutBounce).setOnComplete(catMoved);
LeanTween.move( grumpyRect, orig, 1.0f ).setDelay(1.0f).setEase( LeanTweenType.easeOutBounce);
}
}
if(GUI.Button(buttonRect1.rect, "Scale Centered")){
LeanTween.scale( buttonRect1, new Vector2(buttonRect1.rect.width, buttonRect1.rect.height) * 1.2f, 0.25f ).setEase( LeanTweenType.easeOutQuad );
LeanTween.move( buttonRect1, new Vector2(buttonRect1.rect.x-buttonRect1.rect.width*0.1f, buttonRect1.rect.y-buttonRect1.rect.height*0.1f), 0.25f ).setEase(LeanTweenType.easeOutQuad);
}
if(GUI.Button(buttonRect2.rect, "Scale")){
LeanTween.scale( buttonRect2, new Vector2(buttonRect2.rect.width, buttonRect2.rect.height) * 1.2f, 0.25f ).setEase(LeanTweenType.easeOutBounce);
}
staticRect = new Rect(0.76f*w, 0.53f*h, 0.2f*w, 0.14f*h);
if(GUI.Button( staticRect, "Flip Tile")){
LeanTween.move( beautyTileRect, new Vector2( 0f, beautyTileRect.rect.y + 1.0f ), 1.0f ).setEase(LeanTweenType.easeOutBounce);
}
GUI.DrawTextureWithTexCoords( new Rect(0.8f*w, 0.5f*h - beauty.height*0.5f, beauty.width*0.5f, beauty.height*0.5f), beauty, beautyTileRect.rect);
if(GUI.Button(buttonRect3.rect, "Alpha")){
LeanTween.alpha( buttonRect3, 0.0f, 1.0f).setEase(LeanTweenType.easeOutQuad);
LeanTween.alpha( buttonRect3, 1.0f, 1.0f).setDelay(1.0f).setEase( LeanTweenType.easeInQuad);
LeanTween.alpha( grumpyRect, 0.0f, 1.0f).setEase(LeanTweenType.easeOutQuad);
LeanTween.alpha( grumpyRect, 1.0f, 1.0f).setDelay(1.0f).setEase(LeanTweenType.easeInQuad);
}
GUI.color = new Color(1.0f,1.0f,1.0f,1.0f); // Reset to normal alpha, otherwise other gui elements will be effected
if(GUI.Button(buttonRect4.rect, "Rotate")){
LeanTween.rotate( buttonRect4, 150.0f, 1.0f ).setEase(LeanTweenType.easeOutElastic);
LeanTween.rotate( buttonRect4, 0.0f, 1.0f ).setDelay(1.0f).setEase(LeanTweenType.easeOutElastic);
}
GUI.matrix = Matrix4x4.idenreplacedy;
}
19
Source : NodeEditor.cs
with MIT License
from virror
with MIT License
from virror
private static void DrawSubCanvas (NodeCanvas nodeCanvas, NodeEditorState editorState)
{
if (!editorState.drawing)
return;
BeginEditingCanvas (nodeCanvas, editorState);
if (Event.current.type == EventType.Repaint)
{ // Draw Background when Repainting
// Offset from origin in tile units
Vector2 tileOffset = new Vector2 (-(curEditorState.zoomPos.x * curEditorState.zoom + curEditorState.panOffset.x) / NodeEditorGUI.Background.width,
((curEditorState.zoomPos.y - curEditorState.canvasRect.height) * curEditorState.zoom + curEditorState.panOffset.y) / NodeEditorGUI.Background.height);
// Amount of tiles
Vector2 tileAmount = new Vector2 (Mathf.Round (curEditorState.canvasRect.width * curEditorState.zoom) / NodeEditorGUI.Background.width,
Mathf.Round (curEditorState.canvasRect.height * curEditorState.zoom) / NodeEditorGUI.Background.height);
// Draw tiled background
GUI.DrawTextureWithTexCoords (curEditorState.canvasRect, NodeEditorGUI.Background, new Rect (tileOffset, tileAmount));
}
// Handle input events
NodeEditorInputSystem.HandleInputEvents (curEditorState);
if (Event.current.type != EventType.Layout)
curEditorState.ignoreInput = new List<Rect> ();
// We're using a custom scale method, as default one is messing up clipping rect
Rect canvasRect = curEditorState.canvasRect;
curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale (ref canvasRect, curEditorState.zoomPos, curEditorState.zoom, NodeEditorGUI.isEditorWindow, false);
// ---- BEGIN SCALE ----
// Some features which require zoomed drawing:
if (curEditorState.navigate)
{ // Draw a curve to the origin/active node for orientation purposes
Vector2 startPos = (curEditorState.selectedNode != null? curEditorState.selectedNode.rect.center : curEditorState.panOffset) + curEditorState.zoomPanAdjust;
Vector2 endPos = Event.current.mousePosition;
RTEditorGUI.DrawLine (startPos, endPos, Color.green, null, 3);
RepaintClients ();
}
if (curEditorState.connectOutput != null)
{ // Draw the currently drawn connection
NodeOutput output = curEditorState.connectOutput;
Vector2 startPos = output.GetGUIKnob ().center;
Vector2 startDir = output.GetDirection ();
Vector2 endPos = Event.current.mousePosition;
Vector2 endDir = -startDir; // NodeEditorGUI.GetSecondConnectionVector (startPos, endPos, startDir); <- causes unpleasant jumping when switching polarity
NodeEditorGUI.OptimiseBezierDirections (startPos, ref startDir, endPos, ref endDir);
NodeEditorGUI.DrawConnection (startPos, startDir, endPos, endDir, output.typeData.Color);
RepaintClients ();
}
// Draw the groups below everything else
for (int groupCnt = 0; groupCnt < curNodeCanvas.groups.Count; groupCnt++)
curNodeCanvas.groups [groupCnt].DrawGroup ();
// Push the active node to the top of the draw order.
if (Event.current.type == EventType.Layout && curEditorState.selectedNode != null)
{
curNodeCanvas.nodes.Remove (curEditorState.selectedNode);
curNodeCanvas.nodes.Add (curEditorState.selectedNode);
}
// Draw the transitions and connections. Has to be drawn before nodes as transitions originate from node centers
for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
curNodeCanvas.nodes [nodeCnt].DrawConnections ();
// Draw the nodes
for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
{
Node node = curNodeCanvas.nodes [nodeCnt];
node.DrawNode ();
if (Event.current.type == EventType.Repaint)
node.DrawKnobs ();
}
// ---- END SCALE ----
// End scaling group
GUIScaleUtility.EndScale ();
// Handle input events with less priority than node GUI controls
NodeEditorInputSystem.HandleLateInputEvents (curEditorState);
EndEditingCanvas ();
}
19
Source : SFN_Get.cs
with MIT License
from XINCGer
with MIT License
from XINCGer
public override void DrawLowerPropertyBox() {
Rect r = new Rect( lowerRect );
r.yMin += 4;
r.yMax -= 2;
r.xMin += 2;
Rect[] splitRects = r.SplitHorizontal( 0.25f, 2 );
int selectedID = -1;
if( connectors[1].inputCon != null){
selectedID = editor.nodeView.NodeIdToRelayId( connectors[1].inputCon.node.id );
}
EditorGUI.BeginChangeCheck();
int newID = UndoableEnumPopupNamed( splitRects[1], selectedID, editor.nodeView.relayInNames, "select Get option" );
if( EditorGUI.EndChangeCheck() ) {
// Changed input, let's hook it up!
SF_NodeConnector con = editor.nodeView.relayInSources[newID].con;
connectors[1].LinkTo( con );
}
Rect texCoords = new Rect( splitRects[0] );
texCoords.width /= 7;
texCoords.height /= 3;
texCoords.x = texCoords.y = 0;
GUI.DrawTextureWithTexCoords( splitRects[0], SF_GUI.Handle_drag, texCoords, alphaBlend:true );
}
19
Source : SFN_MultiplyMatrix.cs
with MIT License
from XINCGer
with MIT License
from XINCGer
public override void NeatWindow() {
PrepareWindowColor();
GUI.BeginGroup( rect );
Rect r = new Rect( rectInner );
r = r.Pad( 4 );
Rect texCoords = new Rect( r );
texCoords.width /= 7;
texCoords.height /= 3;
texCoords.x = texCoords.y = 0;
GUI.DrawTextureWithTexCoords( r, SF_GUI.Handle_drag, texCoords, alphaBlend: true );
GUI.EndGroup();
ResetWindowColor();
}
19
Source : SFN_Relay.cs
with MIT License
from XINCGer
with MIT License
from XINCGer
public override void DrawLowerPropertyBox() {
Rect r = new Rect( lowerRect );
r.yMin += 4;
r.yMax -= 2;
r.xMin += 2;
Rect texCoords = new Rect( r );
texCoords.width /= 7;
texCoords.height /= 3;
texCoords.x = texCoords.y = 0;
GUI.DrawTextureWithTexCoords( r, SF_GUI.Handle_drag, texCoords, alphaBlend:true );
}
19
Source : SFN_Set.cs
with MIT License
from XINCGer
with MIT License
from XINCGer
public override void DrawLowerPropertyBox() {
Rect r = new Rect( lowerRect );
r.yMin += 4;
r.yMax -= 2;
r.xMin += 2;
Rect[] splitRects = r.SplitHorizontal( 0.75f, 2 );
EditorGUI.BeginChangeCheck();
variableName = UndoableTextField( splitRects[0], variableName, "Set variable name", null );
if( EditorGUI.EndChangeCheck() ) {
editor.nodeView.RefreshRelaySources();
}
Rect texCoords = new Rect( splitRects[1] );
texCoords.width /= 7;
texCoords.height /= 3;
texCoords.x = texCoords.y = 0;
GUI.DrawTextureWithTexCoords( splitRects[1], SF_GUI.Handle_drag, texCoords, alphaBlend: true );
}
19
Source : SFN_ToggleProperty.cs
with MIT License
from XINCGer
with MIT License
from XINCGer
public override void DrawLowerPropertyBox() {
PrepareWindowColor();
float vecPrev = texture.dataUniform[0];
//int strWidth = (int)SF_Styles.GetLargeTextField().CalcSize( new GUIContent( texture.dataUniform[0].ToString() ) ).x;
//lowerRect.width = Mathf.Max( 32, strWidth );
Rect r = new Rect( lowerRect );
r.width -= 75;
r.width *= 2;
r.yMin += 4;
r.yMax -= 2;
r.xMin += 2;
float fVal = texture.dataUniform[0];;
//GUI.enabled = false;
//fVal = EditorGUI.FloatField(r, texture.dataUniform[0], SF_Styles.LargeTextField);
//GUI.enabled = true;
//r.x += r.width + 6;
bool prevVal = on;
GUI.enabled = false;
r = r.PadTop(2);
GUI.Label(r,prevVal ? "1": "0", SF_Styles.LargeTextFieldNoFrame);
r = r.PadTop(-2);
GUI.enabled = true;
r.x += 18;
r.width = r.height + 2;
bool newVal = GUI.Button(r,string.Empty) ? !prevVal : prevVal;
if(newVal){
Rect chkRect = r;
chkRect.width = SF_GUI.Toggle_check_icon.width;
chkRect.height = SF_GUI.Toggle_check_icon.height;
chkRect.x += (r.width-chkRect.width)*0.5f;
chkRect.y += 2;
GUI.DrawTexture(chkRect,SF_GUI.Toggle_check_icon);
}
if(prevVal != newVal){
UndoRecord("set toggle of " + property.nameDisplay + " to " + newVal.ToString());
fVal = newVal ? 1f : 0f;
connectors[0].label = "";
//Debug.Log("Setting it to " + newVal.ToString());
}
r.x += r.width + 6;
r.width = r.height + 18;
Rect texCoords = new Rect( r );
texCoords.width /= 7;
texCoords.height /= 3;
texCoords.x = texCoords.y = 0;
GUI.DrawTextureWithTexCoords( r, SF_GUI.Handle_drag, texCoords, alphaBlend:true );
on = newVal;
texture.dataUniform = new Color( fVal, fVal, fVal, fVal );
if( texture.dataUniform[0] != vecPrev ) {
OnUpdateNode( NodeUpdateType.Soft );
editor.shaderEvaluator.ApplyProperty( this );
}
ResetWindowColor();
}
19
Source : SFN_ValueProperty.cs
with MIT License
from XINCGer
with MIT License
from XINCGer
public override void DrawLowerPropertyBox() {
PrepareWindowColor();
float vecPrev = texture.dataUniform[0];
//int strWidth = (int)SF_Styles.GetLargeTextField().CalcSize( new GUIContent( texture.dataUniform[0].ToString() ) ).x;
//lowerRect.width = Mathf.Max( 32, strWidth );
Rect r = new Rect( lowerRect );
r.width -= 32;
r.yMin += 4;
r.yMax -= 2;
r.xMin += 2;
float fVal;
if(IsGlobalProperty()){
fVal = 1f;
GUI.enabled = false;
EditorGUI.FloatField( r, 1, SF_Styles.LargeTextField );
GUI.enabled = true;
} else {
fVal = UndoableFloatField(r, texture.dataUniform[0], "value" , SF_Styles.LargeTextField);
//fVal = EditorGUI.FloatField( r, texture.dataUniform[0], SF_Styles.LargeTextField );
}
r.x += r.width + 6;
r.width = r.height;
Rect texCoords = new Rect( r );
texCoords.width /= 7;
texCoords.height /= 3;
texCoords.x = texCoords.y = 0;
GUI.DrawTextureWithTexCoords( r, SF_GUI.Handle_drag, texCoords, alphaBlend:true );
texture.dataUniform = new Vector4( fVal, fVal, fVal, fVal );
if( texture.dataUniform[0] != vecPrev ) {
OnUpdateNode( NodeUpdateType.Soft );
editor.shaderEvaluator.ApplyProperty( this );
}
ResetWindowColor();
}
19
Source : SFN_Vector1.cs
with MIT License
from XINCGer
with MIT License
from XINCGer
public override void DrawLowerPropertyBox() {
float vecPrev = texture.dataUniform[0];
//int strWidth = (int)SF_Styles.GetLargeTextField().CalcSize( new GUIContent( texture.dataUniform[0].ToString() ) ).x;
//lowerRect.width = Mathf.Max( 32, strWidth );
Rect r = new Rect( lowerRect );
r.width -= 32;
r.yMin += 4;
r.yMax -= 2;
r.xMin += 2;
//SF_GUI.EnterableFloatField( this, r, ref texture.dataUniform.r, SF_Styles.LargeTextField );
UndoableEnterableFloatField(r, ref texture.dataUniform.x, "value", SF_Styles.LargeTextField);
r.x += r.width + 6;
r.width = r.height;
Rect texCoords = new Rect( r );
texCoords.width /= 7;
texCoords.height /= 3;
texCoords.x = texCoords.y = 0;
GUI.DrawTextureWithTexCoords( r, SF_GUI.Handle_drag, texCoords, alphaBlend:true );
texture.dataUniform = new Vector4( texture.dataUniform.x, texture.dataUniform.x, texture.dataUniform.x, texture.dataUniform.x );
if( texture.dataUniform[0] != vecPrev )
OnUpdateNode();
}
19
Source : SF_DraggableSeparator.cs
with MIT License
from XINCGer
with MIT License
from XINCGer
public void Draw( int yPos, int height ) {
rect.y = yPos;
rect.height = height;
rect.width = 7;
GUI.Box( rect, "", EditorStyles.textField );
Rect rHandle = new Rect( rect );
rHandle.xMin += 0;
rHandle.xMax -= 0;
Rect uv = new Rect( rect );
uv.x = 0;
uv.y = 0;
uv.width = 1;
uv.height /= SF_GUI.Handle_drag.height;
GUI.DrawTextureWithTexCoords( rHandle, SF_GUI.Handle_drag, uv );
if( rect.Contains( Event.current.mousePosition ) || dragging ) {
SF_GUI.replacedignCursor( rect, MouseCursor.ResizeHorizontal );
}
if(Event.current.isMouse){
if( SF_GUI.ReleasedRawLMB() ) {
StopDrag();
}
if( dragging ) {
UpdateDrag();
}
if( SF_GUI.PressedLMB( rect ) ) {
StartDrag();
}
}
}
19
Source : SFPSC_Properties.cs
with MIT License
from XINCGer
with MIT License
from XINCGer
public override float DrawInner(ref Rect r){
Restart:
//int propCount = editor.nodeView.treeStatus.propertyList.Count;
List<SF_Node> propertyList = editor.nodeView.treeStatus.propertyList;
//GUI.Label( r.MovedUp(), "propertyList.Count = " + propertyList.Count );
int propCount = propertyList.Count;
bool multiple = propCount > 1;
float prevYpos = r.y;
r.y = 0;
if( propCount == 0 ) {
r.y += 16;
GUI.enabled = false;
GUI.Label( r, "No properties in this shader yet" );
GUI.enabled = true;
r.y -= 16;
}
r.y += 23;
r.xMin += 20; // Indent
r.xMax -= 3;
r.height = propertyHeight;
// On drop...
if( draggingProperty != null && SF_GUI.ReleasedRawLMB()) {
int moveDist = Mathf.RoundToInt( ( Event.current.mousePosition.y - startMouseY ) / propertyHeight );
// Execute reordering!
if( moveDist != 0 ) { // See if it actually moved to another slot
int newIndex = Mathf.Clamp( dragStartIndex + moveDist, 0, propCount - 1 );
Undo.RecordObject(editor.nodeView.treeStatus,"property reorder");
editor.nodeView.treeStatus.propertyList.RemoveAt( dragStartIndex );
//if( newIndex > dragStartIndex )
// newIndex--;
editor.nodeView.treeStatus.propertyList.Insert( newIndex, draggingProperty );
}
draggingProperty = null;
}
float yStart = r.y;
int i = 0;
for(int j=0;j<propertyList.Count;j++){
SF_Node prop = propertyList[j];
if( prop.property == null ) { // Due to a weird bug - remove these nodes
// Disconnect
foreach( SF_NodeConnector con in prop.connectors ) {
if( con.conType == ConType.cOutput ) {
con.Disconnect();
}
}
prop.Deselect( registerUndo: false );
propertyList.Remove( prop );
editor.nodeView.treeStatus.propertyList.Remove( prop );
editor.nodes.Remove( prop );
//Debug.Log("Removing broken property...");
DestroyImmediate( prop );
goto Restart;
}
bool draggingThis = ( draggingProperty == prop );
bool dragging = (draggingProperty != null);
r.y = yStart + propertyHeight * i;
if( draggingThis ) {
r.x -= 5;
r.y = Mathf.Clamp(Event.current.mousePosition.y + dragStartOffsetY, yStart, yStart+propertyHeight*(propCount-1));
} else if( dragging ) {
if( i < dragStartIndex ){
float offset = propertyHeight + SF_Tools.Smoother( Mathf.Clamp( r.y - DragRectPosY, -propertyHeight, 0 ) / -propertyHeight ) * -propertyHeight;
r.y += offset;
} else if( i > dragStartIndex) {
r.y -= propertyHeight - SF_Tools.Smoother( Mathf.Clamp( r.y - DragRectPosY, 0, propertyHeight ) / propertyHeight ) * propertyHeight;
}
}
GUI.Box( r, string.Empty, draggingThis ? SF_Styles.HighlightStyle : SF_Styles.NodeStyle );
bool mouseOver = r.Contains( Event.current.mousePosition );
// We're now in the property box
// We need: Grabber, Text field, Internal label
bool imagePreview = (prop.property is SFP_Tex2d || prop.property is SFP_Cubemap);
bool colorInput = ( prop.property is SFP_Color );
bool checkboxInput = (prop.property is SFP_ToggleProperty || prop.property is SFP_SwitchProperty);
// GRABBER
Rect gRect = SF_Tools.GetExpanded( r, -6);
gRect.width = gRect.height/2f;
gRect.yMin += 8;
Rect gRectCoords = new Rect( gRect );
gRectCoords.x = 0;
gRectCoords.y = 0;
gRectCoords.width /= SF_GUI.Handle_drag.width;
gRectCoords.height /= SF_GUI.Handle_drag.height;
if(multiple)
GUI.DrawTextureWithTexCoords( gRect, SF_GUI.Handle_drag, gRectCoords );
gRect.yMin -= 8;
/*
if( propCount > 1 ) {
if( gRect.Contains( Event.current.mousePosition ) && SF_GUI.PressedLMB() && !dragging ) {
dragStartOffsetY = r.y - Event.current.mousePosition.y;
draggingProperty = prop;
dragStartIndex = i;
startMouseY = Event.current.mousePosition.y;
}
SF_GUI.replacedignCursor( gRect,MouseCursor.Pan);
GUI.DrawTextureWithTexCoords(gRect, SF_GUI.Handle_drag, gRectCoords );
}
*/
// Property type name
Color c = GUI.color;
c.a = 0.5f;
GUI.color = c;
Rect propTypeNameRect = new Rect( gRect );
//propTypeNameRect.x += propTypeNameRect.width + 8;
propTypeNameRect.y -= 5;
if( imagePreview || colorInput || checkboxInput )
propTypeNameRect.width = r.width - r.height - 38;
else
propTypeNameRect.width = r.width - 48;
propTypeNameRect.height = 16;
//if( prop.property != null )
GUI.Label( propTypeNameRect, prop.property.nameType, EditorStyles.miniLabel );
propTypeNameRect.x += gRect.width + 8;
c.a = 1f;
GUI.color = c;
//else
//return (int)r.yMax;
// INTERNAL NAME
if( mouseOver ) {
c.a = 0.5f;
GUI.color = c;
Rect intRect = new Rect( propTypeNameRect );
intRect.xMin += intRect.width - SF_GUI.WidthOf( prop.property.nameInternal, EditorStyles.label );
//SF_GUI.replacedignCursor( intRect, MouseCursor.Text );
GUI.Label( intRect, prop.property.nameInternal, EditorStyles.label );
c.a = 1f;
GUI.color = c;
}
// DISPLAY NAME
Rect dispNameRect = new Rect( propTypeNameRect );
dispNameRect.y += 18;
//dispNameRect.x += dispNameRect.width + 4;
//dispNameRect.height = 16;
//dispNameRect.y += 10;
//dispNameRect.width = ( r.width - dispNameRect.width - texRect.width - 20 ) * 0.5f;
ps.StartIgnoreChangeCheck();
string bef = prop.property.nameDisplay;
SF_GUI.replacedignCursor( dispNameRect, MouseCursor.Text );
//if( mouseOver )
UndoableEnterableNodeTextField(prop.property.node, dispNameRect, ref prop.property.nameDisplay, "change property name", update:false, extra:prop.property);
//else
//GUI.Label( dispNameRect, prop.property.nameDisplay, EditorStyles.boldLabel );
if( prop.property.nameDisplay != bef ) { // Changed
prop.property.UpdateInternalName();
}
ps.EndIgnoreChangeCheck();
// Texture preview
Rect texRect = new Rect( 0, 0, 0, 0 );
c = GUI.color;
if( imagePreview ) {
texRect = SF_Tools.GetExpanded(new Rect( r ), -4);
texRect.xMin += texRect.width - texRect.height;
//texRect.x += gRect.width + 4;
//texRect.width = texRect.height;
GUI.Box( SF_Tools.GetExpanded( texRect, 1f ), string.Empty, SF_Styles.NodeStyle );
GUI.color = Color.white;
GUI.DrawTexture( texRect, prop.texture.texture );
GUI.color = c;
}
if( prop.property is SFP_Slider ) {
SFN_Slider slider = ( prop as SFN_Slider );
ps.StartIgnoreChangeCheck();
Rect sR = new Rect( dispNameRect );
sR.y += sR.height+5;
sR.width = 28;
GUI.Label( sR, "Min" );
//sR.x += sR.width;
sR = sR.MovedRight();
prop.UndoableEnterableFloatField(sR, ref slider.min, "min value",null);
sR = sR.MovedRight();
sR.width = r.width - 164;
float beforeSlider = slider.current;
string sliderName = "slider" + slider.id;
GUI.SetNextControlName( sliderName );
sR.xMin += 4;
sR.xMax -= 4;
slider.current = prop.UndoableHorizontalSlider(sR, slider.current, slider.min, slider.max, "value");
if( beforeSlider != slider.current ) {
GUI.FocusControl( sliderName );
slider.OnValueChanged();
}
//SF_GUI.replacedignCursor( sR, MouseCursor.Arrow );
sR.x += sR.width+4;
sR.width = 32;
prop.UndoableEnterableFloatField(sR, ref slider.max, "max value",null);
sR.x += sR.width;
GUI.Label( sR, "Max" );
ps.EndIgnoreChangeCheck();
} else if( colorInput ) {
SFN_Color colNode = ( prop as SFN_Color );
texRect = SF_Tools.GetExpanded( new Rect( r ), -4 );
texRect.xMin += texRect.width - texRect.height;
//GUI.Box( SF_Tools.GetExpanded( texRect, 1f ), string.Empty, SF_Styles.NodeStyle );
GUI.color = Color.white;
texRect.yMax -= 21;
texRect.yMin += 15;
texRect.xMin += 2;
//texRect.xMax -= 2;
SF_GUI.replacedignCursor( texRect, MouseCursor.Arrow );
ps.StartIgnoreChangeCheck();
//Color col = EditorGUI.ColorField( texRect, colNode.texture.dataUniform );
Color col = colNode.UndoableColorField(texRect, colNode.texture.dataUniform, "set color of " + colNode.property.nameDisplay);
ps.EndIgnoreChangeCheck();
colNode.SetColor( col );
GUI.color = c;
} else if( prop.property is SFP_Vector4Property ) {
SFN_Vector4Property vec4 = ( prop as SFN_Vector4Property );
ps.StartIgnoreChangeCheck();
Rect sR = new Rect( dispNameRect );
sR.y += sR.height + 5;
sR.width = 20;
int lbWidth = 12;
//string channelStr = "XYZW";
sR.width = lbWidth;
GUI.Label( sR, "X", EditorStyles.miniLabel );
sR.x += sR.width;
sR.width = 32;
prop.UndoableEnterableFloatField(sR, ref vec4.texture.dataUniform.x, "X channel", EditorStyles.textField );
SF_GUI.replacedignCursor( sR, MouseCursor.Text );
sR.x += sR.width + 3;
sR.width = lbWidth;
GUI.Label( sR, "Y", EditorStyles.miniLabel );
sR.x += sR.width;
sR.width = 32;
prop.UndoableEnterableFloatField(sR, ref vec4.texture.dataUniform.y, "Y channel", EditorStyles.textField );
SF_GUI.replacedignCursor( sR, MouseCursor.Text );
sR.x += sR.width+3;
sR.width = lbWidth;
GUI.Label( sR, "Z", EditorStyles.miniLabel );
sR.x += sR.width;
sR.width = 32;
prop.UndoableEnterableFloatField(sR, ref vec4.texture.dataUniform.z, "Z channel", EditorStyles.textField );
SF_GUI.replacedignCursor( sR, MouseCursor.Text );
sR.x += sR.width + 3;
sR.width = lbWidth;
GUI.Label( sR, "W", EditorStyles.miniLabel );
sR.x += sR.width;
sR.width = 32;
prop.UndoableEnterableFloatField(sR, ref vec4.texture.dataUniform.w, "W channel", EditorStyles.textField );
SF_GUI.replacedignCursor( sR, MouseCursor.Text );
ps.EndIgnoreChangeCheck();
} else if( prop.property is SFP_ValueProperty ) {
SFN_ValueProperty val = ( prop as SFN_ValueProperty );
ps.StartIgnoreChangeCheck();
Rect sR = new Rect( dispNameRect );
sR.y += sR.height + 5;
sR.width = 20;
sR.width = 35;
GUI.Label( sR, "Value", EditorStyles.miniLabel );
sR.x += sR.width;
sR.width = 55;
//SF_GUI.EnterableFloatField( prop, sR, ref val.texture.dataUniform.r, EditorStyles.textField );
prop.UndoableEnterableFloatField(sR, ref val.texture.dataUniform.x, "value", EditorStyles.textField);
SF_GUI.replacedignCursor( sR, MouseCursor.Text );
ps.EndIgnoreChangeCheck();
} else if (checkboxInput){
bool isToggle = (prop.property is SFP_ToggleProperty);
bool prevValue = isToggle ? (prop.property.node as SFN_ToggleProperty).on : (prop.property.node as SFN_SwitchProperty).on;
ps.StartIgnoreChangeCheck();
texRect = SF_Tools.GetExpanded( new Rect( r ), -4 );
texRect.xMin += texRect.width - texRect.height;
//GUI.Box( SF_Tools.GetExpanded( texRect, 1f ), string.Empty, SF_Styles.NodeStyle );
texRect.yMax -= 21;
texRect.yMin += 15;
texRect.xMin += 2;
//texRect.xMax -= 2;
SF_GUI.replacedignCursor( texRect, MouseCursor.Arrow );
bool newValue = prevValue;
if(isToggle){
prop.property.node.UndoableToggle(texRect, ref (prop.property.node as SFN_ToggleProperty).on, "", "property checkbox", EditorStyles.toggle);
newValue = (prop.property.node as SFN_ToggleProperty).on;
} else {
prop.property.node.UndoableToggle(texRect, ref (prop.property.node as SFN_SwitchProperty).on, "", "property checkbox", EditorStyles.toggle);
newValue = (prop.property.node as SFN_SwitchProperty).on;
}
if(newValue != prevValue){
//if(isToggle){
// (prop.property.node as SFN_ToggleProperty).on = newValue;
//} else {
// (prop.property.node as SFN_SwitchProperty).on = newValue;
////}
if(isToggle){
prop.property.node.texture.dataUniform = Color.white * (newValue ? 1f : 0f);
} else {
//prop.property.node.texture.UpdateColorPreview("",true);
}
prop.property.node.OnUpdateNode(NodeUpdateType.Soft);
}
ps.EndIgnoreChangeCheck();
}
if( r.Contains( Event.current.mousePosition ) && SF_GUI.PressedLMB() && !dragging && multiple) {
dragStartOffsetY = r.y - Event.current.mousePosition.y;
draggingProperty = prop;
dragStartIndex = i;
startMouseY = Event.current.mousePosition.y;
editor.Defocus();
}
if(multiple)
SF_GUI.replacedignCursor( r, MouseCursor.Pan );
if( draggingThis )
r.x += 5;
//GUI.Label( r, "prop.property.nameType = " + prop.property.nameType );
r.y += propertyHeight;
i++;
}
r.y = yStart + propCount * propertyHeight;
r.height = 20;
r.y += prevYpos;
return r.yMax;
}
19
Source : ServerBrowser.cs
with MIT License
from Zetrith
with MIT License
from Zetrith
private void DrawSteam(Rect inRect)
{
string info = null;
if (!SteamManager.Initialized)
info = "MpNotConnectedToSteam".Translate();
else if (friends.Count == 0)
info = "MpNoFriendsPlaying".Translate();
if (info != null)
{
Text.Anchor = TextAnchor.MiddleCenter;
Widgets.Label(new Rect(0, 8, inRect.width, 40f), info);
Text.Anchor = TextAnchor.UpperLeft;
inRect.yMin += 40f;
}
float margin = 80;
Rect outRect = new Rect(margin, inRect.yMin + 10, inRect.width - 2 * margin, inRect.height - 20);
float height = friends.Count * 40;
Rect viewRect = new Rect(0, 0, outRect.width - 16f, height);
Widgets.BeginScrollView(outRect, ref steamScroll, viewRect, true);
float y = 0;
int i = 0;
foreach (SteamPersona friend in friends)
{
Rect entryRect = new Rect(0, y, viewRect.width, 40);
if (i % 2 == 0)
Widgets.DrawAltRect(entryRect);
if (Event.current.type == EventType.repaint)
GUI.DrawTextureWithTexCoords(new Rect(5, entryRect.y + 4, 32, 32), SteamImages.GetTexture(friend.avatar), new Rect(0, 1, 1, -1));
Text.Anchor = TextAnchor.MiddleLeft;
Widgets.Label(entryRect.Right(45).Up(5), friend.username);
GUI.color = SteamGreen;
Text.Font = GameFont.Tiny;
Widgets.Label(entryRect.Right(45).Down(8), "MpPlayingRimWorld".Translate());
Text.Font = GameFont.Small;
GUI.color = Color.white;
Text.Anchor = TextAnchor.MiddleCenter;
if (friend.serverHost != CSteamID.Nil)
{
Rect playButton = new Rect(entryRect.xMax - 85, entryRect.y + 5, 80, 40 - 10);
if (Widgets.ButtonText(playButton, "MpJoinButton".Translate()))
{
Close(false);
Log.Message("Connecting through Steam");
Find.WindowStack.Add(new SteamConnectingWindow(friend.serverHost) { returnToServerBrowser = true });
var conn = new SteamClientConn(friend.serverHost);
conn.username = Multiplayer.username;
Multiplayer.session = new MultiplayerSession();
Multiplayer.session.client = conn;
Multiplayer.session.ReapplyPrefs();
conn.State = ConnectionStateEnum.ClientSteam;
}
}
else
{
Rect playButton = new Rect(entryRect.xMax - 125, entryRect.y + 5, 120, 40 - 10);
Widgets.ButtonText(playButton, "MpNotInMultiplayer".Translate(), false, false, false);
}
Text.Anchor = TextAnchor.UpperLeft;
y += entryRect.height;
i++;
}
Widgets.EndScrollView();
}