public static UITiledFill CreateFill(UIRenderContext ctx, outki.Texture tex, outki.UIBitmapTilingSettings settings, float x0, float y0, float x1, float y1) { UITiledFill tf = new UITiledFill(); float tileW = settings.UseLayoutScale ? settings.TileWidth * ctx.LayoutScale : settings.TileWidth; float tileH = settings.UseLayoutScale ? settings.TileHeight * ctx.LayoutScale : settings.TileHeight; float numX = (x1 - x0) / tileW; float numY = (y1 - y0) / tileH; int cX = (int)Math.Ceiling(numX) + 1; int cY = (int)Math.Ceiling(numY) + 1; tf.m_xs = new float[cX]; tf.m_ys = new float[cY]; for (int i = 0; i < cX - 1; i++) tf.m_xs[i] = (int)(x0 + i * tileW); for (int i = 0; i < cY - 1; i++) tf.m_ys[i] = (int)(y0 + i * tileH); tf.m_xs[cX - 1] = x1; tf.m_ys[cY - 1] = y1; float lastU1 = (tf.m_xs[cX - 1] - tf.m_xs[cX - 2]) / tileW; float lastV1 = (tf.m_ys[cY - 1] - tf.m_ys[cY - 2]) / tileH; tf.m_tex_f = ctx.TextureManager.ResolveTexture(tex, ctx.LayoutScale, 0, 0, 1, 1); tf.m_tex_r = ctx.TextureManager.ResolveTexture(tex, ctx.LayoutScale, 0, 0, lastU1, 1); tf.m_tex_b = ctx.TextureManager.ResolveTexture(tex, ctx.LayoutScale, 0, 0, 1, lastV1); tf.m_tex_br = ctx.TextureManager.ResolveTexture(tex, ctx.LayoutScale, 0, 0, lastU1, lastV1); return tf; }
public UIScreenRenderer(outki.UIScreen screen, UIWidgetHandler handler) { m_screen = screen; m_widgetHandler = handler; CreateAndInit(); }
public static UIWidgetRenderer CreateWidgetRenderer(outki.UIWidget widget, UIWidgetHandler handler) { // special case for dialogs system. if (widget.handler == "dialog-container") return new UIDialogContainerRenderer(widget, handler); return new UIWidgetRenderer(widget, handler); }
public static void AddDialog(outki.UIWidget widget, EventHandler evt) { DialogInstance dlg = new DialogInstance(); dlg.Template = widget; dlg.Renderer = null; dlg.EventHandler = evt; m_dialogs.Add(dlg); }
public CCGUI.UIWidgetRenderer CreateWidgetRenderer(outki.UIWidget widget) { switch (widget._rtti_type) { case outki.TetrisFieldWidget.TYPE: return new TetrisFieldWidgetRenderer(widget, this); default: break; } return CCGUI.UIDefaultWidgetHandler.CreateWidgetRenderer(widget, this); }
public UIButtonElementRenderer(outki.UIButtonElement element) { m_element = element; if (m_element.Style != null) { m_f0 = new UIFill(m_element.Style.Normal); m_f1 = new UIFill(m_element.Style.Highlight); m_f2 = new UIFill(m_element.Style.Pressed); if (m_element.Style.FontStyle != null) m_font = new UIFont(m_element.Style.FontStyle.Font); } }
public static Texture ResolveTextureUV(outki.Texture tex, float u0, float v0, float u1, float v1) { Texture tmp = new Texture(); outki.TextureOutputPng png = (outki.TextureOutputPng)tex.Output; if (png != null) { tmp.bmp = new BitmapImage(new Uri(png.PngPath, UriKind.Relative)); tmp.img = new CroppedBitmap(tmp.bmp, new Int32Rect((int)(u0 * tmp.bmp.Width), (int)(v0 * tmp.bmp.Height), (int)((u1 - u0) * tmp.bmp.Width), (int)((v1 - v0) * tmp.bmp.Height))); } return tmp; }
public static UIElementRenderer CreateElementRenderer(outki.UIElement element, UIWidgetHandler handler) { switch (element._rtti_type) { case outki.UIWidgetElement.TYPE: return handler.CreateWidgetRenderer(((outki.UIWidgetElement)element).widget); case outki.UIBitmapElement.TYPE: return new UIBitmapElementRenderer((outki.UIBitmapElement)element); case outki.UITextElement.TYPE: return new UITextElementRenderer((outki.UITextElement)element); case outki.UIFillElement.TYPE: return new UIFillElementRenderer((outki.UIFillElement)element); case outki.UIButtonElement.TYPE: return new UIButtonElementRenderer((outki.UIButtonElement)element); case outki.UISliderElement.TYPE: return new UISliderElementRenderer((outki.UISliderElement)element); default: return new UIDoNothingRenderer(); } }
public static void DrawSolidRect(float x0, float y0, float x1, float y1, outki.UIColor col = null) { if (lastTexture != null || begin == 0) { if (begin != 0) GL.End(); lastTexture = null; SolidMaterial.SetPass(0); GL.Begin(GL.QUADS); begin = 1; } if (col == null) GL.Color(new Color(m_currentColor.r, m_currentColor.g, m_currentColor.b, m_currentColor.a)); else GL.Color(new Color(m_currentColor.r * col.r / 255, m_currentColor.g * col.g / 255.0f, m_currentColor.b * col.b / 255.0f, m_currentColor.a * col.a / 255.0f)); GL.Vertex3(x0, y0, 0); GL.Vertex3(x1, y0, 0); GL.Vertex3(x1, y1, 0); GL.Vertex3(x0, y1, 0); }
public static void DrawGradientRect(float x0, float y0, float x1, float y1, outki.UIColor tl, outki.UIColor tr, outki.UIColor bl, outki.UIColor br) { if (lastTexture != null || begin == 0) { if (begin != 0) GL.End(); lastTexture = null; SolidMaterial.SetPass(0); GL.Begin(GL.QUADS); begin = 1; } HelpGLColor(tl); GL.Vertex3(x0, y0, 0); HelpGLColor(tr); GL.Vertex3(x1, y0, 0); HelpGLColor(br); GL.Vertex3(x1, y1, 0); HelpGLColor(bl); GL.Vertex3(x0, y1, 0); }
public static void HelpGLColor(outki.UIColor t) { GL.Color(new Color(m_currentColor.r * t.r / 255, m_currentColor.g * t.g / 255.0f, m_currentColor.b * t.b / 255.0f, m_currentColor.a * t.a / 255.0f)); }
public UIFillElementRenderer(outki.UIFillElement element) { m_fill = new UIFill(element.fill); }
// public UIDialogContainerRenderer(outki.UIWidget widget, UIWidgetHandler handler) : base(widget, handler) { m_handler = handler; }
// This can be overriden for custom drawing. public virtual void RenderSubElement(UIRenderContext rctx, ref UIElementLayout myLayout, outki.UIElement element, UIElementRenderer renderer, ref UIElementLayout layout) { renderer.Render(rctx, ref layout); }
public static void DrawGradientRect(float x0, float y0, float x1, float y1, outki.UIColor tl, outki.UIColor tr, outki.UIColor bl, outki.UIColor br) { }
public UIFill(outki.UIFill data) { m_data = data; }
public static Texture ResolveTextureUV(outki.Texture tex, float u0, float v0, float u1, float v1) { UIRenderer.Texture t = new Texture(); t.ld = LoadTexture(tex); outki.TextureOutput png = tex.Output as outki.TextureOutput; if (png != null) { // unused for now, need to add for jpeg too?! t.u0 = png.u0 + (png.u1 - png.u0) * u0; t.v0 = png.v0 + (png.v1 - png.v0) * v0; t.u1 = png.u0 + (png.u1 - png.u0) * u1; t.v1 = png.v0 + (png.v1 - png.v0) * v1; } return t; }
public UIBitmapElementRenderer(outki.UIBitmapElement element) { m_element = element; }
public UIWidgetRenderer(outki.UIWidget widget, UIWidgetHandler handler) { m_data = widget; m_handler = handler; Setup(m_data, m_handler); }
public CCGUI.UIElementRenderer CreateRenderer(outki.UIElement element) { return CCGUI.UIDefaultWidgetHandler.CreateElementRenderer(element, this); }
public Entry GetGlyph(string glyphId, outki.Font font, outki.FontGlyphPixData pixData, bool allowAlloc = true) { if (m_entries.ContainsKey(glyphId)) return m_entries[glyphId]; for (int i=0;i<m_atlases.Count;i++) { DynamicAtlas.TexRect r; if (m_atlases[i].atlas.Alloc(pixData.pixelWidth, pixData.pixelHeight, out r)) { Color[] col = new Color[pixData.pixelWidth * pixData.pixelHeight]; int[] val = new int[pixData.pixelWidth]; for (int y=0;y<pixData.pixelHeight;y++) { int rle0 = pixData.rleDataBegin[y]; int rle1 = rle0 + pixData.rleDataLength[y]; int opos = 0; for (int j=rle0;j!=rle1;j++) { if ((font.RLEData[j] & 0x80) == 0x80) { int count = font.RLEData[j++] & 0x7f; byte value = font.RLEData[j]; for (int b=0;b!=count;b++) val[opos++] = value; } else { int b = font.RLEData[j] * 2; if (b == 254) b = 255; val[opos++] = b; } } for (int x=0;x<pixData.pixelWidth;x++) { int idx = y * pixData.pixelWidth + x; col[idx].a = (float)val[x] / 255.0f; col[idx].r = 255.0f; col[idx].g = 255.0f; col[idx].b = 255.0f; } } m_atlases[i].atlas.SetPixels(r, col); Entry e = new Entry(); e.rect = r; e.atlas = m_atlases[i].atlas; m_entries[glyphId] = e; return e; } } if (allowAlloc) { Cache c = new Cache(); c.atlas = new DynamicAtlas(512, 512); m_atlases.Add(c); return GetGlyph(glyphId, font, pixData, false); } return null; }
private static Color ConvertColor(outki.UIColor color) { return Color.FromArgb(color.a, color.r, color.g, color.b); }
public static LoadedTexture LoadTexture(outki.Texture tex) { string imgPath = null; outki.TextureOutput to = tex.Output as outki.TextureOutput; if (to == null) return null; outki.DataContainer container = to.Data; if (container == null) return null; outki.DataContainerOutputFile output = container.Output as outki.DataContainerOutputFile; if (output == null) return null; imgPath = output.FilePath; foreach (LoadedTexture lt in loaded) { if (lt.path == imgPath) { return lt; } } UnityEngine.Debug.Log("Loading img [" + imgPath + "]"); LoadedTexture ld = new LoadedTexture(); TextAsset ta = Resources.Load(imgPath.Replace("Resources/",""), typeof(TextAsset)) as TextAsset; if (ta != null) { ld.unityTexture = new Texture2D (4, 4); ld.unityTexture.LoadImage(ta.bytes); ld.unityTexture.filterMode = FilterMode.Bilinear; ld.unityTexture.anisoLevel = 0; } else { // Try loading texture asset ld.unityTexture = Resources.Load(imgPath.Replace("Resources/","").Replace(".png", "")) as Texture2D; if (ld.unityTexture == null) { UnityEngine.Debug.LogError("Failed to load texture [" + imgPath + "]"); return null; } } ld.unityTexture.wrapMode = TextureWrapMode.Clamp; ld.material = new Material(TexturedShader); ld.material.mainTexture = ld.unityTexture; ld.path = imgPath; loaded.Add(ld); UnityEngine.Debug.Log("Loaded texture " + imgPath + " it is "+ ld.unityTexture); return ld; }
public UITextElementRenderer(outki.UITextElement element) { m_element = element; m_font = new UIFont(m_element.font); }
public static Texture ResolveTexture(outki.Texture tex) { return ResolveTextureUV(tex, 0, 0, 1, 1); }
public UISliderElementRenderer(outki.UISliderElement element) { m_fill = new UIFill(element.BackgroundFill); m_element = element; m_value = 0.5f; }
public RColor(outki.UIColor col) { r = col.r / 255.0f; g = col.g / 255.0f; b = col.b / 255.0f; a = col.a / 255.0f; }
public void Setup(outki.UIWidget widget, UIWidgetHandler handler) { int elements = 0; int layers = m_data.layers.Length; for (int l = 0; l < layers; l++) { outki.UIElementLayer layer = m_data.layers[l]; if (layer == null) continue; elements += layer.elements.Length; } // int count = 0; m_rtData = new ElementList[elements]; for (int l = 0; l < layers; l++) { outki.UIElementLayer layer = m_data.layers[l]; if (layer == null) continue; for (int i = 0; i < layer.elements.Length; i++) { m_rtData[count].element = layer.elements[i]; // can happen during live update. if (m_rtData[count].element != null) { m_rtData[count].renderer = handler.CreateRenderer(layer.elements[i]); } count++; } } }
public TetrisFieldWidgetRenderer(outki.UIWidget widget, CCGUI.UIWidgetHandler handler) : base(widget, handler) { m_widget = widget as outki.TetrisFieldWidget; }
public static void DrawSolidRect(float x0, float y0, float x1, float y1, outki.UIColor color) { Brush b = new SolidColorBrush(ConvertColor(color)); dc.DrawRectangle(b, new Pen(), new Rect(x0, y0, x1 - x0, y1 - y0)); }