Resume as default patch from dingo35
authorChris Tallon <chris@vomp.tv>
Sun, 19 May 2013 15:43:16 +0000 (16:43 +0100)
committerChris Tallon <chris@vomp.tv>
Sun, 19 May 2013 15:43:16 +0000 (16:43 +0100)
vrecording.cc
vrecording.h

index b285061635b6c91dfd651169592535c0d5803f44..0a5b3f63d8f0a136510e3c6e5b1967c3a400bd38 100644 (file)
@@ -73,36 +73,26 @@ VRecording::VRecording(RecMan* trecman, Recording* trec)
 
   add(&summary);
   
-  
-  buttonPlay.setPosition(10, area.h - 40);
-  buttonResume.setPosition(150, area.h - 40);
-  buttonMove.setPosition(290, area.h - 40);
-  buttonDelete.setPosition(430, area.h - 40);
-  
   int sfh = getFontHeight();
-  
-  buttonPlay.setSize(130, sfh);
-  buttonResume.setSize(130, sfh);
-  buttonMove.setSize(130, sfh);
-  buttonDelete.setSize(130, sfh);
-  
   buttonRegion.x = 10;
   buttonRegion.y = area.h - 40;
   buttonRegion.w = 550;
   buttonRegion.h = sfh;
 
-  buttonPlay.setText(tr("Play"));
-  buttonResume.setText(tr("Resume"));
-  buttonMove.setText(tr("Move"));
-  buttonDelete.setText(tr("Delete"));
+  button[PLAY].setText(tr("Play"));
+  button[RESUME].setText(tr("Resume"));
+  button[MOVE].setText(tr("Move"));
+  button[DELETE].setText(tr("Delete"));
   
-  add(&buttonPlay);
-  add(&buttonResume);    
-  add(&buttonMove);
-  add(&buttonDelete);
+  for (int i=PLAY, hor=10; i<last; i++, hor+= 140)
+  {
+    button[i].setPosition(hor, area.h - 40);
+    button[i].setSize(130, sfh);
+    add(&button[i]);
+  }
   
-  buttonPlay.setActive(1);
-  selected = 1;
+  selected = RESUME;
+  button[selected].setActive(1);
 }
 
 VRecording::~VRecording()
@@ -128,7 +118,7 @@ int VRecording::handleCommand(int command)
     case Remote::DF_UP:
     case Remote::UP:
     {
-      doLeft();
+      moveCursor(LEFT);
       return 2;
     }
     case Remote::RIGHT:
@@ -136,13 +126,13 @@ int VRecording::handleCommand(int command)
     case Remote::DF_DOWN:
     case Remote::DOWN:
     {
-      doRight();
+      moveCursor(RIGHT);
       return 2;
     }
     case Remote::OK:
     {
 
-      if (selected == 1)
+      if (selected == PLAY)
       {
         Message* m = new Message(); // Must be done after this view deleted
         m->from = this;
@@ -152,7 +142,7 @@ int VRecording::handleCommand(int command)
         return 4;
       }
 
-      if (selected == 2)
+      if (selected == RESUME)
       {
         Message* m = new Message(); // Must be done after this view deleted
         m->from = this;
@@ -162,7 +152,7 @@ int VRecording::handleCommand(int command)
         return 4;
       }
 
-      if (selected == 3)
+      if (selected == MOVE)
       {
         VRecMove* vrm = new VRecMove(recman);
         vrm->setParent(this);
@@ -172,7 +162,7 @@ int VRecording::handleCommand(int command)
         return 2;
       }
 
-      if (selected == 4)
+      if (selected == DELETE)
       {
         VQuestion* v = new VQuestion(this);
         v->setSize(260, 180);
@@ -208,73 +198,20 @@ int VRecording::handleCommand(int command)
   return 1;
 }
 
-void VRecording::doRight()
+void VRecording::moveCursor(Direction direction)
 {
-  switch(selected)
-  {
-    case 1:
-      buttonPlay.setActive(0);
-      buttonResume.setActive(1);
-      buttonPlay.draw();
-      buttonResume.draw();
-      break;
-    case 2:
-      buttonResume.setActive(0);
-      buttonMove.setActive(1);
-      buttonResume.draw();
-      buttonMove.draw();
-      break;
-    case 3:
-      buttonMove.setActive(0);
-      buttonDelete.setActive(1);
-      buttonMove.draw();
-      buttonDelete.draw();
-      break;
-    case 4:
-      buttonDelete.setActive(0);
-      buttonPlay.setActive(1);
-      buttonDelete.draw();
-      buttonPlay.draw();
-      break;
+  button[selected].setActive(0);
+  button[selected].draw();
+  if (direction == RIGHT)
+  { 
+    if (++selected == last) selected = PLAY;
   }
-  
-  if (++selected == 5) selected = 1;
-  
-  BoxStack::getInstance()->update(this, &buttonRegion);
-}
-
-void VRecording::doLeft()
-{
-  switch(selected)
+  else
   {
-    case 1:
-      buttonPlay.setActive(0);
-      buttonDelete.setActive(1);
-      buttonPlay.draw();
-      buttonDelete.draw();
-      break;
-    case 2:
-      buttonResume.setActive(0);
-      buttonPlay.setActive(1);
-      buttonResume.draw();
-      buttonPlay.draw();
-      break;
-    case 3:
-      buttonMove.setActive(0);
-      buttonResume.setActive(1);
-      buttonMove.draw();
-      buttonResume.draw();
-      break;
-    case 4:
-      buttonDelete.setActive(0);
-      buttonMove.setActive(1);
-      buttonDelete.draw();
-      buttonMove.draw();
-      break;
+    if (--selected < 0) selected = last - 1;
   }
-  
-  if (--selected == 0) selected = 4;
-  
+  button[selected].setActive(1);
+  button[selected].draw();
   BoxStack::getInstance()->update(this, &buttonRegion);
 }
 
@@ -282,66 +219,33 @@ void VRecording::processMessage(Message* m)
 {
   if (m->message == Message::MOUSE_MOVE)
   {
-    if (buttonPlay.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    for (int i = PLAY; i < last; i++)
     {
-      buttonPlay.setActive(1);
-      buttonResume.setActive(0);
-      buttonMove.setActive(0);
-      buttonDelete.setActive(0);
-      selected=1;
-      draw();
-      BoxStack::getInstance()->update(this);
-    }
-    else if (buttonResume.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
-    {
-      buttonPlay.setActive(0);
-      buttonResume.setActive(1);
-      buttonMove.setActive(0);
-      buttonDelete.setActive(0);
-      selected=2;
-      draw();
-      BoxStack::getInstance()->update(this);
-    }
-    else if (buttonMove.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
-    {
-      buttonPlay.setActive(0);
-      buttonResume.setActive(0);
-      buttonMove.setActive(1);
-      buttonDelete.setActive(0);
-      selected=3;
-      draw();
-      BoxStack::getInstance()->update(this);
-    }
-    else if (buttonDelete.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
-    {
-      buttonPlay.setActive(0);
-      buttonResume.setActive(0);
-      buttonMove.setActive(0);
-      buttonDelete.setActive(1);
-      selected=4;
-      draw();
-      BoxStack::getInstance()->update(this);
+      if (button[i].mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+      {
+        for (int j = PLAY; j < last; j++)
+          button[j].setActive(0);
+        button[i].setActive(1);
+        selected=i;
+        draw();
+        BoxStack::getInstance()->update(this);
+        break;
+      }
     }
   }
   else if (m->message == Message::MOUSE_LBDOWN)
   {
-    if (buttonPlay.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    int cancel = true;
+    for (int i = PLAY; i < last; i++)
     {
-      BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
-    }
-    else if (buttonResume.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
-    {
-      BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
-    }
-    else if (buttonMove.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
-    {
-      BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
-    }
-    else if (buttonDelete.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
-    {
-      BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
+      if (button[i].mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+      {
+        BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
+        cancel = false;
+        break;
+      }
     }
-    else
+    if (cancel)
     {
       //check if press is outside this view! then simulate cancel
       int x=(m->parameter>>16)-getScreenX();
@@ -354,7 +258,7 @@ void VRecording::processMessage(Message* m)
   }
   else if (m->message == Message::QUESTION_YES)
   {
-    if (selected == 4)
+    if (selected == DELETE)
     {
       Message* m2 = new Message(); // Delete self
       m2->from = this;
index 9d3e043e9c0687698a61914bd3cad9cb5a659800..e6c60ad5854e7cbd89a09d2e58b6b82fedefd649 100644 (file)
@@ -51,17 +51,19 @@ class VRecording : public TBBoxx
     Recording* rec;
     
     WTextbox summary;
-    
-    WButton buttonPlay;        // 1
-    WButton buttonResume;      // 2
-    WButton buttonMove;        // 3 
-    WButton buttonDelete;      // 4
+
+    enum Action { PLAY=0, RESUME, MOVE, DELETE, last };
+    WButton button[last];
+//    WButton buttonPlay;        // 1
+//    WButton buttonResume;      // 2
+//    WButton buttonMove;        // 3 
+//    WButton buttonDelete;      // 4
     
     int selected;
     Region buttonRegion;
-    
-    void doLeft();
-    void doRight();
+   
+    enum Direction { LEFT, RIGHT };
+    void moveCursor(Direction direction);
 };
 
 #endif