Exemplo n.º 1
0
	/**
	 *  \brief Draw, Call back from the GLMoblet.
	 */
	void draw()
	{
		mDTime.tick(); // update delta time ticker. our fps timer (resets for every tick call)
		MoGraph::Scene &scene = mGraph->getScene();	// get scene information
		const int iGridZ = scene.getGridZ(); // need to be able to read the grid size
		const int iGridX = scene.getGridX();
		const int sz = iGridX * iGridZ;

		mGraph->setValues(mTables,sz); // set the value array to the Graph to read from
		mGraph->setColors(mColors,sz); // set the color array to the Graph to read from

		mGraph->draw(); // Draw the whole graph system


		// DRAW ADDITIONAL TEXT ON SCREEN (Orthogonal projections)
		//---------------------------------------------------------------------
		glm::vec4 col(1.0f,1.0f,1.0f,1.0f);	// White color
		glm::vec3 pos(0.0f,0.0f,10.0f); // set screen position upper left corner 0,0.. note need z depth value for order.
		float sy = (0.6f*(float)scene.getWidth())/320.0f; // scale size regardless to resolution our reference resolution is 320..
		mText.setScale(sy,sy);

		char buf[64]; // create text string
		sprintf ( buf, "FPS=%.2f ms=%d",mDTime.currentFps(),mDTime.getElapsed());
		mText.drawText(buf,pos,col); // call drawText
	}
Exemplo n.º 2
0
	/**
	 *  \brief Draw, Call back from the GLMoblet.
	 */
	void draw()
	{
		mDTime.tick(); // update delta time ticker. our fps timer (resets for every tick call)
		MoGraph::Scene &scene = mGraph->getScene();	// get scene information
		const int iGridZ = scene.getGridZ(); // need to be able to read the grid size
		const int iGridX = scene.getGridX();
		const int sz = iGridX * iGridZ;
		float dt = static_cast<float>(mDTime.getElapsed())*0.001f; // calculate a delta time factor for omega
		mOmega += dt; // accumulate the omega used for sin/cos func

		if (mOmega > M_PI*2.0f)	// for high precision make sure omega 0..2*PI
			mOmega -= M_PI*2.0f; // wrapping a x value is also faster not to use large values in sin(x).

		const float f = 2.5f/255.0f; // prepare for a scale value of result being max 2.5f
		for(int j=0; j<iGridZ; j++)	// Build the data arrays for colors and for tables.
		{
			const float jcos = 2.0f + cos(j*0.3f+mOmega); // calculate the Depth Wave with cos
			for(int i=0; i<iGridX; i++)
			{
				const int id 	= j*iGridX+i;
				Color *c 		= (Color *)&mLogoH.getData()[id];
				mTables[id] 	= (float)c->r * f + (sin(i*0.3f+mOmega) + jcos); // generate a sine wave and add depth wave
			}
		}

		mGraph->setValues(mTables,sz); // set the value array to the Graph to read from
		mGraph->setColors(mColors,sz); // set the color array to the Graph to read from

		mGraph->draw();	// Draw the whole graph system


		// DRAW ADDITIONAL TEXT ON SCREEN (Orthogonal projections)
		//---------------------------------------------------------------------
		glm::vec4 col(1.0f,1.0f,1.0f,1.0f);	// White color
		glm::vec3 pos(0.0f,0.0f,10.0f);	// set screen position upper left corner 0,0.. note need z depth value for order.
		float sy = (0.6f*(float)scene.getWidth())/320.0f; // scale size regardless to resolution our reference resolution is 320..
		mText.setScale(sy,sy);

		char buf[64]; // create text string
		sprintf ( buf, "FPS=%.2f ms=%d",mDTime.currentFps(),mDTime.getElapsed());
		mText.drawText(buf,pos,col); // call drawText
	}
