]> git.vomp.tv Git - vompclient.git/commitdiff
Mouse support (part 1)
authorChris Tallon <chris@vomp.tv>
Wed, 27 Dec 2006 23:13:50 +0000 (23:13 +0000)
committerChris Tallon <chris@vomp.tv>
Wed, 27 Dec 2006 23:13:50 +0000 (23:13 +0000)
17 files changed:
message.h
mtdmvp.cc
vaudioselector.cc
vaudioselector.h
vchannellist.cc
vchannellist.h
vepg.cc
vepg.h
viewman.cc
wbutton.cc
wbutton.h
widget.cc
widget.h
woptionbox.cc
woptionbox.h
wselectlist.cc
wselectlist.h

index 4c98b999cfdc1564619906597020dab27a785368..a323b231378190771f4a4e2693750e054d22303d 100644 (file)
--- a/message.h
+++ b/message.h
@@ -67,6 +67,8 @@ class Message
     const static ULONG PLAYER_EVENT = 22;
     const static ULONG AUDIO_CHANGE_CHANNEL = 23;
     const static ULONG CHILD_CLOSE = 24;
+    const static ULONG MOUSE_MOVE = 25;
+    const static ULONG MOUSE_LBDOWN = 26;
 };
 
 #endif
index 28a943217ed4cdf393b22cfdea8ca1e2faed27c5..0860a16e9dcf0f9fde6a3c951ed4750181d6044a 100644 (file)
--- a/mtdmvp.cc
+++ b/mtdmvp.cc
@@ -37,7 +37,7 @@ int MtdMVP::init(char* device)
 
   int fd;
 
-  if ((fd = open("/dev/mtdblock1", O_RDONLY)) < 0)
+  if ((fd = open("/dev/mtd1", O_RDONLY)) < 0)
   {
     Log::getInstance()->log("MTD", Log::DEBUG, "Open fail");
     initted = 0;
index a277d8b4f6375d4f5f401bc4f77a5931ff168d4d..d44dff561130530c06e916d2acd82cd154efa23c 100644 (file)
@@ -229,3 +229,34 @@ int VAudioSelector::handleCommand(int command)
 
   return 0;
 }
+
+void VAudioSelector::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      sl.draw();
+      ViewMan::getInstance()->updateView(this);
+    }
+    return;
+  }
+
+  if (m->message == Message::MOUSE_LBDOWN)
+  {
+    if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+    else
+    { //check if press is outside this view! then simulate cancel
+      int x=(m->parameter>>16)-getScreenX();
+      int y=(m->parameter&0xFFFF)-getScreenY();
+      if (x<0 || y <0 || x>getWidth() || y>getHeight())
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+      }
+    }
+    return;
+  }
+}
index 1904b53e215d84d59ce5e00a7f3616f6fc679665..d6aebefe4bfeefbe89e14e5aafa8ad1a1bda893c 100644 (file)
@@ -56,6 +56,7 @@ class VAudioSelector : public View
     ~VAudioSelector();
 
     int handleCommand(int command);
+    void processMessage(Message* m);
     void draw();
 
   private:
index 9da042d13f936ddd779a73ef27520f5e176eab28..424a88622c6b40a6377bdb2c77e87d0eef390471 100644 (file)
@@ -214,3 +214,35 @@ int VChannelList::handleCommand(int command)
   // stop command getting to any more views
   return 1;
 }
+
+void VChannelList::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      sl.draw();
+      doShowingBar();
+      ViewMan::getInstance()->updateView(this);
+    }
+    return;
+  }
+
+  if (m->message == Message::MOUSE_LBDOWN)
+  {
+    if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+    else
+    { //check if press is outside this view! then simulate cancel
+      int x=(m->parameter>>16)-getScreenX();
+      int y=(m->parameter&0xFFFF)-getScreenY();
+      if (x<0 || y <0 || x>getWidth() || y>getHeight())
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+      }
+    }
+    return;
+  }
+}
\ No newline at end of file
index 13c747eae22cfd3f8aa0f4d12669f27c05ea7f83..a0b2cbd0d1672cd943e07f49e3bd4fc7e35e9d2e 100644 (file)
@@ -46,6 +46,7 @@ class VChannelList : public View
     void setList(ChannelList* chanList);
     void highlightChannel(Channel* channel);
 
