Exemplo n.º 1
0
        /// <summary>
        /// Retrieves the value for the variable from the context.
        /// </summary>
        public float GetValue(ThemeContext context)
        {
            // Start variable
            float value = num2;

            if (op2 == "-")
                value = -value;

            // Process the variables
            if (variable != null)
            {
                // Grab the variable
                float vval = Convert.ToSingle(context[variable]);

                // Apply the operation
                if (op1 == "*")
                    vval *= num1;
                else
                    vval /= num1;

                // Add it to the results (since we already negate for
                // negatives)
                value += vval;
            }

            // Return the results
            return value;
        }
Exemplo n.º 2
0
        public static void SetThemeContext <TTheme>(this HttpContext context, ThemeContext <TTheme> themeContext)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (themeContext == null)
            {
                throw new ArgumentNullException(nameof(themeContext));
            }

            context.Items[ThemeContextKey] = themeContext;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Renders the theme command out.
        /// </summary>
        public void Render(ThemeContext context)
        {
            // Get the values
            float rx = x.GetValue(context);
            float ry = y.GetValue(context);

            // Get the font
            font = context.Theme.Fonts[fontName];

            // Figure out the string
            string output = text;
            string fmt = format;

            if (!String.IsNullOrEmpty(format) && variables != null)
            {
                // Create a format string instead
                object [] parms = new object [variables.Length];

                for (int i = 0; i < variables.Length; i++)
                {
                    // We need to do a bit of formatting to make these
                    // numbers as appropriate.
                    if (fmt.IndexOf("{" + i + ":N") >= 0)
                    {
                        // Convert to a double to make it a number
                        parms[i] = Convert.ToDouble(context[variables[i]]);
                    }
                    else if (fmt.IndexOf("{" + i + ":z") >= 0)
                    {
                        // This uses the zero fill rules
                        FormatZeroFill(i, ref fmt, context[variables[i]]);
                        parms[i] = 0;
                    }
                    else
                    {
                        // Just use it as a string
                        parms[i] = context[variables[i]].ToString();
                    }
                }

                // Format the string
                output = String.Format(fmt, parms);
            }

            // Render out the string
            font.Font.Print(output,
                color.GetColor(context),
                rx, ry,
                font.Alignment);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Renders the theme command out.
        /// </summary>
        public void Render(ThemeContext context)
        {
            // Get the values
            float rx = x.GetValue(context);
            float ry = y.GetValue(context);
            float rw = w.GetValue(context);
            float rh = h.GetValue(context);
            RectangleF bounds = new RectangleF(rx, ry, rw, rh);

            // Set the clipping area
            IBackendDrawingArgs ibda = context.DrawingArgs.Backend
                .SetClippingRegion(
                    context.DrawingArgs.BackendDrawingArgs, bounds);
            context.DrawingArgs.BackendDrawingArgs = ibda;

            // Call the viewport
            context.Callback.DrawViewport(context.DrawingArgs, bounds);

            // Clear the clip
            context.DrawingArgs.BackendDrawingArgs =
                context.DrawingArgs.Backend.ClearClippingRegion(ibda);
        }
Exemplo n.º 5
0
        //init the  theme
        public void InitTheme(string theme)
        {
            //ThemeInfo themeInfo;
            IThemeContext themeContext = ThemeContext.GetInstance();
            var           themeInfo    = new ThemeInfo();

            themeInfo.Name = SiteConfig.GetSetting().Theme;

            if (!string.IsNullOrEmpty(theme))
            {
                themeInfo.Name = theme;
                themeContext.WorkingDesktopTheme = theme;
            }
            else if (!string.IsNullOrEmpty(themeInfo.Name))
            {
                themeContext.WorkingDesktopTheme = themeInfo.Name;
            }
            else
            {
                //默认样式
                themeContext.WorkingDesktopTheme = "Default";
            }
        }
Exemplo n.º 6
0
        public Task <ThemeContext <Theme> > ResolveAsync(HttpContext context)
        {
            var themeContext = new ThemeContext <Theme>(_theme);

            return(Task.FromResult(themeContext));
        }
Exemplo n.º 7
0
 /// <summary>
 /// Retrieves the color, which may be based on context.
 /// </summary>
 public Color GetColor(ThemeContext context)
 {
     return color;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Renders out the screen, using the callback to fill in the
        /// gaps.
        /// </summary>
        public void Render(
			string layout, IThemeCallback callback, DrawingArgs args)
        {
            // Get the layout
            if (!layouts.Contains(layout))
                throw new Exception("Theme does not have the " + layout
                    + " layout");

            // Set up the context
            ThemeContext context = new ThemeContext();
            context.DrawingArgs = args;
            context.Callback = callback;
            context.ScreenSize = VideoManager.ScreenSize;
            context.Theme = this;

            context["width"] = context.ScreenSize.Width;
            context["height"] = context.ScreenSize.Height;

            if (State.Score != null)
            {
                context["distance"] = State.Score.Distance;
                context["countdown"] = State.Score.CountdownString;
                context["popsaved"] = State.Score.PopulationSaved;
                context["popkilled"] = State.Score.PopulationKilled;
                context["percentpopsaved"] = State.Score.PercentageSavedString;
                context["speed"] = State.Score.Speed;
                context["maxspeed"] = State.Score.MaximumSpeed;
                context["speedfmt"] = State.Score.SpeedString;
                context["maxspeedfmt"] = State.Score.MaximumSpeedString;
            }

            // Get it
            ThemeLayout tl = layouts[layout];
            tl.Render(context);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Renders out the screen, using the callback to fill in the
 /// gaps.
 /// </summary>
 public void Render(ThemeContext context)
 {
     // Loop through the commands
     foreach (IThemeCommand itc in commands)
         itc.Render(context);
 }