예제 #1
0
 public void add_layer(Graphics.Texture t, float scale = 1f, float alpha = 1f, uint color = 0xffffffff, Graphics.blend_mode blend = Graphics.blend_mode.normal, int sequence_x = 0, int sequence_y = 0)
 {
     if (_default) { _layers.Clear(); _default = false; }
     var l = new Layer();
     l.texture = t;
     l.alpha = alpha;
     l.scale = scale;
     l.blend = blend;
     l.color = color;
     l.sequence_x = sequence_x;
     l.sequence_y = sequence_y;
     _layers.Add(l);
 }
예제 #2
0
 public shader_param_buffer(string name, Graphics.ScreenBuffer buff)
 {
     this.name = name;
     this.buffer = buff;
 }
예제 #3
0
 public shader_param_tex(string name, Graphics.Texture tex)
 {
     this.name = name;
     this.texture = tex;
 }
예제 #4
0
        /// <summary> Breaks input text into lines based on font data. 
        /// It takes into account the width of each individual character as defined in font data to determine total width. It correctly takes into accountline break characters. </summary>
        /// <param name="input">the text to be broken into lines </param>
        /// <param name="max_width">maximum width of a single line</param>
        /// <param name="font">font</param>
        /// <returns>A neatly formated list of lines, including width data for each</returns>
        public static BreakResult break_text(string input, float max_width, Graphics.BitmapFont font)
        {
            var br = new BreakResult();
            br.font = font;

            float lw = 0f; // width of current line
            float ww = 0f; // width of current word

            word = new StringBuilder();

            linelist.Clear();
            line.Clear();

            float sw = font[' '].width; // space width

            for (int cursor = 0; cursor < input.Length; cursor++)
            {
                var c = input[cursor];

                if (c >= font.char_data.Length) throw new System.Exception("CHAR NOT SUPPORTED"); // this should never happen but even so the framework has catchers in place for graceful resuming

                var last_letter = cursor == input.Length - 1;

                if (line_break_chars.IndexOf(c) >= 0)
                {
                    linelist.Add(new Line(line.ToString(), lw));     // add current line to new line:
                    line.Clear(); lw = 0f;                           // clear line vars:
                    word.Clear(); ww = 0f;
                }
                else if (separators.IndexOf(c) >= 0)
                {
                    if (lw + sw + ww > max_width) // can'tex add word without overshooting
                    {
                        // add to new line:
                        linelist.Add(new Line(line.ToString(), lw));
                        // clear line vars:
                        line.Clear(); lw = 0f;
                        // add current word to new line and set width:
                        line.Append(word); lw = ww;
                        // clear word:
                        word.Clear(); ww = 0f;
                    }
                    else // can add the word.
                    {
                        if (line.Length > 0) { line.Append(' '); lw += sw; }
                        line.Append(word); lw += ww;
                        word.Clear(); ww = 0f;
                    }

                }
                else
                {
                    word.Append(c);
                    ww += font[c].width;
                }

                if (last_letter) // SPECIAL CASE
                {
                    if (lw + sw + ww > max_width) // can'tex add word without overshooting
                    {

                        linelist.Add(new Line(line.ToString(), lw)); // add to new line:
                        line.Clear(); lw = 0f;          // clear line vars:
                        line.Append(word); lw = ww;     // add current word to new line and set width:
                        word.Clear(); ww = 0f;          // clear word:
                        linelist.Add(new Line(line.ToString(), lw));
                    }
                    else
                    {
                        if (line.Length > 0) { line.Append(' '); lw += sw; }
                        line.Append(word); lw += ww;
                        linelist.Add(new Line(line.ToString(), lw));
                    }

                }

            }

            br.lines = linelist.ToArray(); // after having this entire method iterate through hundreds of numbers, the comparative costs of returning a neatly formated array is negligible.
            foreach (var ll in br.lines) if (ll.width > br.max_width) br.max_width = ll.width;
            return br;
        }