+    void processMessage(Message* m);
     int handleCommand(int command);
     void draw();
 
diff --git a/vepg.cc b/vepg.cc
index cdd783f4cb57ec881bf41f12fe8c0c746503d593..d60f194c6cbcf4da83dbc952a43b65ce9f3620c1 100644 (file)
--- a/vepg.cc
+++ b/vepg.cc
@@ -623,3 +623,88 @@ time_t VEpg::prevHour(time_t* t)
   return mktime(tms);
 }
 
+void VEpg::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (chanListbox.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      drawData();
+      ViewMan::getInstance()->updateView(this);
+    }
+    return;
+  }
+
+  if (m->message == Message::MOUSE_LBDOWN)
+  {
+    if (chanListbox.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+    else
+    {
+      //check if press is outside this view! then simulate cancel
+      int x=(m->parameter>>16)-getScreenX();
+      int y=(m->parameter&0xFFFF)-getScreenY();
+      int keyx = chanListbox.getOffsetX();
+      int keyy = chanListbox.getOffsetY() + chanListbox.getHeight() + 2;
+
+      if (x<0 || y <0 || x>getWidth() || y>getHeight())
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+      }
+      else if (x>=(keyx+72) && y>=(keyy+4) &&x<=(keyx+72+104) &&y<=(keyy+4+Surface::getFontHeight() + 2))
+      {
+        ViewMan::getInstance()->handleCommand(Remote::RED);
+      }
+      else if (x>=(keyx+72) && y>=(keyy+ Surface::getFontHeight() + 8) &&x<=(keyx+72+104) &&y<=(keyy+8+2*Surface::getFontHeight() + 2))
+      {
+        ViewMan::getInstance()->handleCommand(Remote::GREEN);
+      }
+      else if (x>=(keyx+180) && y>=(keyy+4) &&x<=(keyx+180+104) &&y<=(keyy+4+Surface::getFontHeight() + 2))
+      {
+        ViewMan::getInstance()->handleCommand(Remote::YELLOW);
+      }
+      else if (x>=(keyx+180) && y>=(keyy+ Surface::getFontHeight() + 8) &&x<=(keyx+180+104) &&y<=(keyy+8+2*Surface::getFontHeight() + 2))
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BLUE);
+      }
+      else if (x>=(keyx+290) && y>=(keyy+4) &&x<=(keyx+180+290) &&y<=(keyy+4+Surface::getFontHeight() + 2))
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK);
+      }
+      else if (x>=(keyx+290) && y>=(keyy+ Surface::getFontHeight() + 8) &&x<=(keyx+290+180) &&y<=(keyy+8+2*Surface::getFontHeight() + 2))
+      {
+        ViewMan::getInstance()->handleCommand(Remote::RECORD);
+      }
+      else if (x>=(keyx+474) && y>=(keyy+4) &&x<=(keyx+128+474) &&y<=(keyy+4+Surface::getFontHeight() + 2))
+      {
+        ViewMan::getInstance()->handleCommand(Remote::PLAY);
+      }
+      else if (x>=(keyx+474) && y>=(keyy+ Surface::getFontHeight() + 8) &&x<=(keyx+238+474) &&y<=(keyy+8+2*Surface::getFontHeight() + 2))
+      {
+        ViewMan::getInstance()->handleCommand(Remote::GO);
+      }
+      else if ( x>=(chanListbox.getOffsetX())
+                && y>=(chanListbox.getOffsetY() + 5)
+                // &&x<=(chanListbox.getOffsetX()+155 + WINDOW_WIDTH * MINUTE_SCALE)
+                &&y<=(chanListbox.getOffsetY() - Surface::getFontHeight()
+                - 3+chanListbox.getHeight() + Surface::getFontHeight() + 3)
+              )
+      {
+        int cy=y-(chanListbox.getOffsetY() + 5);
+        int row=cy/(Surface::getFontHeight()+2);
+        int clistTop = chanListbox.getTopOption();
+        chanListbox.hintSetCurrent(clistTop+row);
+        int cx=x-155;
+        time_t ttime = cx*60/MINUTE_SCALE+ltime;
+        //x = 155 + (MINUTE_SCALE * (event->time - ltime) / 60);
+
+        selTime = ttime;
+        drawData();
+        viewman->updateView(this);
+      }
+    }
+    return;
+  }
+}
diff --git a/vepg.h b/vepg.h
index 27f8e9f99377f51d6bfd9155221ac0c410c7a390..35a58c89deb089c353d2def513ee1e255297528b 100644 (file)
--- a/vepg.h
+++ b/vepg.h
@@ -53,6 +53,7 @@ class VEpg : public View
     int handleCommand(int command); // deal with commands (from remote control)
     void draw(); // draw epg view
     void setCurrentChannel(char* chname);
