update status label if state changes

This commit is contained in:
test 2019-04-09 19:01:22 +02:00
parent 9984eca5ff
commit e7b37f8211
2 changed files with 43 additions and 2 deletions

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -26,11 +27,28 @@ public static class SMvcr
public static event VCREventHandler evFastforwardbutton; public static event VCREventHandler evFastforwardbutton;
public delegate void StatusLabelHandler(StatusEventArgs e);
public static event StatusLabelHandler evUpdateStatus;
public static void initSMvcr() public static void initSMvcr()
{ {
setState(new SvcrStandBy()); setState(new SvcrStandBy());
} }
public static void triggerUpdateLabel(string txt)
{
var e = new StatusEventArgs(txt);
//trigger handler
if (evUpdateStatus != null)
{
evUpdateStatus(e);
}
}
public static void setState(StateVCR e) public static void setState(StateVCR e)
{ {
_concreteState = null; _concreteState = null;
@ -96,6 +114,8 @@ public class SvcrStandBy : StateVCR
{ {
Debug.Print("Standby\n"); Debug.Print("Standby\n");
SMvcr.triggerUpdateLabel("Standby");
SMvcr.evRecordbutton += evRecordbutton; SMvcr.evRecordbutton += evRecordbutton;
SMvcr.evPlaybutton += evPlaybutton; SMvcr.evPlaybutton += evPlaybutton;
SMvcr.evRewindbutton += evRewindbutton; SMvcr.evRewindbutton += evRewindbutton;
@ -151,6 +171,8 @@ public class SvcrPlay : StateVCR
{ {
Debug.Print("Play\n"); Debug.Print("Play\n");
SMvcr.triggerUpdateLabel("Play");
SMvcr.evStopbutton += evStopbutton; SMvcr.evStopbutton += evStopbutton;
SMvcr.evEndtape += evEndtape; SMvcr.evEndtape += evEndtape;
SMvcr.evRewindbutton += evRewindbutton; SMvcr.evRewindbutton += evRewindbutton;
@ -216,6 +238,8 @@ public class SvcrRewind : StateVCR
{ {
Debug.Print("Rewind\n"); Debug.Print("Rewind\n");
SMvcr.triggerUpdateLabel("Rewind");
SMvcr.evStopbutton += evStopbutton; SMvcr.evStopbutton += evStopbutton;
SMvcr.evBeginningtape += evBeginningtape; SMvcr.evBeginningtape += evBeginningtape;
SMvcr.evPlaybutton += evPlaybutton; SMvcr.evPlaybutton += evPlaybutton;
@ -281,6 +305,8 @@ public class SvcrFastForward : StateVCR
{ {
Debug.Print("FastForward\n"); Debug.Print("FastForward\n");
SMvcr.triggerUpdateLabel("FastForward");
SMvcr.evStopbutton += evStopbutton; SMvcr.evStopbutton += evStopbutton;
SMvcr.evEndtape += evEndtape; SMvcr.evEndtape += evEndtape;
SMvcr.evRewindbutton += evRewindbutton; SMvcr.evRewindbutton += evRewindbutton;
@ -336,6 +362,8 @@ public class SvcrRecord : StateVCR
{ {
Debug.Print("Record\n"); Debug.Print("Record\n");
SMvcr.triggerUpdateLabel("Record");
SMvcr.evStopbutton += evStopbutton; SMvcr.evStopbutton += evStopbutton;
SMvcr.evEndtape += evEndtape; SMvcr.evEndtape += evEndtape;
} }
@ -375,4 +403,14 @@ public class SvcrRecord : StateVCR
public override void evFastforwardbutton() public override void evFastforwardbutton()
{ {
} }
}
public class StatusEventArgs
{
public StatusEventArgs(string txt)
{
Text = txt;
}
public string Text { get; private set; }
} }

View File

@ -25,13 +25,16 @@ namespace winVCR
SMtape.initSMtape(); SMtape.initSMtape();
SMvcr.initSMvcr(); SMvcr.initSMvcr();
SMvcr.evUpdateStatus += setLabelText;
} }
public void setLabelText(string txt)
public void setLabelText(StatusEventArgs e)
{ {
statusLabel.Text = txt; statusLabel.Text = e.Text;
} }