Example #1
0
        public void GetDefaultBGColour(MHColour colour)
        {
            MHApplication pApp = CurrentApp();

            if (pApp != null && pApp.BGColour.IsSet())
            {
                colour.Copy(pApp.BGColour);
            }
            else
            {
                colour.SetFromString("\u0000\u0000\u0000\u00FF");  // '=00=00=00=FF' Default - transparent
            }
        }
Example #2
0
        public void GetDefaultTextColour(MHColour colour)
        {
            MHApplication pApp = CurrentApp();

            if (pApp != null && pApp.TextColour.IsSet())
            {
                colour.Copy(pApp.TextColour);
            }
            else
            {
                colour.SetFromString("\u00FF\u00FF\u00FF\u0000");  // '=FF=FF=FF=00' UK MHEG Default - white
            }
        }
Example #3
0
        //  void GetDefaultFont(MHFontBody &font); // Not currently implemented
        public void GetDefaultFontAttrs(MHOctetString str)
        {
            MHApplication pApp = CurrentApp();

            if (pApp != null && pApp.FontAttrs.Size > 0)
            {
                str.Copy(pApp.FontAttrs);
            }
            else
            {
                str.Copy("plain.24.24.0");  // TODO: Check this.
            }
        }
Example #4
0
        // Get the various defaults.  These are extracted from the current app or the (UK) MHEG defaults.
        public int GetDefaultCharSet()
        {
            MHApplication pApp = CurrentApp();

            if (pApp != null && pApp.CharSet > 0)
            {
                return(pApp.CharSet);
            }
            else
            {
                return(10); // UK MHEG default.
            }
        }
Example #5
0
        public int GetDefaultBitmapCHook()
        {
            MHApplication pApp = CurrentApp();

            if (pApp != null && pApp.BitmapCHook > 0)
            {
                return(pApp.BitmapCHook);
            }
            else
            {
                return(4); // UK MHEG default - PNG bitmap
            }
        }
Example #6
0
        public int GetDefaultStreamCHook()
        {
            MHApplication pApp = CurrentApp();

            if (pApp != null && pApp.StrCHook > 0)
            {
                return(pApp.StrCHook);
            }
            else
            {
                return(10); // UK MHEG default.
            }
        }
Example #7
0
        public void GetDefaultButtonRefColour(MHColour colour)
        {
            MHApplication pApp = CurrentApp();

            if (pApp != null && pApp.ButtonRefColour.IsSet())
            {
                colour.Copy(pApp.ButtonRefColour);
            }
            else
            {
                colour.SetFromString("\u00FF\u00FF\u00FF\u0000");  // '=FF=FF=FF=00' ??? Not specified in UK MHEG
            }
        }
Example #8
0
        protected MHGroup ParseProgram(byte[] text)
        {
            if (text.Length == 0)
            {
                return(null);
            }

            IMHParser   parser = null;
            MHParseNode pTree  = null;
            MHGroup     pRes   = null;

            // Look at the first byte to decide whether this is text or binary.  Binary
            // files will begin with 0xA0 or 0xA1, text files with white space, comment ('/')
            // or curly bracket.
            // This is only there for testing: all downloaded objects will be in ASN1
            byte ch = text[0];

            if (ch >= 128)
            {
                parser = new MHParseBinary(text);
            }
            else
            {
                parser = new MHParseText(text);
            }

            // Parse the binary or text.
            pTree = parser.Parse();

            switch (pTree.GetTagNo())
            { // The parse node should be a tagged item.
            case ASN1Codes.C_APPLICATION: pRes = new MHApplication(); break;

            case ASN1Codes.C_SCENE: pRes = new MHScene(); break;

            default: pTree.Failure("Expected Application or Scene"); break; // throws exception.
            }
            pRes.Initialise(pTree, this);                                   // Convert the parse tree.

            return(pRes);
        }
Example #9
0
        public void PrintCurrentApp(TextWriter writer)
        {
            MHApplication application = CurrentApp();

            application.Print(writer, 0);
        }