Exemplo n.º 3
0
	void updateTextColumns(std::vector<std::string> &tableName, bool bIsSuccess)
	{
		MoGraph::Scene &scene = mGraph->getScene();	// get scene information
		std::vector<MoGraph::Text> &textArray = scene.getTextMgr().getTextArray(); // get text array

		if (bIsSuccess == true)
		{
			textArray[0].mColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
			textArray[0].mText = "NASDAQ:" + mDateTime;
			if (mTextUpdated == false)
			{
				const float scale = 0.7f*scene.getScaleFactor();
				const float cx = scene.getCx(); // need to be able to read the grid size
				const float cz = scene.getCz();
				const int gridX = scene.getGridX();

				for(int i = 0; i < gridX; i++)
				{
					MoGraph::Text text; // use a working text struct for building new text items.
					text.mColor = glm::vec4(1.0f,1.0f,1.0f,1.0f);
					text.mPos = glm::vec3(cx+i*1.0f,0.0f,cz);
					text.mText = tableName[i]; // add parsed name of the share
					text.mRotate = glm::vec3(0.0f,0.0f,0.0f);
					text.mScale = glm::vec2(scale,scale);
					text.mTextFlagX = MoGraph::Text::CENTER_LEFT;
					text.mTextFlagY = MoGraph::Text::CENTER_TOP;

					textArray.push_back(text); // add text item to the back of the text rendering array
				}
				mTextUpdated = true;
			}
		}
		else // failed connection, we provide user with fail msg and redish if the text
		{
			textArray[0].mColor = glm::vec4(175.0f/255.0f, 64.0f/255.0f, 0.0f, 1.0f);
			textArray[0].mText = "Connection Failed!";
		}
	}
Exemplo n.º 4
0
	/**
	 * init call backed from GLMoblet
	 */
	void init()
	{
		/*
		 * Graph object needs to be allocated and then initiated,
		 * Font is a separate system but is required in the graph for rendering text in 3D
		 * RenterText is an independent text renderer flat on screen. but very same class is being used in Graph as well
		 * can handle both orthogonal projection see drawText and drawText3D
		 */

		mWidth 		= (int)(EXTENT_X(maGetScrSize())); // Screen Resolution
		mHeight 	= (int)(EXTENT_Y(maGetScrSize()));
		mGraph 		= new MoGraph::Graph(); // Create MoGraph::Graph class
		mFont 		= new BMFont(); // Create Font class

		// Initiate the RenderText system that will be used in Graph
		std::vector<MAHandle> fontTexArray;
		fontTexArray.push_back(R_BOX_TEXTURE);

		mFont->Init(R_BOX_FNT, fontTexArray); // Initiate font where to get its resources (.fnt) file generated from BMFont and the bitmap texture that contains the aphabet
		mText.init(mWidth,mHeight,mFont); // initiate the text system by setting a Font & Screen dimensions

		mDTime.setDesiredFps(50.0f); // set up the DTime used for calculating FPS
		setPreferredFramesPerSecond(50); // set preferred fps for the Moblet

		// initiate Graph by setting up a grid sz in X & Z ,
		// also grid in Y with grid step,
		// additional info like fit to screen, screen resolutions.

		MoGraph::GraphDesc desc;

		desc.scrWidth = mWidth; // screen width
		desc.scrHeight = mHeight; // screen height
		desc.gridX = 32; // amount of bars in X axis
		desc.gridZ = 32; // amount of bars in Z axis (depth)
		desc.gridYLines = 0; // amount of horisontal lines to be displayed in graph
		desc.gridStepYLines = 1.0f; // the step Y position between the lines
		desc.gridStepValue = 1.0f; // the step value for the displayed numbers for line
		desc.gridDecimals = 1; // use amount of decimals e.g 0="1", 1="1.0", 2="1.00", 3="1.000" etc..
		desc.gridOffsetStartLine = -1; // offset where to start horisontal lines from requires OFFSET_GRIDS to be set. see flagGridLines enums
		desc.gridOffsetStartValue = -2.0f; // offset startin value can be other then zero, requires OFFSET_GRIDS to be set.
		desc.bFitScreen = true; // fit graph to screen (default)
		desc.flagGridLines = MoGraph::DEFAULT_GRIDS; // MoGraph::OFFSET_GRIDS .. MoGraph::MIRRORED_GRIDS;
		desc.bUseGridValue = false; // switch to turn on/off grid values
		desc.font = mFont; // use Font for text rendering in Graph such as values titles etc.

		if (!mGraph->init(&desc))
			maPanic(1,"Failed to initiate Graph");

		glm::vec4 bkcolor(0.2f, 0.2f, 0.2f, 1.0f);
		mGraph->setBGColor(bkcolor); // additional set background color

		// TEXT MANIPULATION IN GRAPH
		// Text strings in the graph has a default setup.
		// everything is built upon the Text structs that are pushed to an
		// std::vector<Text>   Text array
		// We can change the existing setup by changing the strings...
		std::vector<MoGraph::Text> &textArray = mGraph->getScene().getTextMgr().getTextArray();
		std::vector<MoGraph::Line> &lineArray = mGraph->getScene().getAxisMgr().getLineArray();
		// and we can also push new ones to the table for more text in the graph...
		// you can add as many as you please... fps issue in the end.

		// Clear any existing texts created by the graph system.
		textArray.clear();
		lineArray.clear();

		float scale = mGraph->getScene().getGridX()/500.0f;

		// create additional example text
		MoGraph::Text text;
		text.mColor 	= glm::vec4(1.0f,1.0f,1.0f,1.0f);
		text.mPos 		= glm::vec3(0.0f,10.0f,0.0f);
		text.mRotate 	= glm::vec3(0.0f,0.0f,0.0f); // Rotation in degrees
		text.mScale 	= glm::vec2(scale,scale);
		text.mTextFlagX = MoGraph::Text::CENTER_X;
		text.mText 		= "MoGraph";
		textArray.push_back(text);

		mLogo.init(R_MOSYNC_LOGO);	// load and access picture data
		mLogoH.init(R_MOSYNC_HEIGHT);

		// Prepare the colors for the Graph.
		// colors are static so we only need to build them once.
		const int iGridZ 		= desc.gridZ; // need to be able to read the grid size
		const int iGridX 		= desc.gridX;
		const int sz			= iGridX * iGridZ;

		if (mTables == 0) // check if array already is allocated
			mTables = new float[sz]; // allocate an array for set data to the Bars.
		if (mColors == 0) // check if array already is allocated
			mColors = new glm::vec4[sz]; // allocate an array for color table

		const float f = 1.0f/255.0f;
		for(int j=0; j<iGridZ; j++)	// Build the data arrays for colors and for tables.
		{
			for(int i=0; i<iGridX; i++)
			{
				const int id = j*iGridX+i;
				Color *c = (Color *)&mLogo.getData()[id];
				mColors[id]	= glm::vec4((float)c->r*f, (float)c->g*f, (float)c->b*f, 1.0f);	// set color gradients
			}
		}
	}
