4 Replies Latest reply: Feb 9, 2010 4:10 AM by 843851 RSS

    HScene repaint sequence

    843851
      Hi.

      I'm developing an mhp application that has to render an animation.
      I have tested it on xLetView and on the ADB Stb developer version
      getting the same behavior.

      On an applet when I call a repaint(), internally the system calls
      the update(Graphics g) method... the default implementation
      clears the screen and then calls paint. Often I override this method
      in this way
      public void update(Graphics g) { paint(g); }
      so that no screen clearing is done (this is very useful when you have
      a still image on a background and you don't want to rewrite it every time).

      Going to my xLet... it's a simple snake game. When I call repaint the screen is cleared to the background color every time. So I have overridden the update method... but this method is never called
      (I placed a System.out.println in it and so I'm sure is never called).

      So I looked at the HScene specification... here there is a method
      scene.setBackgroundMode(HScene.NO_BACKGROUND_FILL);
      that tells the HScene not to clear the screen every time... but seems
      to not have any effect...

      so... I can't tell to my xLet to not clear the screen every time... and the update method seems that is never called.

      Anyone can help me? I really don't understand who is clearing the screen every time and how I can avoid this.

      p.s. another little question. If I place the image on the Background device I can solve the problem since the Image isn't rendered by the paint method every time... is it correct? I have good performance improvements in this way? On some documents I read that the background image is managed by the video decoder and so the cpu-processing can avoid to deal with it... if it's true, this technique can be used on every decoder or are there decoders not supporting background images?

      thanks

      Ignazio
        • 1. Re: HScene repaint sequence
          843851
          Here is a very short example showing my problem.

          In xLetView I have a red square moving left to right... but I don't want to have a background clear... so I would expect to have a growing red rectangle from left to right...

          What's wrong with this code?

          /**
          * Test: simple xLet showing background clear problems
          * Author: Ignazio Locatelli - DotLand srl - (C) 2005
          */

          package giochi.snake;

          import javax.tv.xlet.*;
          import java.io.*;
          import java.awt.*;
          import java.awt.event.*;
          import java.util.*;
          import org.havi.ui.*;
          import org.havi.ui.event.*;
          import org.dvb.ui.*;
          import javax.tv.service.selection.*;

          public class Test extends HComponent implements Xlet, Runnable {

          // xLet context
          private XletContext context;

          // reference to main thread
          private Thread testThread;

          private HScene scene;

          // square x Position
          int xPos = 0;

          public Test() {}

          public void initXlet(javax.tv.xlet.XletContext context) throws javax.tv.xlet.XletStateChangeException {
          this.context = context;
          }

          public void startXlet() throws javax.tv.xlet.XletStateChangeException {
          testThread = new Thread(this);
          testThread.start();
          }

          public void run() {
          getResources();
          while (true) {
          xPos++;
          if (xPos > 300) xPos = 0;
          try {
          Thread.sleep(100);
          } catch(Exception e) {}
          repaint();
          }
          }

          public void getResources() {
               HSceneFactory factory = HSceneFactory.getInstance();
               HSceneTemplate hst = new HSceneTemplate();
               hst.setPreference(
                    HSceneTemplate.SCENE_SCREEN_DIMENSION,
                    new org.havi.ui.HScreenDimension(1,1),
                    HSceneTemplate.REQUIRED);
               hst.setPreference(
                    HSceneTemplate.SCENE_SCREEN_LOCATION,
                    new org.havi.ui.HScreenPoint(0,0),
                    HSceneTemplate.REQUIRED);

               scene = factory.getBestScene(hst);

          scene.setBackgroundMode(HScene.NO_BACKGROUND_FILL);
          scene.setRenderMode(HScene.IMAGE_NONE);

          Rectangle rect = scene.getBounds();
               setBounds(rect);
               setVisible(true);

               scene.setVisible(false);
               scene.add(this);
               scene.setVisible(true);

               // do focus al component
          this.requestFocus();
          }

          /** NEVER CALLED!!! WHY? */
          public void update(Graphics g) { paint(g); }

          public void paint(Graphics g) {

          System.out.println("fill mode: " + scene.getBackgroundMode() + " mode fill = " + scene.BACKGROUND_FILL);
          g.setColor(new Color(200,0,0));
          g.fillRect(xPos,100,13,13);
          }

          public void pauseXlet() {
               doPause();
          }

          public void destroyXlet(boolean unconditional) throws javax.tv.xlet.XletStateChangeException {
               if (unconditional) {
               doDestroy();
               } else {
               throw new XletStateChangeException("May I stay alive?");
               }
          }

          public void doPause() {
               scene.setVisible(false);
          }

          public void doDestroy() {
               scene.setVisible(false);
               scene.remove(this);
               HSceneFactory.getInstance().dispose(scene);
               scene = null;
          }

          }
          • 2. Re: HScene repaint sequence
            843851
            Surfing the web I realized that update isn't called on lightweight components...

            And the xLet is an extension of a simple Component (or HComponent) and so it's a lightweight component.

            So... ok... update isn't called. But why my component background is cleared everytime? maybe is the HScene to which the component is added to perform a background clear?
            • 3. Re: HScene repaint sequence
              843851
              try to use:

              scene.paint(scene.getGraphics());

              insted of repaint.
              • 4. Re: HScene repaint sequence
                843851
                Thank you, your answer help me so much.