Exemplo n.º 1
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.º 2
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();
		}
	}