Exemplo n.º 1
0
        public override void Propagate(IInstanceState state)
        {
            SwitchInstance myState = state.Instance as SwitchInstance;
            Value          curVal  = myState == null ? Value.X : myState.currentValue;

            state.Set(0, curVal, 1);
        }
Exemplo n.º 2
0
 public void Dispose()
 {
     if (SwitchInstance != null)
     {
         SwitchInstance.UnregisterRoute(id);
     }
 }
Exemplo n.º 3
0
        protected override void OnInitialized()
        {
            base.OnInitialized();
            if (SwitchInstance == null)
            {
                throw new InvalidOperationException("A Route markup must be nested in a Switch markup.");
            }

            SwitchInstance.RegisterRoute(id, ChildContent, Template);
        }
Exemplo n.º 4
0
 protected override Task OnParametersSetAsync()
 {
     if (!hasRegisterd)
     {
         hasRegisterd = true;
         base.OnParametersSetAsync();
         if (SwitchInstance == null)
         {
             throw new InvalidOperationException("A Route markup must be included in a Switch markup.");
         }
         return(SwitchInstance.RegisterRoute(ChildContent, Template, MatchChildren));
     }
     return(Task.CompletedTask);
 }
Exemplo n.º 5
0
        public override void Paint(IComponentPainter painter)
        {
            SwitchInstance myState  = painter.Instance as SwitchInstance;
            bool           pending  = myState.pendingPress;
            Value          value    = myState.currentValue;
            int            valColor = painter.GetColorFor(value);
            int            vr       = (valColor >> 16) & 0xFF;
            int            vg       = (valColor >> 8) & 0xFF;
            int            vb       = valColor & 0xFF;
            int            darken   = ((vr >> 1) << 16) | ((vg >> 1) << 8) | (vb >> 1);
            int            contrast = vr + vg + vb > 128 * 3 ? 0x000000 : 0xFFFFFF;

            painter.FontSize  = 40;
            painter.FontStyle = Toves.AbstractGui.Canvas.FontStyle.Bold;
            if (pending)
            {
                painter.StrokeWidth = 10;
                painter.Color       = valColor;
                painter.FillRectangle(-52, -20, 52, 52);
                painter.Color = 0;
                painter.StrokeRectangle(-52, -20, 52, 52);
                painter.Color = contrast;
                painter.DrawText(-26, 0, value.ToString(), TextAlign.Center | TextAlign.VCenter);
            }
            else
            {
                int[] bgXs = new int[] { -64, -52, 0, 0, -12 };
                int[] bgYs = new int[] { 20, 32, 32, -20, -32 };
                painter.StrokeWidth = 10;
                painter.Color       = darken;
                painter.FillPolygon(bgXs, bgYs);
                painter.Color = valColor;
                painter.FillRectangle(-64, -32, 52, 52);
                painter.Color = 0;
                painter.StrokeRectangle(-64, -32, 52, 52);
                painter.StrokeLines(bgXs, bgYs);
                painter.StrokeLine(-12, 20, 0, 32);
                painter.Color = contrast;
                painter.DrawText(-38, -12, value.ToString(), TextAlign.Center | TextAlign.VCenter);
            }
            painter.PaintPorts();
        }
Exemplo n.º 6
0
 private Action <IInstanceState> PokeUpdate(PokeEventArgs args, bool pending, bool flip)
 {
     return((IInstanceState state) => {
         SwitchInstance myState = state.Instance as SwitchInstance;
         bool repaint = false;
         if (flip)
         {
             myState.currentValue = myState.currentValue.Not;
             myState.pendingPress = pending;
             args.Repropagate();
             repaint = true;
         }
         if (myState.pendingPress != pending)
         {
             myState.pendingPress = pending;
             repaint = true;
         }
         if (repaint)
         {
             args.Repaint();
         }
     });
 }