+    void processMessage(Message* m);
 
   private:
     static VEpg* instance;
index 7b017aac8d56c773c3f3b8f2b914bdbc32363034..9b03c63089151b68e11cb6a04e62bbfd92cb9dd6 100644 (file)
@@ -414,6 +414,14 @@ void ViewMan::processMessage(Message* m)
     return;
   }
 
+  /* Handle mouse events*/
+  // They come in with m->to = NULL? and just need to be delivered to top view?
+  if (numViews && ((m->message == Message::MOUSE_MOVE) || (m->message == Message::MOUSE_LBDOWN)))
+  {
+    views[numViews-1]->processMessage(m);
+    return;
+  }
+
   Log::getInstance()->log("ViewMan", Log::DEBUG, "it's for meeee!");
 
   switch(m->message)
index 5e7c69cdfb4fdde01185da2b7e0d8eee238acd52..e638c9aace96fba740dc11798c53a5f8d61b3c67 100644 (file)
@@ -70,3 +70,24 @@ int WButton::getTag()
 {
   return tag;
 }
+
+bool WButton::mouseMove(int x, int y)
+{
+  if ((x-offsetX)>=area.x && (y-offsetY)>=area.y
+    && (x-offsetX)<=area.w && (y-offsetY)<=area.h && !active)
+  {
+    setActive(1);
+    return true;
+  }
+  return false;
+}
+
+bool WButton::mouseLBDOWN(int x, int y)
+{
+  if ((x-offsetX)>=area.x && (y-offsetY)>=area.y
+    && (x-offsetX)<=area.w && (y-offsetY)<=area.h && active)
+  {
+    return true;
+  }
+  return false;
+}
index a76f77ecc753a3d7edb7e9647258bdec0dc4a41b..14461aa38780c3f808ce004cbe5f61502b6a5b70 100644 (file)
--- a/wbutton.h
+++ b/wbutton.h
@@ -39,6 +39,9 @@ class WButton : public Widget
     void setTag(int tag);
     int getTag();
 
+    virtual bool mouseMove(int x, int y);
+    virtual bool mouseLBDOWN(int x, int y);
+
   private:
     UCHAR active;
 
index dc332c359955b2a64a5f62d268b8b4b2bb77c17c..757ce569fb77490404a46c953081b373aaeec0d6 100644 (file)
--- a/widget.cc
+++ b/widget.cc
@@ -54,3 +54,13 @@ int Widget::getOffsetX()
 {
   return offsetX;
 }
+
+bool Widget::mouseMove(int x, int y)
+{
+  return false;
+}
+
+bool Widget::mouseLBDOWN(int x, int y)
+{
+  return false;
+}
index c57200978811839dfc144959557f80c354bdbdd2..a2d01bb36160d11fb9cfc49c24e6ca35962c4860 100644 (file)
--- a/widget.h
+++ b/widget.h
@@ -38,6 +38,8 @@ class Widget : public Box
     int getOffsetY();
     int getOffsetX();
 
+    virtual bool mouseMove(int x, int y);
+    virtual bool mouseLBDOWN(int x, int y);
 
   private:
 
index 65c3b4fdaea7fe010e38198a713e88521d278463..be1b5d22dff00a1f37a2c415d657e731dd761eea 100644 (file)
@@ -147,3 +147,24 @@ void WOptionBox::setSelected(int toSelect)
   }
   currentOption = 0;
 }