Exemplo n.º 5
0
	/**
	*  This function is called with a coordinate when a pointer is released.
	*/
	void multitouchReleaseEvent(MAPoint2d p, int touchId)
	{
		mGraph->getTouch().multitouchReleaseEvent(p,touchId); // just forward function to the Graphs own touch handler
	}
Exemplo n.º 6
0
	/**
	 * init call backed from GLMoblet
	 */
	void init()
	{
		/*
		 * Graph object needs to be allocated and then initiated,
		 * Font is a separate system but is required in the graph for rendering text in 3D
		 * RenterText is an independent text renderer flat on screen. but very same class is being used in Graph as well
		 * can handle both orthogonal projection see drawText and drawText3D
		 */

		int gridX = 10;
		int gridY = 4;

		mWidth = (int)(EXTENT_X(maGetScrSize()));
		mHeight = (int)(EXTENT_Y(maGetScrSize()));
		mGraph = new MoGraph::Graph(); // Create MoGraph::Graph class
		mFont = new BMFont(); // Create Font class
		mNameTable.resize(gridX * gridY);

		// Initiate the RenderText system that will be used in Graph
		std::vector<MAHandle> fontTexArray;
		fontTexArray.push_back(R_BOX_TEXTURE);

		mFont->Init(R_BOX_FNT, fontTexArray); // Initiate font where to get its resources (.fnt) file generated from BMFont and the bitmap texture that contains the aphabet
		mText.init(mWidth,mHeight,mFont); // initiate the text system by setting a Font & Screen dimensions

		mDTime.setDesiredFps(50.0f); // set up the DTime used for calculating FPS
		setPreferredFramesPerSecond(50); // set preferred fps for the Moblet

		// initiate Graph by setting up a grid sz in X & Z ,
		// also grid in Y with grid step,
		// additional info like fit to screen, screen resolutions.
		mScaleBarHeight = 0.25f;

		MoGraph::GraphDesc desc;
		desc.scrWidth = mWidth; // screen width
		desc.scrHeight = mHeight; // screen height
		desc.gridX = gridX; // amount of bars in X axis
		desc.gridZ = gridY; // amount of bars in Z axis (depth)
		desc.gridYLines = 16; // amount of horisontal lines to be displayed in graph
		desc.gridStepYLines = 0.5f; // the step Y position between the lines
		desc.gridStepValue = 0.5f/mScaleBarHeight; // the step value for the displayed numbers for line
		desc.gridDecimals = 1; // use amount of decimals e.g 0="1", 1="1.0", 2="1.00", 3="1.000" etc..
		desc.gridOffsetStartLine = -1; // offset where to start horisontal lines from requires OFFSET_GRIDS to be set. see flagGridLines enums
		desc.gridOffsetStartValue = -2.0f; // offset startin value can be other then zero, requires OFFSET_GRIDS to be set.
		desc.bFitScreen = true; // fit graph to screen (default)
		desc.flagGridLines = MoGraph::DEFAULT_GRIDS; // MoGraph::OFFSET_GRIDS .. MoGraph::MIRRORED_GRIDS;
		desc.bUseGridValue = true; // switch to turn on/off grid values
		desc.font = mFont; // use Font for text rendering in Graph such as values titles etc.

		if (!mGraph->init(&desc)) // initiates graph
			maPanic(1,"Failed to initiate Graph");

		glm::vec4 bkcolor(0.2f, 0.2f, 0.2f, 1.0f); // set background color
		mGraph->setBGColor(bkcolor); // additional set background color

		// TEXT MANIPULATION IN GRAPH
		// Text strings in the graph has a default setup.
		// everything is built upon the Text structs that are pushed to an
		// std::vector<Text>   Text array
		// We can change the existing setup by changing the strings...
		std::vector<MoGraph::Text> &textArray = mGraph->getScene().getTextMgr().getTextArray();
	//	std::vector<MoGraph::Line> &lineArray = mGraph->getScene().getAxisMgr().getLineArray();
		// and we can also push new ones to the table for more text in the graph...
		// you can add as many as you please... fps issue in the end.
		const float scale = mGraph->getScene().getScaleFactor();
		const float ss = 0.75f;
		glm::vec2 scaleAxisText = glm::vec2(scale*ss,scale*ss);

		textArray[0].mColor = glm::vec4(124.0f/255.0f, 175.0f/255.0f,	0.0f,	1.0f);
		textArray[0].mPos.y -= 0.3f;
		textArray[0].mText = "Connecting..."; // Graph title text. we also use it for connection status
		textArray[0].mTextFlagX = MoGraph::Text::CENTER_LEFT;
		textArray[0].mTextFlagY = MoGraph::Text::CENTER_TOP;
		textArray[0].mScale	= glm::vec2(scale*0.8,scale*0.8);

		textArray[1].mScale = scaleAxisText; // Y-AXIS
		textArray[1].mTextFlagX = MoGraph::Text::CENTER_X;
		textArray[1].mTextFlagY = MoGraph::Text::CENTER_TOP;

		textArray[2].mPos.x	+= 0.1f;
		textArray[2].mText = "Shares";
		textArray[2].mScale = scaleAxisText; // X-AXIS
		textArray[2].mTextFlagX = MoGraph::Text::CENTER_LEFT;
		textArray[2].mTextFlagY = MoGraph::Text::CENTER_TOP;

		textArray[textArray.size()-1].mPos.x += 0.1f;
		textArray[textArray.size()-1].mScale = scaleAxisText; // Z-AXIS (last entry before user storage! due to z being optional)
		textArray[textArray.size()-1].mTextFlagX = MoGraph::Text::CENTER_RIGHT;
		textArray[textArray.size()-1].mTextFlagY = MoGraph::Text::CENTER_TOP;

		// create additional example text

		MoGraph::Text text;
		text.mColor = glm::vec4(1.0f,1.0f,1.0f,1.0f);
		text.mPos = glm::vec3(0.0f,10.0f,0.0f);
		text.mRotate = glm::vec3(0.0f,0.0f,0.0f);		// Rotation in degrees
		text.mScale = glm::vec2(scale,scale);
		text.mTextFlagX = MoGraph::Text::CENTER_X;
		text.mText = "MoGraph";

		textArray.push_back(text);

		// Prepare the colors for the Graph.
		// colors are static so we only need to build them once.
		const int iGridZ = desc.gridZ;		// need to be able to read the grid size
		const int iGridX = desc.gridX;
		const int sz = iGridX * iGridZ;

		if (mTables == 0)					// check if array already is allocated
			mTables = new float[sz];		// allocate an array for set data to the Bars.
		if (mColors == 0)					// check if array already is allocated
			mColors = new glm::vec4[sz];	// allocate an array for color table

		for(int j=0; j<iGridZ; j++)			// Build the data arrays for colors and for tables.
		{
			for(int i=0; i<iGridX; i++)
			{
				const int id = j*iGridX+i;
				mColors[id]	= glm::vec4(0.0f, 1.0f, 1.0f, 1.0f);			// set color gradients
				mTables[id]	= 1.0f;
			}
		}

		// Start the HTTP request.
		mSharesData = NULL;
		lprintfln("@@@ MOSYNC BEFORE REQUEST");
		MAUtil::String url = "http://finance.google.com/finance/info?client=ig&q=NASDAQ:MSFT,NASDAQ:FB,NASDAQ:ERIC,NASDAQ:BBRY,NYSE:NOK,NASDAQ:YHOO,NASDAQ:INTC,NASDAQ:CSCO,NASDAQ:ORCL,NASDAQ:NVDA";

		int res = mHttp.create(url.c_str(),HTTP_GET);
		if(res < 0)
		{
			lprintfln("@@@@@@@@@@@@@@@@ unable to connect - %i\n", res);
		}
		else
		{
			mHttp.finish();
		}
	}
