From 104369207661d152bb502125b4e1223ea360fec1 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 27 Dec 2006 23:13:50 +0000 Subject: [PATCH] Mouse support (part 1) --- message.h | 2 ++ mtdmvp.cc | 2 +- vaudioselector.cc | 31 +++++++++++++++++ vaudioselector.h | 1 + vchannellist.cc | 32 ++++++++++++++++++ vchannellist.h | 1 + vepg.cc | 85 +++++++++++++++++++++++++++++++++++++++++++++++ vepg.h | 1 + viewman.cc | 8 +++++ wbutton.cc | 21 ++++++++++++ wbutton.h | 3 ++ widget.cc | 10 ++++++ widget.h | 2 ++ woptionbox.cc | 21 ++++++++++++ woptionbox.h | 3 ++ wselectlist.cc | 55 ++++++++++++++++++++++++++++-- wselectlist.h | 4 +++ 17 files changed, 279 insertions(+), 3 deletions(-) diff --git a/message.h b/message.h index 4c98b99..a323b23 100644 --- 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 diff --git a/mtdmvp.cc b/mtdmvp.cc index 28a9432..0860a16 100644 --- 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; diff --git a/vaudioselector.cc b/vaudioselector.cc index a277d8b..d44dff5 100644 --- a/vaudioselector.cc +++ b/vaudioselector.cc @@ -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; + } +} diff --git a/vaudioselector.h b/vaudioselector.h index 1904b53..d6aebef 100644 --- a/vaudioselector.h +++ b/vaudioselector.h @@ -56,6 +56,7 @@ class VAudioSelector : public View ~VAudioSelector(); int handleCommand(int command); + void processMessage(Message* m); void draw(); private: diff --git a/vchannellist.cc b/vchannellist.cc index 9da042d..424a886 100644 --- a/vchannellist.cc +++ b/vchannellist.cc @@ -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 diff --git a/vchannellist.h b/vchannellist.h index 13c747e..a0b2cbd 100644 --- a/vchannellist.h +++ b/vchannellist.h @@ -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 cdd783f..d60f194 100644 --- 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 27f8e9f..35a58c8 100644 --- 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; diff --git a/viewman.cc b/viewman.cc index 7b017aa..9b03c63 100644 --- a/viewman.cc +++ b/viewman.cc @@ -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) diff --git a/wbutton.cc b/wbutton.cc index 5e7c69c..e638c9a 100644 --- a/wbutton.cc +++ b/wbutton.cc @@ -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; +} diff --git a/wbutton.h b/wbutton.h index a76f77e..14461aa 100644 --- 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; diff --git a/widget.cc b/widget.cc index dc332c3..757ce56 100644 --- 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; +} diff --git a/widget.h b/widget.h index c572009..a2d01bb 100644 --- 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: diff --git a/woptionbox.cc b/woptionbox.cc index 65c3b4f..be1b5d2 100644 --- a/woptionbox.cc +++ b/woptionbox.cc @@ -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; +} diff --git a/woptionbox.h b/woptionbox.h index 6ef0514..3e4261b 100644 --- a/woptionbox.h +++ b/woptionbox.h @@ -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; diff --git a/wselectlist.cc b/wselectlist.cc index 21b6d98..c01eff7 100644 --- a/wselectlist.cc +++ b/wselectlist.cc @@ -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; +} diff --git a/wselectlist.h b/wselectlist.h index 06ed6d9..a39a52a 100644 --- a/wselectlist.h +++ b/wselectlist.h @@ -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 options; UINT selectedOption; -- 2.39.2