Example #10
0
        public bool Launch(MHObjectRef target, bool fIsSpawn)
        {
            string csPath = GetPathName(target.GroupId); // Get path relative to root.

            if (csPath.Length == 0)
            {
                return(false);                    // No file name.
            }
            if (m_fInTransition)
            {
                Logging.Log(Logging.MHLogWarning, "Launch during transition - ignoring");
                return(false);
            }
            // Check that the file exists before we commit to the transition.
            // This may block if we cannot be sure whether the object is present.
            byte[] text;
            if (!m_Context.GetCarouselData(csPath, out text))
            {
                return(false);
            }

            m_fInTransition = true; // Starting a transition
            try
            {
                if (CurrentApp() != null)
                {
                    if (fIsSpawn)
                    {
                        // Run the CloseDown actions.
                        AddActions(CurrentApp().CloseDown);
                        RunActions();
                    }
                    if (CurrentScene() != null)
                    {
                        CurrentScene().Destruction(this);
                    }
                    CurrentApp().Destruction(this);
                    if (!fIsSpawn)
                    {
                        m_ApplicationStack.Pop();             // Pop and delete the current app.
                    }
                }

                MHApplication pProgram = (MHApplication)ParseProgram(text);

                if ((Logging.GetLoggingLevel() & Logging.MHLogScenes) != 0)   // Print it so we know what's going on.
                {
                    pProgram.Print(Logging.GetLoggingStream(), 0);
                }

                if (!pProgram.IsApp)
                {
                    throw new MHEGException("Expected an application");
                }

                // Save the path we use for this app.
                pProgram.Path = csPath; // Record the path
                int nPos = pProgram.Path.LastIndexOf('/');
                if (nPos < 0)
                {
                    pProgram.Path = "";
                }
                else
                {
                    pProgram.Path = pProgram.Path.Substring(0, nPos);
                }
                // Have now got the application.
                m_ApplicationStack.Push(pProgram);

                // This isn't in the standard as far as I can tell but we have to do this because
                // we may have events referring to the old application.
                m_EventQueue.Clear();

                // Activate the application. ....
                CurrentApp().Activation(this);
                m_fInTransition = false; // The transition is complete
                return(true);
            }
            catch (MHEGException)
            {
                m_fInTransition = false; // The transition is complete
                return(false);
            }
        }
Example #11
0
        public void TransitionToScene(MHObjectRef target)
        {
            int i;

            if (m_fInTransition)
            {
                // TransitionTo is not allowed in OnStartUp or OnCloseDown actions.
                Logging.Log(Logging.MHLogWarning, "TransitionTo during transition - ignoring");
                return;
            }
            if (target.GroupId.Size == 0)
            {
                return;                           // No file name.
            }
            string csPath = GetPathName(target.GroupId);

            // Check that the file exists before we commit to the transition.
            byte[] text;
            if (!m_Context.GetCarouselData(csPath, out text))
            {
                return;
            }

            // Parse and run the file.
            MHGroup pProgram = ParseProgram(text);

            if (pProgram.IsApp)
            {
                throw new MHEGException("Expected a scene");
            }
            // Clear the action queue of anything pending.
            m_ActionStack.Clear();

            // At this point we have managed to load the scene.
            // Deactivate any non-shared ingredients in the application.
            MHApplication pApp = CurrentApp();

            for (i = pApp.Items.Size; i > 0; i--)
            {
                MHIngredient pItem = pApp.Items.GetAt(i - 1);
                if (!pItem.IsShared())
                {
                    pItem.Deactivation(this);                    // This does not remove them from the display stack.
                }
            }
            m_fInTransition = true; // TransitionTo etc are not allowed.
            if (pApp.CurrentScene != null)
            {
                pApp.CurrentScene.Deactivation(this); // This may involve a call to RunActions
                pApp.CurrentScene.Destruction(this);
            }
            // Everything that belongs to the previous scene should have been removed from the display stack.

            // At this point we may have added actions to the queue as a result of synchronous
            // events during the deactivation.

            // Remove any events from the asynch event queue unless they derive from
            // the application itself or a shared ingredient.
            List <MHAsynchEvent> removeEvents = new List <MHAsynchEvent>();

            foreach (MHAsynchEvent e in m_EventQueue)
            {
                if (!e.EventSource.IsShared())
                {
                    removeEvents.Add(e);
                }
            }
            foreach (MHAsynchEvent e in removeEvents)
            {
                m_EventQueue.Remove(e);
            }

            // Can now actually delete the old scene.
            if (pApp.CurrentScene != null)
            {
                pApp.CurrentScene = null;
            }

            // Switch to the new scene.
            CurrentApp().CurrentScene = (MHScene)pProgram;
            SetInputRegister(CurrentScene().EventReg);

            m_redrawRegion = new Region(new Rectangle(0, 0, CurrentScene().SceneCoordX, CurrentScene().SceneCoordY)); // Redraw the whole screen

            if ((Logging.GetLoggingLevel() & Logging.MHLogScenes) != 0)
            { // Print it so we know what's going on.
                pProgram.Print(Logging.GetLoggingStream(), 0);
            }

            pProgram.Preparation(this);
            pProgram.Activation(this);
            m_fInTransition = false; // The transition is complete
        }