+
+bool WOptionBox::mouseMove(int x, int y)
+{
+  if ((x-offsetX)>=area.x && (y-offsetY)>=area.y
+    && (x-offsetX)<=area.w && (y-offsetY)<=area.h && !active)
+  {
+    setActive(1);
+    return true;
+  }
+  return false;
+}
+
+bool WOptionBox::mouseLBDOWN(int x, int y)
+{
+  if ((x-offsetX)>=area.x && (y-offsetY)>=area.y
+    && (x-offsetX)<=area.w && (y-offsetY)<=area.h && active)
+  {
+    return true;
+  }
+  return false;
+}
index 6ef0514e6f25990490e3e346114f144c04eaf1c9..3e4261b28ca638f3edc3f5cdf344f5f9e95d6208 100644 (file)
@@ -47,6 +47,9 @@ class WOptionBox : public Widget
     void draw();
     int getSelectedIndex();
 
+    virtual bool mouseMove(int x, int y);
+    virtual bool mouseLBDOWN(int x, int y);
+
     const static int MODE_TEXT = 1;
     const static int MODE_INT = 2;
 
index 21b6d98251f99e2ef575d1beebfdce7284c6f86d..c01eff7f217a9374c368d94ee9700f3139a14e32 100644 (file)
@@ -97,7 +97,6 @@ void WSelectList::draw()
   if (topOption < 0) topOption = 0;
 
 
-
   fillColour(backgroundColour);
 
   UINT ypos = 5;
@@ -149,7 +148,6 @@ void WSelectList::drawOptionLine(char* text, int xpos, int ypos, Colour& colour)
   }
 }
 
-
 void WSelectList::up()
 {
   if (selectedOption > 0)
@@ -221,3 +219,56 @@ ULONG WSelectList::getCurrentOptionData()
 {
   return options[selectedOption].data;
 }
+
+bool WSelectList::mouseMove(int x, int y)
+{
+  int ml = getMouseLine(x-offsetX,y-offsetY);
+  if (ml>=0 && ml!=(int)selectedOption)
+  {
+    selectedOption = ml;
+    return true;
+  }
+  return false;
+}
+
+bool WSelectList::mouseLBDOWN(int x, int y)
+{
+  int ml = getMouseLine(x-offsetX, y-offsetY);
+  if (ml == (int)selectedOption)
+  {
+    /* caller should generate a OK message*/
+    return true;
+  }
+  return false;
+}
+
+int WSelectList::getMouseLine(int x,int y)
+{
+  int fontHeight = surface->getFontHeight();
+  int ySeperation = fontHeight + gap;
+
+  if (y<0) return -1;
+  if (x<0 || x>(int)area.w) return -1;
+  if (y>(int)(10+numOptionsDisplayable*ySeperation)) return -1;
+
+  int cy = y - 5;
+
+  int selected=cy/ySeperation;
+  if (y<5) selected=-1;
+  if (selected> ((int)numOptionsDisplayable)) return -1;
+  /* Important: should be the same algorithm used in draw! */
+  if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
+  if (selectedOption == ((UINT)topOption - 1)) topOption--;
+  // if still not visible...
+  if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
+  {
+    topOption = selectedOption - (numOptionsDisplayable / 2);
+  }
+
+  if (topOption < 0) topOption = 0;
+
+  if ((selected+topOption >= (int) options.size()) ||
+      (selected + topOption < 0)) return -1;
+
+  return selected + topOption;
+}
index 06ed6d9c89a5d5cb2cbdaf1cef41aa445eafaa53..a39a52a720af304e6474004e932bd6d73cf1444b 100644 (file)
@@ -64,8 +64,12 @@ class WSelectList : public Widget
     void hintSetCurrent(int index);
     void hintSetTop(int index);
 
+    virtual bool mouseMove(int x, int y);
+    virtual bool mouseLBDOWN(int x, int y);
+
   private:
     void drawOptionLine(char* text, int xpos, int ypos, Colour& colour);
+    int getMouseLine(int x, int y);
 
     vector<wsloption> options;
     UINT selectedOption;