00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "stdafx.h"
00024 #include "VTPlayerOutputAgent.h"
00025 #include <VTPDynamicIcon.h>
00026 #include "ReachinMicoleApplication.h"
00027
00028 #include <string>
00029 #include <vector>
00030
00031 using namespace std;
00032
00033
00034 vector<string> explodestr(string& delimiter,std::string& input)
00035 {
00036 vector<string> result;
00037 unsigned int ndxS=0, ndxE;
00038 do
00039 {
00040 if ((ndxE = (unsigned int)(input.find(delimiter, ndxS))) == -1)
00041 ndxE = (unsigned int)(input.length());
00042 result.push_back(input.substr(ndxS,ndxE-ndxS));
00043 ndxS = ndxE + delimiter.length();
00044 }while (ndxS < (unsigned int)(input.length()));
00045
00046 return result;
00047 }
00048
00049
00050 VTPlayerOutputAgent::VTPlayerOutputAgent()
00051 : MicoleAgent("VTPlayerOutputAgent","OutputAgent"), _left(new VTPStaticIcon(4,4)), _right(new VTPStaticIcon(4,4)), _sN(new VTPStaticIcon(4,4)), _sS(new VTPStaticIcon(4,4)), _sE(new VTPStaticIcon(4,4)), _sW(new VTPStaticIcon(4,4)), _sNE(new VTPStaticIcon(4,4)), _sNW(new VTPStaticIcon(4,4)), _sSE(new VTPStaticIcon(4,4)), _sSW(new VTPStaticIcon(4,4))
00052 {
00053 bindMessage( "^OUT VTP : (.*)=\\((.*)\\);$", BUS_CALLBACK_OF(VTPlayerOutputAgent, handleStatic ));
00054 bindMessage( "^OUT VTP : (.*)=\\((.*)\\); dur=(.*);$", BUS_CALLBACK_OF(VTPlayerOutputAgent, handleDynamic ));
00055 bindMessage( "^OUT VTP : dir=(.*); type=(.*); cell=(.*);$", BUS_CALLBACK_OF(VTPlayerOutputAgent, handleDirection ));
00056 _vtpctrl = VTPMouseController::getInstance();
00057 _vtpctrl->run();
00058
00059
00060 _sN->setXY(0, 0, '1');
00061 _sN->setXY(1, 0, '1');
00062 _sN->setXY(2, 0, '1');
00063 _sN->setXY(3, 0, '1');
00064
00065 _sS->setXY(0, 3, '1');
00066 _sS->setXY(1, 3, '1');
00067 _sS->setXY(2, 3, '1');
00068 _sS->setXY(3, 3, '1');
00069
00070 _sE->setXY(0, 0, '1');
00071 _sE->setXY(0, 1, '1');
00072 _sE->setXY(0, 2, '1');
00073 _sE->setXY(0, 3, '1');
00074
00075 _sW->setXY(3, 0, '1');
00076 _sW->setXY(3, 1, '1');
00077 _sW->setXY(3, 2, '1');
00078 _sW->setXY(3, 3, '1');
00079
00080 _sNE->setXY(1, 0, '1');
00081 _sNE->setXY(2, 0, '1');
00082 _sNE->setXY(3, 0, '1');
00083 _sNE->setXY(3, 1, '1');
00084 _sNE->setXY(3, 2, '1');
00085
00086 _sNW->setXY(1, 3, '1');
00087 _sNW->setXY(2, 3, '1');
00088 _sNW->setXY(3, 3, '1');
00089 _sNW->setXY(3, 2, '1');
00090 _sNW->setXY(3, 1, '1');
00091
00092 _sSE->setXY(0, 1, '1');
00093 _sSE->setXY(0, 2, '1');
00094 _sSE->setXY(0, 3, '1');
00095 _sSE->setXY(1, 3, '1');
00096 _sSE->setXY(2, 3, '1');
00097
00098 _sSW->setXY(3, 1, '1');
00099 _sSW->setXY(3, 2, '1');
00100 _sSW->setXY(3, 3, '1');
00101 _sSW->setXY(2, 3, '1');
00102 _sSW->setXY(1, 3, '1');
00103 }
00104
00105 VTPlayerOutputAgent::~VTPlayerOutputAgent()
00106 {
00107 delete _left;
00108 delete _right;
00109 delete _vtpctrl;
00110
00111 }
00112
00113 void VTPlayerOutputAgent::handleStatic(MicoleBus *app, int argc, const char **argv)
00114 {
00115 VTPStaticIcon newIcon = VTPStaticIcon(4,4);
00116
00117 if (argc >= 1)
00118 {
00119 const char * pChar = argv[1];
00120 if (strlen(argv[1]) >= 16)
00121 {
00122 for (int j = 0; j < 4; j++)
00123 {
00124 for (int i = 0; i < 4; i++)
00125 {
00126 newIcon.setXY(i, j, *pChar);
00127 pChar++;
00128 }
00129 }
00130 }
00131 }
00132
00133 if (!strcmp(argv[0],"left"))
00134 _vtpctrl->setLeftIcon(&newIcon);
00135 else
00136 _vtpctrl->setRightIcon(&newIcon);
00137 }
00138
00139
00140 void VTPlayerOutputAgent::handleDynamic(MicoleBus *app, int argc, const char **argv)
00141 {
00142 VTPDynamicIcon ico = VTPDynamicIcon(atof(argv[2]));
00143 VTPStaticIcon frame = VTPStaticIcon(4,4);
00144
00145 string iconsList = string(argv[1]);
00146
00147 vector<string> arr = explodestr(string(","), iconsList);
00148
00149 for (unsigned int k = 0; k < arr.size(); k++)
00150 {
00151 const char * pChar = arr[k].c_str();
00152 if (strlen(arr[k].c_str()) >= 16)
00153 {
00154 for (int j=0; j<4; j++)
00155 {
00156 for (int i=0; i<4; i++)
00157 {
00158 frame.setXY(i,j,*pChar);
00159 pChar++;
00160 }
00161 }
00162 }
00163 ico.add(frame);
00164 }
00165
00166 if (!strcmp(argv[0],"left"))
00167 _vtpctrl->setLeftIcon(&ico);
00168 else
00169 _vtpctrl->setRightIcon(&ico);
00170 }
00171
00172
00173
00174 void VTPlayerOutputAgent::handleDirection ( MicoleBus *app, int argc, const char **argv )
00175 {
00176 if (argc < 3)
00177 return;
00178
00179
00180 VTPStaticIcon *tobedisplayed = NULL;
00181
00182 if (strcmp(argv[0], "N") == 0)
00183 tobedisplayed = _sN;
00184 else if (strcmp(argv[0], "S") == 0)
00185 tobedisplayed = _sS;
00186 else if (strcmp(argv[0], "E") == 0)
00187 tobedisplayed = _sE;
00188 else if (strcmp(argv[0], "W") == 0)
00189 tobedisplayed = _sW;
00190 else if (strcmp(argv[0], "NE") == 0)
00191 tobedisplayed = _sNE;
00192 else if (strcmp(argv[0], "NW") == 0)
00193 tobedisplayed = _sNW;
00194 else if (strcmp(argv[0], "SE") == 0)
00195 tobedisplayed = _sSE;
00196 else if (strcmp(argv[0], "SW") == 0)
00197 tobedisplayed = _sSW;
00198 if (!tobedisplayed)
00199 return;
00200
00201 if (strcmp(argv[2], "right") == 0)
00202 _vtpctrl->setRightIcon(tobedisplayed);
00203 else if (strcmp(argv[2], "left") == 0)
00204 _vtpctrl->setLeftIcon(tobedisplayed);
00205 }