Exemplo n.º 7
0
	/**
	 * \brief parseJSON
	 * \note parses from mSharedData and populate the arrays such as
	 * mNameTable[], mTable[], mDataTime, mColor[]
	 */
	void parseJSON()
	{
		YAJLDom::Value *jsonRoot = YAJLDom::parse((const unsigned char*)mSharesData, strlen(mSharesData));

		if(jsonRoot->getType() == YAJLDom::Value::ARRAY)
		{
			lprintfln("SUCCESS IN PARSING JSON DATA");
			MAUtil::String tmp,t;
			float scale = mScaleBarHeight;
			const int gridX = mGraph->getScene().getGridX();
			const int gridZ	= mGraph->getScene().getGridZ();
			bool bGotDate = false;
			for(int i=0; i<gridX; i++)
			{
				YAJLDom::Value *row = jsonRoot->getValueByIndex(i);

				int j = 0;
				t = row->getValueForKey("t")->toString();
				mNameTable[i + gridX*j] = t.c_str();

				tmp = row->getValueForKey("l")->toString();
				mTables[i + gridX*j] = scale*(atof(tmp.c_str()));
				lprintfln("@@@r l=%s t=%s", tmp.c_str(),t.c_str());
				j++;

				t = row->getValueForKey("t")->toString();
				mNameTable[i + gridX*j] = t.c_str();

				tmp = row->getValueForKey("l_cur")->toString();
				mTables[i + gridX*j] = scale*(atof(tmp.c_str()));
				lprintfln("@@@ l_cur=%s t=%s", tmp.c_str(),t.c_str());
				j++;

				t = row->getValueForKey("t")->toString();
				mNameTable[i + gridX*j] = t.c_str();

				tmp = row->getValueForKey("c")->toString();
				mTables[i + gridX*j] = scale*(atof(tmp.c_str()));
				lprintfln("@@@ c=%s t=%s", tmp.c_str(),t.c_str());
				j++;

				t = row->getValueForKey("t")->toString();
				mNameTable[i + gridX*j] = t.c_str();

				tmp = row->getValueForKey("cp")->toString();
				mTables[i + gridX*j] = scale*(atof(tmp.c_str()));
				lprintfln("@@@ cp=%s t=%s", tmp.c_str(),t.c_str());

				if (bGotDate == false)
				{
					tmp = row->getValueForKey("lt")->toString();
					mDateTime = tmp.c_str();
					bGotDate = true;
				}
			}

			glm::vec4 colScheme[gridZ];
			glm::vec4 redScheme[gridZ];

			colScheme[0] = glm::vec4(0.0f, 236.0f/255.0f, 255.0f/255.0f, 1.0f);	// L blue
			colScheme[1] = glm::vec4(0.0f, 177.0f/255.0f, 191.0f/255.0f, 1.0f);	// D blue
			colScheme[2] = glm::vec4(181.0f/255.0f, 255.0f/255.0f, 0.0f, 1.0f);	// L Green
			colScheme[3] = glm::vec4(124.0f/255.0f, 175.0f/255.0f, 0.0f, 1.0f);	// D Green

			redScheme[0] = glm::vec4(255.0f/255.0f, 0.0f, 236.0f/255.0f, 1.0f);	// L blue
			redScheme[1] = glm::vec4(177.0f/255.0f, 0.0f, 191.0f/255.0f, 1.0f);	// D blue
			redScheme[2] = glm::vec4(255.0f/255.0f, 90.0f/255.0f, 0.0f, 1.0f);  // L Red
			redScheme[3] = glm::vec4(175.0f/255.0f, 64.0f/255.0f, 0.0f, 1.0f);  // D Red

			for(int j=0; j<gridZ; j++)
			{
				for(int i=0; i<gridX; i++)
				{
					const int id 	= i+gridX*j;
					mColors[id] 	= mTables[id]>=0.0f? colScheme[j]: redScheme[j];
				}
			}
		}
	}