示例#1
0
void WorldUIView::drawBg(){
	color(Color(0, 140.0/255.0, 240.0/255.0));
	drawSolidRect(Rectf(rect.x, rect.y, rect.xEnd, rect.yEnd));
}	
void CharacterCreation::render() {
	arx_assert(ARXmenu.mode() == Mode_CharacterCreation);
	
	GRenderer->Clear(Renderer::ColorBuffer);
	
	//-------------------------------------------------------------------------
	
	arx_assert(BookBackground);
	
	{
	UseRenderState state(render2D());
	
	EERIEDrawBitmap(Rectf(Vec2f(0, 0), g_size.width(), g_size.height()), 0.9f, BookBackground, Color::white);
	
	g_playerBook.stats.manageNewQuest();
		
	bool DONE = (player.Skill_Redistribute == 0 && player.Attribute_Redistribute == 0);
	
	Color color = Color::none;
	
	Rectf book = g_playerBook.getArea();
	
	Vec2f spacing = Vec2f(20.f, 30.f) * minSizeRatio();
	
	Vec2f quickGenerateButtonSize(hFontMenu->getTextSize(str_button_quickgen).size());
	Rectf quickGenerateButton(book.bottomLeft() + Vec2f(0.f, spacing.y),
	                          quickGenerateButtonSize.x, quickGenerateButtonSize.y);
	
	Vec2f doneButtonSize(hFontMenu->getTextSize(str_button_done).size());
	Rectf doneButton(book.bottomRight() + Vec2f(-doneButtonSize.x, spacing.y),
	                 doneButtonSize.x, doneButtonSize.y);
	
	Vec2f skinButtonSize(hFontMenu->getTextSize(str_button_skin).size());
	Rectf skinButton((quickGenerateButton.centerRight() + doneButton.centerLeft() - skinButtonSize) / 2.f,
	                 skinButtonSize.x, skinButtonSize.y);
	
	if(quickGenerateButton.right > skinButton.left - spacing.x) {
		quickGenerateButton.move(skinButton.left - spacing.x - quickGenerateButton.right, 0.f);
	}
	
	if(doneButton.left < skinButton.right + spacing.x) {
		doneButton.move(skinButton.right + spacing.x - doneButton.left, 0.f);
	}
	
	// Button QUICK GENERATION
	
	if(quickGenerateButton.contains(Vec2f(DANAEMouse))) {
		
		cursorSetInteraction();
		
		if(eeMousePressed1());
		else if (eeMouseUp1())
		{
			m_cheatQuickGenButtonClickCount++;
			int iSkin = player.skin;
			ARX_SOUND_PlayMenu(g_snd.MENU_CLICK);
			
			if(bQuickGenFirstClick) {
				ARX_PLAYER_MakeAverageHero();
				bQuickGenFirstClick = false;
			} else {
				ARX_PLAYER_QuickGeneration();
			}
			
			player.skin = checked_range_cast<char>(iSkin);
		}
		
		color = Color::white;
	}
	else
		color = Color(232, 204, 143);
	
	ARX_UNICODE_DrawTextInRect(hFontMenu, quickGenerateButton.topLeft(), 999999, str_button_quickgen, color);
	
	// Button SKIN
	
	if(skinButton.contains(Vec2f(DANAEMouse))) {
		cursorSetInteraction();
		
		if(eeMouseUp1()) {
			m_cheatSkinButtonClickCount++;
			ARX_SOUND_PlayMenu(g_snd.MENU_CLICK);
			player.skin++;
			
			if(player.skin > 3)
				player.skin = 0;
			
			ARX_PLAYER_Restore_Skin();
		}
		
		color = Color::white;
	}
	else
		color = Color(232, 204, 143);
	
	ARX_UNICODE_DrawTextInRect(hFontMenu, skinButton.topLeft(), 999999, str_button_skin, color);
	
	// Button DONE
	
	if(doneButton.contains(Vec2f(DANAEMouse))) {
		if(DONE)
			cursorSetInteraction();
		
		if(DONE && eeMouseUp1()) {
			if(m_cheatSkinButtonClickCount == 8 && m_cheatQuickGenButtonClickCount == 10) {
				m_cheatSkinButtonClickCount = -2;
			} else if(m_cheatSkinButtonClickCount == -1) {
				ARX_PLAYER_MakeSpHero();
				player.skin = 4;
				ARX_PLAYER_Restore_Skin();
				m_cheatSkinButtonClickCount = 0;
				SP_HEAD = 1;
			} else {
				if(SP_HEAD) {
					player.skin = 4;
					ARX_PLAYER_Restore_Skin();
					SP_HEAD = 0;
				}
				
				ARX_SOUND_PlayMenu(g_snd.MENU_CLICK);
				
				MenuFader_start(Fade_In, Mode_InGame);
			}
		} else {
			if(DONE) {
				color = Color::white;
			} else {
				color = Color::gray(0.75f);
			}
		}
	} else {
		if(DONE) {
			color = Color(232, 204, 143);
		} else {
			color = Color::gray(0.75f);
		}
	}
	
	if(m_cheatSkinButtonClickCount < 0) {
		color = Color::magenta;
	}
	
	ARX_UNICODE_DrawTextInRect(hFontMenu, doneButton.topLeft(), 999999, str_button_done, color);
	}
	
	EERIE_LIGHT * light = lightHandleGet(torchLightHandle);
	light->pos.x = 0.f + GInput->getMousePosition().x - (g_size.width() >> 1);
	light->pos.y = 0.f + GInput->getMousePosition().y - (g_size.height() >> 1);
	
	if(pTextManage) {
		pTextManage->Update(g_platformTime.lastFrameDuration());
		pTextManage->Render();
	}
	
	ARX_INTERFACE_RenderCursor(true);
	
	if(MenuFader_process()) {
		if(iFadeAction == Mode_InGame) {
			ARX_MENU_NEW_QUEST_Clicked_QUIT();
			MenuFader_reset();
			if(pTextManage) {
				pTextManage->Clear();
			}
		}
	}
	
}
示例#3
0
 void add(const Rectf& rect, const C& c)
 {
   if (m_depth > 8) // FIXME: max_depth shouldn't be hardcode
   {
     Object obj;
     obj.rect = rect;
     obj.data = c;
     m_items.push_back(obj);
   }
   else
   {
     if (rect.right < m_center.x) // west
     {
       if (rect.bottom < m_center.y) // north
       {
         if (!m_nw.get())
         {
           m_nw.reset(new QuadTreeNode(m_depth+1, Rectf(m_bounding_rect.left, m_bounding_rect.top,
                                                        m_center.x, m_center.y)));
         }
         m_nw->add(rect, c);
       }
       else if(rect.top > m_center.y)  // south
       {
         if (!m_sw.get())
         {
           m_sw.reset(new QuadTreeNode(m_depth+1, Rectf(m_bounding_rect.left, m_center.y,
                                                        m_center.x, m_bounding_rect.bottom)));
         }
         m_sw->add(rect, c);
       }
       else
       {
         Object obj;
         obj.rect = rect;
         obj.data = c;
         m_items.push_back(obj);
       }
     }
     else if (rect.left > m_center.x) // east
     {
       if (rect.bottom < m_center.y) // north
       {
         if (!m_ne.get())
         {
           m_ne.reset(new QuadTreeNode(m_depth+1, Rectf(m_center.x, m_bounding_rect.top,
                                                        m_bounding_rect.right, m_center.y)));
         }
         m_ne->add(rect, c);
       }
       else if(rect.top > m_center.y) // south
       {
         if (!m_se.get())
         {
           m_se.reset(new QuadTreeNode(m_depth+1, Rectf(m_center.x, m_center.y,
                                                        m_bounding_rect.right, m_bounding_rect.bottom)));
         }
         m_se->add(rect, c);
       }
       else
       {
         Object obj;
         obj.rect = rect;
         obj.data = c;
         m_items.push_back(obj);
       }
     }
     else
     {
       Object obj;
       obj.rect = rect;
       obj.data = c;
       m_items.push_back(obj);
     }
   }
 }
示例#4
0
//-----------------------------------------------------------------------------
// ARX Menu Rendering Func
// returns false if no menu needs to be displayed
//-----------------------------------------------------------------------------
bool ARX_Menu_Render() {
	
	if(ARXmenu.currentmode == AMCM_OFF)
		return false;

	bool br = Menu2_Render();

	if(br)
		return br;

	if(ARXmenu.currentmode == AMCM_OFF)
		return false;


	GRenderer->Clear(Renderer::ColorBuffer | Renderer::DepthBuffer);
	
	FLYING_OVER = 0;

	//-------------------------------------------------------------------------

	if(ARXmenu.currentmode == AMCM_NEWQUEST && ARXmenu.mda) {
		
		GRenderer->SetRenderState(Renderer::Fog, false);
		GRenderer->SetRenderState(Renderer::AlphaBlending, false);

		if(ARXmenu.mda->BookBackground != NULL) {
			GRenderer->SetRenderState(Renderer::AlphaBlending, false);
			GRenderer->SetRenderState(Renderer::Fog, false);
			GRenderer->SetRenderState(Renderer::DepthWrite, false);
			GRenderer->SetRenderState(Renderer::DepthTest, false);

			EERIEDrawBitmap2(Rectf(Vec2f(0, 0), g_size.width(), g_size.height()), 0.9f, ARXmenu.mda->BookBackground, Color::white);
		}

		BOOKZOOM = 1;

		ARX_INTERFACE_ManageOpenedBook();


		if(ARXmenu.mda) {
			long DONE = 0;

			if(player.Skill_Redistribute == 0 && player.Attribute_Redistribute == 0)
				DONE = 1;
			
			if(!ARXmenu.mda->flyover[FLYING_OVER].empty() ) //=ARXmenu.mda->flyover[FLYING_OVER];
			{
				if(FLYING_OVER != OLD_FLYING_OVER) {

					float fRandom = rnd() * 2;

					int t = checked_range_cast<int>(fRandom);

					pTextManage->Clear();
					OLD_FLYING_OVER = FLYING_OVER;
					UNICODE_ARXDrawTextCenteredScroll(hFontInGame,
						(g_size.width() * 0.5f),
						12,
						(g_size.center().x) * 0.82f,
						ARXmenu.mda->flyover[FLYING_OVER],
						Color(232 + t, 204 + t, 143 + t),
						1000,
						0.01f,
						2);
				}
			} else {
				OLD_FLYING_OVER = -1;
			}
			
			Vec2f pos;
			pos.x = 0;
			pos.y = 313 * g_sizeRatio.y + (g_size.height() - 313 * g_sizeRatio.y) * 0.70f;
			
			Vec2f size = g_sizeRatio;
			size *= 100;
			
			Color color = Color::none;

			//---------------------------------------------------------------------
			// Button QUICK GENERATION
			pos.x = (g_size.width() - (513 * g_sizeRatio.x)) * 0.5f;
			
			const Rectf quickGenerateButtonMouseTestRect(
				pos,
				size.x,
				size.y
			);
			
			if(quickGenerateButtonMouseTestRect.contains(Vec2f(DANAEMouse))) {
				SpecialCursor = CURSOR_INTERACTION_ON;
				FLYING_OVER = BUTTON_QUICK_GENERATION;

				if(eeMousePressed1());
				else if (eeMouseUp1())
				{
					QUICK_MOD++;
					int iSkin = player.skin;
					ARX_SOUND_PlayMenu(SND_MENU_CLICK);

					if(bQuickGenFirstClick) {
						ARX_PLAYER_MakeAverageHero();
						bQuickGenFirstClick = false;
					} else {
						ARX_PLAYER_QuickGeneration();
					}

					player.skin = checked_range_cast<char>(iSkin);
				}

				color = Color(255, 255, 255);
			}
			else
				color = Color(232, 204, 143);

			pTextManage->AddText(hFontMenu, ARXmenu.mda->str_button_quickgen, static_cast<long>(pos.x), static_cast<long>(pos.y), color);

			//---------------------------------------------------------------------
			// Button SKIN
			pos.x = g_size.width() * 0.5f;
			
			const Rectf skinButtonMouseTestRect(
				pos,
				size.x,
				size.y
			);
			
			if(skinButtonMouseTestRect.contains(Vec2f(DANAEMouse))) {
				SpecialCursor = CURSOR_INTERACTION_ON;
				FLYING_OVER = BUTTON_SKIN;

				if(eeMouseUp1()) {
					SKIN_MOD++;
					BOOKZOOM = 1;
					ARX_SOUND_PlayMenu(SND_MENU_CLICK);
					player.skin++;

					if(player.skin > 3)
						player.skin = 0;

					ARX_PLAYER_Restore_Skin();
				}

				color = Color(255, 255, 255);
			}
			else
				color = Color(232, 204, 143);

			pTextManage->AddText(hFontMenu, ARXmenu.mda->str_button_skin, static_cast<long>(pos.x), static_cast<long>(pos.y), color);

			//---------------------------------------------------------------------
			// Button DONE
			pos.x = g_size.width() - (g_size.width() - 513 * g_sizeRatio.x) * 0.5f - 40 * g_sizeRatio.x;
			
			const Rectf doneButtonMouseTestRect(
				pos,
				size.x,
				size.y
			);
			
			if(doneButtonMouseTestRect.contains(Vec2f(DANAEMouse))) {
				if(DONE)
					SpecialCursor = CURSOR_INTERACTION_ON;

				FLYING_OVER = BUTTON_DONE;

				if(DONE && eeMouseUp1()) {
					if(SKIN_MOD == 8 && QUICK_MOD == 10) {
						SKIN_MOD = -2;
					} else if(SKIN_MOD == -1) {
						ARX_PLAYER_MakeSpHero();
						player.skin = 4;
						ARX_PLAYER_Restore_Skin();
						SKIN_MOD = 0;
						SP_HEAD = 1;
					} else {
						if(SP_HEAD) {
							player.skin = 4;
							ARX_PLAYER_Restore_Skin();
							SP_HEAD = 0;
						}

						ARX_SOUND_PlayMenu(SND_MENU_CLICK);

						bFadeInOut = true;		//fade out
						bFade = true;			//active le fade
						iFadeAction = AMCM_OFF;
					}
				} else {
					if(DONE)
						color = Color(255, 255, 255);
					else
						color = Color(192, 192, 192);
				}
			} else {
				if(DONE)
					color = Color(232, 204, 143);
				else
					color = Color(192, 192, 192);
			}

			if(SKIN_MOD < 0)
				color = Color(255, 0, 255);

			pTextManage->AddText(hFontMenu, ARXmenu.mda->str_button_done, static_cast<long>(pos.x), static_cast<long>(pos.y), color);
		}
	}

	EERIE_LIGHT * light = lightHandleGet(torchLightHandle);
	light->pos.x = 0.f + GInput->getMousePosAbs().x - (g_size.width() >> 1);
	light->pos.y = 0.f + GInput->getMousePosAbs().y - (g_size.height() >> 1);

	if(pTextManage) {
		pTextManage->Update(framedelay);
		pTextManage->Render();
	}

	if(ARXmenu.currentmode != AMCM_CREDITS)
		ARX_INTERFACE_RenderCursor(true);

	if(ARXmenu.currentmode == AMCM_NEWQUEST) {
		if(ProcessFadeInOut(bFadeInOut, 0.1f)) {
			switch(iFadeAction) {
				case AMCM_OFF:
					arxtime.resume();
					ARX_MENU_NEW_QUEST_Clicked_QUIT();
					iFadeAction = -1;
					bFade = false;
					fFadeInOut = 0.f;

					if(pTextManage)
						pTextManage->Clear();

					break;
			}
		}
	}

	return true;
}
示例#5
0
 Rectf grown(float border) const
 {
   return Rectf(p1.x - border, p1.y - border,
                p2.x + border, p2.y + border);
 }
	DataBuffer CursorProvider_Win32::create_ico_file(const PixelBuffer &image)
	{
		return create_ico_helper(image, Rectf(image.get_size()), 1, Point(0, 0));
	}
 Rectf get_bbox() const
 { return Rectf(get_tile_position(0, 0), get_tile_position(width, height)); }
示例#8
0
void ButtonWidget::SetPos(Vec2f pos) {
	
	Vec2f scaledSize = RATIO_2(m_size);
	m_rect = Rectf(pos, scaledSize.x, scaledSize.y);
}
示例#9
0
void Text::ensureGeometryUpdates() const {
	if (!mGeometryNeedsUpdate) {
		return;
	}

	mGeometryNeedsUpdate = false;

	mVertices.clear();
	mBounds = Rectf();

	if (!mFont) {
		return;
	}

	if (mString.isEmpty()) {
		return;
	}

	bool bold				 = (mStyle & Bold) != 0;
	bool underlined			 = (mStyle & Underlined) != 0;
	bool strikeThrough		 = (mStyle & StrikeThrough) != 0;
	float italic			 = (mStyle & Italic) ? 0.208f : 0.f;
	float underlineOffset	 = mFont->getUnderlinePosition(mCharSize);
	float underlineThickness = mFont->getUnderlineThickness(mCharSize);

	Rectf xBounds = mFont->getGlyph(L'x', mCharSize, bold).bounds;
	float strikeThroughOffset = xBounds.top + xBounds.height / 2.f;

	float hspace = staticCastf(mFont->getGlyph(L'', mCharSize, bold).advance);
	float vspace = staticCastf(mFont->getLineSpacing(mCharSize));
	float x		 = 0.f;
	float y		 = staticCastf(mCharSize);

	float minX = staticCastf(mCharSize);
	float minY = staticCastf(mCharSize);
	float maxX = 0.f;
	float maxY = 0.f;
	uint32 prevChar = 0;
	bool expextClosingBracket = false;
	Color color = mColor;

	uint32 foundWordEndPos = 0;
	bool wordFound = false;

	for (sizeT i = 0; i < mString.getSize(); ++i) {
		uint32 currChar = mString[i];
		if (i != 0) {
			prevChar = mString[i - 1];
		}

		uint32 nextChar = 0;
		if (i < mString.getSize()) {
			nextChar = mString[i + 1];
		}

		x += staticCastf(mFont->getKerning(prevChar, currChar, mCharSize));

		if (underlined && (currChar == L'\n')) {
			float top     = std::floor(y + underlineOffset - (underlineThickness / 2) + 0.5f);
			float botttom = top + std::floor(underlineThickness + 0.5f);

			mVertices.append(Vertex(Vector2f(0, top),	  mColor, Vector2f(1, 1)));
			mVertices.append(Vertex(Vector2f(x, top),	  mColor, Vector2f(1, 1)));
			mVertices.append(Vertex(Vector2f(0, botttom), mColor, Vector2f(1, 1)));
			mVertices.append(Vertex(Vector2f(0, botttom), mColor, Vector2f(1, 1)));
			mVertices.append(Vertex(Vector2f(x, top),     mColor, Vector2f(1, 1)));
			mVertices.append(Vertex(Vector2f(x, botttom), mColor, Vector2f(1, 1)));
		}

		if (strikeThrough && (currChar == L'\n')) {
			float top     = std::floor(y + strikeThroughOffset - (underlineThickness / 2) + 0.5f);
			float botttom = top + std::floor(underlineThickness + 0.5f);

			mVertices.append(Vertex(Vector2f(0, top),	  mColor, Vector2f(1, 1)));
			mVertices.append(Vertex(Vector2f(x, top),	  mColor, Vector2f(1, 1)));
			mVertices.append(Vertex(Vector2f(0, botttom), mColor, Vector2f(1, 1)));
			mVertices.append(Vertex(Vector2f(0, botttom), mColor, Vector2f(1, 1)));
			mVertices.append(Vertex(Vector2f(x, top),     mColor, Vector2f(1, 1)));
			mVertices.append(Vertex(Vector2f(x, botttom), mColor, Vector2f(1, 1)));
		}

		if (currChar == ' ' || currChar == '\t' || currChar == '\n') {
			minX = std::min(minX, x);
			minY = std::min(minY, y);

			switch (currChar) {
				case ' ': {
					x += hspace;
				} break;

				case '\t': {
					x += hspace * 4;
				} break;
					
				case '\n': {
					y += vspace;
					x = 0;
				} break;
			}

			maxX = std::max(maxX, x);
			maxY = std::max(maxY, y);

			continue;
		}
		//*
		if (mDoMultiColor) {
			if (currChar == '[' && prevChar != '\\') {
				String str = "";
					
				while (currChar != ']') {
					currChar = mString[++i];
					if (currChar != ']') {
						str += currChar;
					}
				}
	
				if (str == "red") {
					color = Color::Red;
				} else if (str == "blue") {
					color = Color::Blue;
				} else if (str == "white") {
					color = Color::White;
				} else if (str == "black") {
					color = Color::Black;
				} else if (str == "green") {
					color = Color::Green;
				} else if (str == "yellow") {
					color = Color::Yellow;
				} else if (str == "Magenta") {
					color = Color::Magenta;
				} else if (str == "cyan") {
					color = Color::Cyan;
				} else if (str == "transparent") {
					color = Color::Transparent;
				} else {
					if (str.contains(',')) {
						String newColorStr[4];
	
						for (uint32 k = 0; k <= 3; ++k) {
							newColorStr[k] = "255";
						}
	
						if (isdigit(str[0])) {
							newColorStr[0] = "";
						}
	
						uint c = 0;
	
						for (uint32 j = 0; j < str.getLength(); ++j) {
							if (isdigit(str[j]) && c <= 3) {
								newColorStr[c] += str[j];
							} else if (str[j] == ',') {
								++c;
								if (j != str.getLength() - 1) {
									newColorStr[c] = "";
								}
							}
						}
	
						color = Color(newColorStr[0].toUint8(), 
									  newColorStr[1].toUint8(), 
									  newColorStr[2].toUint8(), 
									  newColorStr[3].toUint8());
					} else {
						color = mColor;
					}
				}

				continue;
			}
		} else { //Does not cause open file slowdown.
			uint32 wordWidth = 0;
			String word = mString.nextWord(i, wordWidth);

			if (!wordFound) {
				color = mColor;
			}

			if (mString.startsWith("#", true)) {
				color = Color(142, 192,  124);
				foundWordEndPos = mString.getLength();
				wordFound = true;
			} else if (mString.startsWith("//", true) || mString.startsWith("--", true)) {
				color = Color(146, 131, 116);
				foundWordEndPos = mString.getLength();
				wordFound = true;
			}/* else if (word == "uint32" || word == "int" || word == "float" || word == "char" || word == "void") {
				color = Color(242, 189, 47);
				foundWordEndPos = --wordWidth;
				wordFound = true;
			} else if (word == "if" || word == "else" || word == "return" || word == "for" || word == "break" 
				|| word == "switch" || word == "case" || word == "while" || word == "continue" || word =="do" 
				|| word == "goto" || word == "function" || word == "end" || word == "then" || word == "and" 
				|| word =="or") {
				color = Color(251, 73 ,44);
				foundWordEndPos = --wordWidth;
				wordFound = true;
			} else if (word == "true" || word == "false") {
				color = Color(211, 134, 155);
				foundWordEndPos = --wordWidth;
				wordFound = true;
			}//*/

			//std::cerr << word.toStdString() << "\n";

			if (i > foundWordEndPos) {
				color = mColor;
				wordFound = false;
			}
		}
		//*/
		const Glyph &glyph = mFont->getGlyph(currChar, mCharSize, bold);

		float left	 = glyph.bounds.left;
		float top	 = glyph.bounds.top;
		float right	 = glyph.bounds.left + glyph.bounds.width;
		float bottom = glyph.bounds.top  + glyph.bounds.height;

		float u1 = staticCastf(glyph.textureRect.left);
		float v1 = staticCastf(glyph.textureRect.top);
		float u2 = staticCastf(glyph.textureRect.left + glyph.textureRect.width);
		float v2 = staticCastf(glyph.textureRect.top  + glyph.textureRect.height);

		mVertices.append(Vertex(Vector2f(x + left  - italic * top,	  y + top),	   color, Vector2f(u1, v1)));
		mVertices.append(Vertex(Vector2f(x + right - italic * top,	  y + top),	   color, Vector2f(u2, v1)));
		mVertices.append(Vertex(Vector2f(x + left  - italic * bottom, y + bottom), color, Vector2f(u1, v2)));
		mVertices.append(Vertex(Vector2f(x + left  - italic * bottom, y + bottom), color, Vector2f(u1, v2)));
		mVertices.append(Vertex(Vector2f(x + right - italic * top,    y + top),	   color, Vector2f(u2, v1)));
		mVertices.append(Vertex(Vector2f(x + right - italic * bottom, y + bottom), color, Vector2f(u2, v2)));

		minX = std::min(minX, x + left  - italic * bottom);
		maxX = std::max(maxX, x + right - italic * top);
		minY = std::min(minY, y + top);
		maxY = std::max(maxY, y + bottom);

		x += glyph.advance;
	}

	if (underlined) {
		float top     = std::floor(y + underlineOffset - (underlineThickness / 2) + 0.5f);
		float botttom = top + std::floor(underlineThickness + 0.5f);

		mVertices.append(Vertex(Vector2f(0, top),	  mColor, Vector2f(1, 1)));
		mVertices.append(Vertex(Vector2f(x, top),	  mColor, Vector2f(1, 1)));
		mVertices.append(Vertex(Vector2f(0, botttom), mColor, Vector2f(1, 1)));
		mVertices.append(Vertex(Vector2f(0, botttom), mColor, Vector2f(1, 1)));
		mVertices.append(Vertex(Vector2f(x, top),     mColor, Vector2f(1, 1)));
		mVertices.append(Vertex(Vector2f(x, botttom), mColor, Vector2f(1, 1)));
	}

	if (strikeThrough) {
		float top     = std::floor(y + strikeThroughOffset - (underlineThickness / 2) + 0.5f);
		float botttom = top + std::floor(underlineThickness + 0.5f);

		mVertices.append(Vertex(Vector2f(0, top),	  mColor, Vector2f(1, 1)));
		mVertices.append(Vertex(Vector2f(x, top),	  mColor, Vector2f(1, 1)));
		mVertices.append(Vertex(Vector2f(0, botttom), mColor, Vector2f(1, 1)));
		mVertices.append(Vertex(Vector2f(0, botttom), mColor, Vector2f(1, 1)));
		mVertices.append(Vertex(Vector2f(x, top),     mColor, Vector2f(1, 1)));
		mVertices.append(Vertex(Vector2f(x, botttom), mColor, Vector2f(1, 1)));
	}

	mBounds.left   = minX;
	mBounds.top	   = minY;
	mBounds.width  = maxX - minX;
	mBounds.height = maxY - minY;
}
示例#10
0
void
Dialog::draw(DrawingContext& context)
{
  Rectf bg_rect(Vector(static_cast<float>(m_passive ?
                                          (static_cast<float>(context.get_width()) - m_text_size.width - 20.0f) :
                                          static_cast<float>(context.get_width()) / 2.0f - m_text_size.width / 2.0f),
                       static_cast<float>(m_passive ?
                                          (static_cast<float>(context.get_height()) - m_text_size.height - 65.0f) :
                                          (static_cast<float>(context.get_height()) / 2.0f - m_text_size.height / 2.0f))),
                Sizef(m_text_size.width,
                      m_text_size.height + 44));

  // draw background rect
  context.color().draw_filled_rect(bg_rect.grown(12.0f),
                                     Color(0.2f, 0.3f, 0.4f, m_passive ? 0.3f : 0.8f),
                                     16.0f,
                                     LAYER_GUI-10);

  context.color().draw_filled_rect(bg_rect.grown(8.0f),
                                     Color(0.6f, 0.7f, 0.8f, m_passive ? 0.2f : 0.5f),
                                     16.0f,
                                     LAYER_GUI-10);

  // draw text
  context.color().draw_text(Resources::normal_font, m_text,
                              Vector(bg_rect.get_left() + bg_rect.get_width()/2.0f,
                                     bg_rect.get_top()),
                              ALIGN_CENTER, LAYER_GUI);
  if (m_passive)
    return;

  // draw HL line
  context.color().draw_filled_rect(Rectf(Vector(bg_rect.get_left(), bg_rect.get_bottom() - 35),
                                         Sizef(bg_rect.get_width(), 4)),
                                   Color(0.6f, 0.7f, 1.0f, 1.0f), LAYER_GUI);
  context.color().draw_filled_rect(Rectf(Vector(bg_rect.get_left(), bg_rect.get_bottom() - 35),
                                         Sizef(bg_rect.get_width(), 2)),
                                   Color(1.0f, 1.0f, 1.0f, 1.0f), LAYER_GUI);

  // draw buttons
  for (int i = 0; i < static_cast<int>(m_buttons.size()); ++i)
  {
    float segment_width = bg_rect.get_width() / static_cast<float>(m_buttons.size());
    float button_width = segment_width;
    Vector pos(bg_rect.get_left() + segment_width/2.0f + static_cast<float>(i) * segment_width,
               bg_rect.get_bottom() - 12);

    if (i == m_selected_button)
    {
      float button_height = 24.0f;
      float blink = (sinf(g_real_time * math::PI * 1.0f)/2.0f + 0.5f) * 0.5f + 0.25f;
      context.color().draw_filled_rect(Rectf(Vector(pos.x - button_width/2, pos.y - button_height/2),
                                               Vector(pos.x + button_width/2, pos.y + button_height/2)).grown(2.0f),
                                         Color(1.0f, 1.0f, 1.0f, blink),
                                         14.0f,
                                         LAYER_GUI-10);
      context.color().draw_filled_rect(Rectf(Vector(pos.x - button_width/2, pos.y - button_height/2),
                                               Vector(pos.x + button_width/2, pos.y + button_height/2)),
                                         Color(1.0f, 1.0f, 1.0f, 0.5f),
                                         12.0f,
                                         LAYER_GUI-10);
    }

    context.color().draw_text(Resources::normal_font, m_buttons[i].text,
                              Vector(pos.x, pos.y - static_cast<float>(int(Resources::normal_font->get_height() / 2))),
                              ALIGN_CENTER, LAYER_GUI,
                              i == m_selected_button ? ColorScheme::Menu::active_color : ColorScheme::Menu::default_color);
  }
}
void DebugDrawer::draw( const BlobTrackerRef &blobTracker, const Area &bounds, const Options &options )
{
	if ( options.mDebugMode == Options::DebugMode::NONE )
	{
		return;
	}

	gl::TextureRef tex;
	switch ( options.mDrawMode )
	{
		case Options::DrawMode::ORIGINAL:
		{
			cv::Mat img = blobTracker->getImageInput();
			if ( img.data )
			{
				tex = gl::Texture::create( fromOcv( img ) );
			}
			break;
		}

		case Options::DrawMode::BLURRED:
		{
			cv::Mat img = blobTracker->getImageBlurred();
			if ( img.data )
			{
				tex = gl::Texture::create( fromOcv( img ) );
			}
			break;
		}

		case Options::DrawMode::THRESHOLDED:
		{
			cv::Mat img = blobTracker->getImageThresholded();
			if ( img.data )
			{
				tex = gl::Texture::create( fromOcv( img ) );
			}
			break;
		}

		default:
			break;
	}

	if ( ! tex )
	{
		return;
	}

	ci::gl::disableDepthRead();
	ci::gl::disableDepthWrite();

	bool blendingEnabled = options.mDebugMode == Options::DebugMode::BLENDED;
	auto ctx = gl::context();
	ctx->pushBoolState( GL_BLEND, blendingEnabled );
	ctx->pushBlendFuncSeparate( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

	gl::ScopedColor color( ColorA::gray( 1.0f, 0.5f ) );

	Area outputArea = bounds;
	if ( options.mDrawProportionalFit )
	{
		outputArea = Area::proportionalFit( tex->getBounds(), bounds, true, true );
	}

	gl::draw( tex, outputArea );

	{
		const auto &trackerOptions = blobTracker->getOptions();
		float s = trackerOptions.mNormalizationScale;
		RectMapping blobMapping( Rectf( 0.0f, 0.0f, s, s ), Rectf( outputArea ) );
		Rectf roi = trackerOptions.mNormalizedRegionOfInterest * s;
		gl::color( ColorA( 0.0f, 1.0f, 0.0f, 0.8f ) );
		gl::drawStrokedRect( blobMapping.map( roi ) );

		vec2 offset = outputArea.getUL();
		vec2 scale = vec2( outputArea.getSize() ) / vec2( s, s );
		for ( const auto &blob : blobTracker->getBlobs() )
		{
			gl::pushModelView();
			gl::translate( offset );
			gl::scale( scale );
			if ( trackerOptions.mBoundsEnabled )
			{
				gl::color( ColorA( 1.0f, 1.0f, 0.0f, 0.5f ) );
				gl::drawStrokedRect( blob->mBounds );
			}
			if ( trackerOptions.mConvexHullEnabled && blob->mConvexHull )
			{
				gl::color( ColorA( 1.0f, 0.0f, 1.0f, 0.5f ) );
				gl::draw( *blob->mConvexHull.get() );
			}
			gl::popModelView();
			vec2 pos = blobMapping.map( blob->mPos );
			gl::drawSolidCircle( pos, 2.0f );
			gl::drawString( toString< int32_t >( blob->mId ), pos + vec2( 3.0f, -3.0f ),
					ColorA( 1.0f, 0.0f, 0.0f, 0.9f ) );
		}
	}
	ctx->popBoolState( GL_BLEND );
	ctx->popBlendFuncSeparate();
}
示例#12
0
Rectf Sprite::getLocalBounds() const {
	float w = staticCastf(std::abs(mTextureRect.width));
	float h = staticCastf(std::abs(mTextureRect.height));

	return Rectf(0.f, 0.f, w, h);
}
示例#13
0
bool TextFragment::format(vec2& location, 
                          float rect_width, 
                          bool limit_line_count, 
                          int& line_count,
                          bool single_line)
{
   bool abort = false;
   updateGlyphArrays(limit_line_count);
   // we are going to fill out the m_glyph_rendering_array
   // he is what is used to render in the draw() method.
   m_glyph_rendering_array.clear();
   m_rect_array.clear();
      
   size_t glyph_offset = 0;
   float line_begin = location.x;
      
   for(std::vector<WordInfo>::const_iterator word_info = m_glyph_words_array.begin();
       word_info != m_glyph_words_array.end() && !abort;
       word_info++)
   {
      if(single_line)
      {
         for(size_t i = 0;
             !abort && i < word_info->m_glyph_count;
             i++)
         {
            if(location.x + m_glyph_widths_array[glyph_offset + i].second > rect_width)
            {
               abort = true;
            }
            else
            {
               addGlyphItemToRenderingArray(glyph_offset + i, location);
            }
         }
      }
      else
      {
         if(location.x + word_info->m_width > rect_width)
         {
            m_rect_array.push_back(Rectf(line_begin, location.y - g_skin.getBaselineDrop(),
               location.x, location.y + g_skin.getBaselineRise()));
            if(limit_line_count)
            {
               line_count--;
               if(line_count == 0)
               {
                  abort = true;
               }
            }

            if(!abort)
            {
               moveLocationToNewline(location);
               line_begin = location.x;
            }
         }

         bool break_line_on_char = false;
         if(location.x == 0 && word_info->m_width > rect_width)
         {
            break_line_on_char = true;
         }

         for(size_t i = 0;
             i < word_info->m_glyph_count && !abort;
             i++)
         {
            if(break_line_on_char &&
               location.x + m_glyph_widths_array[glyph_offset + i].second > rect_width)
            {
               m_rect_array.push_back(Rectf(line_begin, location.y - g_skin.getBaselineDrop(),
                  location.x, location.y + g_skin.getBaselineRise()));

               if(limit_line_count)
               {
                  line_count--;
                  if(line_count == 0)
                  {
                     abort = true;
                  }
               }

               if(!abort)
               {
                  moveLocationToNewline(location);
                  line_begin = location.x;
               }
            }

            addGlyphItemToRenderingArray(glyph_offset + i, location);
         }

         if(word_info->m_newline)
         {
            m_rect_array.push_back(Rectf(line_begin, location.y - g_skin.getBaselineDrop(),
               location.x, location.y + g_skin.getBaselineRise()));

            if(limit_line_count)
            {
               line_count--;
               if(line_count == 0)
               {
                  abort = true;
               }
            }

            if(!abort)
            {
               moveLocationToNewline(location);
               line_begin = location.x;
            }
         }
      }

      glyph_offset += word_info->m_glyph_count;
   }

   m_rect_array.push_back(Rectf(line_begin, location.y - g_skin.getBaselineDrop(),
                                location.x, location.y + g_skin.getBaselineRise()));
   m_cumulative_rect = m_rect_array.front();
   for(size_t i = 1; i < m_rect_array.size(); i++)
   {
      m_cumulative_rect.include(m_rect_array[i]);
   }

   return abort;
}
示例#14
0
void WorldUIView::drawBorder(){
	color(Color(0, 0, 0));
	lineWidth(5);
	drawStrokedRect(Rectf(rect.x, rect.y, rect.xEnd, rect.yEnd));
}	
示例#15
0
// gets bounding box of element
Rectf DXFCircle::GetBoundingBox(void) const
{
	return Rectf(center.x - radius, center.y + radius, center.x + radius, center.y - radius);
}
示例#16
0
Rectf
Sprite::get_current_hitbox() const
{
  return Rectf(m_action->x_offset, m_action->y_offset, m_action->x_offset + m_action->hitbox_w, m_action->y_offset + m_action->hitbox_h);
}
示例#17
0
bool Note::allocate() {
	
	if(allocatedForRatio == sizeRatio()) {
		return background ? true : false;
	}
	
	deallocate();
	
	// Allocate textures and calculate sizes
	
	Vec2f newPos;
	Vec2f newTextStart;
	Vec2f newTextEnd;
	
	Vec2f prevButtonOffset;
	Vec2f nextButtonOffset;
	
	size_t maxPages = 1;
	
	Vec2f scale = Vec2f(minSizeRatio(), minSizeRatio());
	
	if(_type == QuestBook) {
		// TODO change this once the aspect ratio in character screen, spell book, etc. is fixed.
		scale = sizeRatio();
	}
	
	switch(_type) {
		
		// TODO this information should not be hardcoded
		
		case Notice: {
			background = TextureContainer::LoadUI("graph/interface/book/notice");
			if(background) {
				newPos = Vec2f(320 * Xratio - background->m_dwWidth * 0.5f * scale.x, 47.f * scale.y);
				newTextStart = Vec2f(50.f, 50.f);
				newTextEnd = Vec2f(background->size()) - Vec2f(50.f, 50.f);
			}
			break;
		}
		
		case SmallNote: {
			background = TextureContainer::LoadUI("graph/interface/book/bignote");
			if(background) {
				newPos = Vec2f(320 * Xratio - background->m_dwWidth * 0.5f * scale.x, 47.f * scale.y);
				newTextStart = Vec2f(30.f, 30.f);
				newTextEnd = Vec2f(background->size()) - Vec2f(30.f, 40.f);
			}
			break;
		}
		
		case BigNote: {
			background = TextureContainer::LoadUI("graph/interface/book/very_bignote");
			if(background) {
				newPos = Vec2f(320 * Xratio - background->m_dwWidth * 0.5f * scale.x, 47.f * scale.y);
				newTextStart = Vec2f(40.f, 40.f);
				newTextEnd = Vec2f(background->size()) * Vec2f(0.5f, 1.f) - Vec2f(10.f, 40.f);
				maxPages = 2;
			}
			break;
		}
		
		case Book: {
			background = TextureContainer::LoadUI("graph/interface/book/ingame_books");
			prevPage = TextureContainer::LoadUI("graph/interface/book/left_corner");
			nextPage = TextureContainer::LoadUI("graph/interface/book/right_corner");
			if(background) {
				newPos = Vec2f(320 * Xratio - background->m_dwWidth * 0.5f * scale.x, 47.f * scale.y);
				newTextStart = Vec2f(40.f, 20.f);
				newTextEnd = Vec2f(background->size()) * Vec2f(0.5f, 1.f) - Vec2f(10.f, 40.f);
				maxPages = std::numeric_limits<size_t>::max();
				prevButtonOffset = Vec2f(8.f, -6.f);
				nextButtonOffset = Vec2f(-15.f, -6.f);
			}
			break;
		}
		
		case QuestBook: {
			background = TextureContainer::LoadUI("graph/interface/book/questbook");
			prevPage = TextureContainer::LoadUI("graph/interface/book/left_corner_original");
			nextPage = TextureContainer::LoadUI("graph/interface/book/right_corner_original");
			if(background) {
				newPos = Vec2f(97, 64) * scale;
				newTextStart = Vec2f(40.f, 40.f);
				newTextEnd = Vec2f(background->size()) * Vec2f(0.5f, 1.f) - Vec2f(10.f, 65.f);
				maxPages = std::numeric_limits<size_t>::max();
				prevButtonOffset = Vec2f(8.f, -6.f);
				nextButtonOffset = Vec2f(-15.f, -6.f);
			}
		}
		
		case Undefined: break; // Cannot handle notes of undefined type.
	}
	
	if(!background) {
		allocatedForRatio = sizeRatio();
		return false;
	}
	
	_area = Rectf(newPos,
	             background->m_dwWidth * scale.x, background->m_dwHeight * scale.y);
	_textArea = Rect(Vec2i(newTextStart * scale), Vec2i(newTextEnd * scale));
	_pageSpacing = 20 * scale.x;
	if(prevPage) {
		Vec2f pos = Vec2f(0.f, background->m_dwHeight - prevPage->m_dwHeight) + prevButtonOffset;
		pos *= scale;
		_prevPageButton = Rectf(newPos + pos,
		                       prevPage->m_dwWidth * scale.x, prevPage->m_dwHeight * scale.y);
	}
	if(nextPage) {
		Vec2f pos = Vec2f(background->size() - nextPage->size()) + nextButtonOffset;
		pos *= scale;
		_nextPageButton = Rectf(newPos + pos,
		                       nextPage->m_dwWidth * scale.x, nextPage->m_dwHeight * scale.y);
	}
	
	// Split text into pages
	
	// TODO This buffer and related string copies can be avoided by
	// using iterators for ARX_UNICODE_ForceFormattingInRect
	std::string buffer = _text;
	
	while(!buffer.empty()) {
		
		// Change the note type if the text is too long.
		if(pages.size() >= maxPages) {
			switch(_type) {
				case Notice: _type = SmallNote; break;
				case SmallNote: _type = BigNote; break;
				case BigNote: _type = Book; break;
				default: ARX_DEAD_CODE(); break;
			}
			return allocate();
		}
		
		long pageSize = ARX_UNICODE_ForceFormattingInRect(hFontInGameNote, buffer, _textArea);
		if(pageSize <= 0) {
			LogWarning << "Error splitting note text into pages";
			pages.push_back(buffer);
			break;
		}
		
		pages.push_back(buffer.substr(0, pageSize));
		
		// Skip whitespace at the start of pages.
		while(size_t(pageSize) < buffer.size() && std::isspace(buffer[pageSize])) {
			pageSize++;
		}
		
		buffer = buffer.substr(pageSize);
	}
	
	// Clamp the current page to a valid page.
	setPage(_page);
	
	allocatedForRatio = sizeRatio();
	
	return true;
}
示例#18
0
 Rectf Touchable::getTouchableBounds()
 {
     return Rectf(0, 0, 0, 0);
 }
//----------------------------------------------------------------------------//
void OpenGLFBOTextureTarget::declareRenderSize(const Sizef& sz)
{
    setArea(Rectf(d_area.getPosition(), d_owner.getAdjustedTextureSize(sz)));
    resizeRenderTexture();
}
示例#20
0
文件: font.cpp 项目: kyelin/ClanLib
void Font::draw_text_ellipsis(Canvas &canvas, int dest_x, int dest_y, Rect content_box, const std::string &text, const Colorf &color)
{
	draw_text_ellipsis(canvas, (float) dest_x, (float) dest_y, Rectf(content_box.left, content_box.top, content_box.right, content_box.bottom), text, color);
}
示例#21
0
 Rectf get_tile_bbox(int x, int y) const
 { return Rectf(get_tile_position(x, y), get_tile_position(x+1, y+1)); }
示例#22
0
	ViewGeometry PositionedLayout::get_geometry(Canvas &canvas, View *view, const Rectf &containing_box)
	{
		bool definite_left = !view->style_cascade().computed_value("left").is_keyword("auto");
		bool definite_right = !view->style_cascade().computed_value("right").is_keyword("auto");
		bool definite_width = !view->style_cascade().computed_value("width").is_keyword("auto");

		float computed_left = resolve_percentage(view->style_cascade().computed_value("left"), containing_box.get_width());
		float computed_right = resolve_percentage(view->style_cascade().computed_value("right"), containing_box.get_width());
		float computed_width = resolve_percentage(view->style_cascade().computed_value("width"), containing_box.get_width());

		float x = 0.0f;
		float width = 0.0f;

		if (definite_left && definite_right)
		{
			x = computed_left;
			width = clan::max(containing_box.get_width() - computed_right - x, 0.0f);
		}
		else if (definite_left && definite_width)
		{
			x = computed_left;
			width = computed_width;
		}
		else if (definite_right && definite_width)
		{
			width = computed_width;
			x = containing_box.get_width() - computed_right - width;
		}
		else if (definite_left)
		{
			x = computed_left;
			width = view->preferred_width(canvas);
			// Note: in HTML there's an additional implicit "max-width: calc(100%-left)" rule active here.
			// We are not emulating this "feature" as it is most likely a bug that got standardized for backwards compatibility.
			// The user should add an max-width rule themselves if they want such an odd constraint active.
		}
		else if (definite_right)
		{
			width = view->preferred_width(canvas);
			x = containing_box.get_width() - computed_right - width;
		}
		else if (definite_width)
		{
			x = 0.0f;
			width = view->style_cascade().computed_value("width").number();
		}
		else
		{
			x = 0.0f;
			width = view->preferred_width(canvas);
		}

		bool definite_top = !view->style_cascade().computed_value("top").is_keyword("auto");
		bool definite_bottom = !view->style_cascade().computed_value("bottom").is_keyword("auto");
		bool definite_height = !view->style_cascade().computed_value("height").is_keyword("auto");

		float computed_top = resolve_percentage(view->style_cascade().computed_value("top"), containing_box.get_height());
		float computed_bottom = resolve_percentage(view->style_cascade().computed_value("bottom"), containing_box.get_height());
		float computed_height = resolve_percentage(view->style_cascade().computed_value("height"), containing_box.get_height());

		float y = 0.0f;
		float height = 0.0f;

		if (definite_top && definite_bottom)
		{
			y = computed_top;
			height = clan::max(containing_box.get_height() - computed_bottom - y, 0.0f);
		}
		else if (definite_top && definite_height)
		{
			y = computed_top;
			height = computed_height;
		}
		else if (definite_bottom && definite_height)
		{
			height = computed_height;
			y = containing_box.get_height() - computed_bottom - height;
		}
		else if (definite_top)
		{
			y = computed_top;
			height = view->preferred_height(canvas, width);
		}
		else if (definite_bottom)
		{
			height = view->preferred_height(canvas, width);
			y = containing_box.get_height() - computed_bottom - height;
		}
		else if (definite_height)
		{
			y = 0.0f;
			height = computed_height;
		}
		else
		{
			y = 0.0f;
			height = view->preferred_height(canvas, width);
		}


		x += containing_box.left;
		y += containing_box.top;

		auto tl = canvas.grid_fit(Pointf(x, y));
		auto br = canvas.grid_fit(Pointf(x + width, y + height));
		Rectf box = Rectf(tl.x, tl.y, br.x, br.y);
		return ViewGeometry::from_content_box(view->style_cascade(), box);
	}
示例#23
0
void
ObjectIcon::draw(DrawingContext& context, Vector pos) {
  context.draw_surface_part(surface, Rectf(Vector(0,0), surface->get_size()),
                            Rectf(pos + offset, pos + Vector(32,32) - offset), LAYER_GUI - 9);
}
示例#24
0
namespace tf {

const Rectf PeerCircle::sWorldRect = Rectf( 0.f, 0.f, 1000.f, 1000.f );

PeerCircle::PeerCircle( int id, std::string address, float bearing, std::string location, TorrentRef tr ) :
	Peer( id, address, bearing, location, tr)
{
	Vec2f bv = sWorldRect.getSize() * Vec2f( .3f, .0f );
	bv.rotate( bearing );
	mOldPos = mPos = sWorldRect.getCenter() + bv;
	//mDecay = Rand::randFloat( .95f, .99f );
	mAttractorPos = sWorldRect.getCenter();
}

void PeerCircle::update()
{
	// attraction to torrent position
	Vec2f dir = mAttractorPos - mPos;
	float distSqrd = dir.lengthSquared();

	float strength = 5.f;

	if ( distSqrd > 0.f )
	{
		float minDistSqrd = 1000.f;
		if ( distSqrd < minDistSqrd )
		{
			strength = lmap< float >( 1.f, minDistSqrd, 0.f, strength, distSqrd );
			strength = math< float >::clamp( strength, 0.f, 5.f );
		}
		float force = strength * mMass / distSqrd;
		Vec2f deltaForce = dir * force;
		moveBy( deltaForce * mInvMass, false );
	}

	// repel other peers
	const std::vector< PeerRef > &peers = mTorrentRef->getPeers();
	for ( PeerRef peer : peers )
	{
		if ( peer->getId() == mId )
			continue;

		auto other = std::static_pointer_cast< PeerCircle >( peer );
		Vec2d dir = mPos - other->getPos();
		float distSqrd = dir.lengthSquared();
		if ( distSqrd > .0f )
		{
			float force = .1f * mMass * other->getMass() / distSqrd;
			Vec2f deltaForce = dir * force;
			moveBy( deltaForce * mInvMass, false );
			other->moveBy( - deltaForce * other->getInvMass(), false );
		}
	}

	// do verlet
	Vec2f curPos = mPos;
	Vec2f vel = mPos - mOldPos;
	mPos += vel * mDrag;
	mOldPos = curPos;

	/*
	// TODO: attract actual torrent position
	Vec2d dir = Vec2d( 500, 500 ) - mPos;
	double distSqrd = dir.lengthSquared();

	if ( distSqrd > 0. )
	{
		double f = math< double >::sqrt( distSqrd ) * .00001;
		mAcc += dir.normalized() * f;
	}

	mVel += mAcc;
	mPos += mVel;
	mVel *= mDecay;
	mAcc.set( 0., 0. );
	//mRadius = lerp< double, double >( mRadius, mRadiusOrig, .01 );
	*/
}

void PeerCircle::draw( const Rectf &rect )
{
	RectMapping rm( sWorldRect, rect, true );
	//app::console() << mId << ": " << mRadius << std::endl;

	gl::color( Color::white() );
	gl::drawStrokedCircle( rm.map( mPos ),
			lmap< float >( 0.f, sWorldRect.getHeight(), 0.f, rect.getHeight(), mRadius ) );
}

} // namespace tf
示例#25
0
void
Menu::draw_item(DrawingContext& context, int index)
{
  float menu_height = get_height();
  float menu_width  = get_width();

  MenuItem& pitem = *(items[index]);

  Color text_color = ColorScheme::Menu::default_color;
  float x_pos       = pos.x;
  float y_pos       = pos.y + 24*index - menu_height/2 + 12;
  int text_width  = int(Resources::normal_font->get_text_width(pitem.text));
  int input_width = int(Resources::normal_font->get_text_width(pitem.input) + 10);
  int list_width = 0;

  float left  = pos.x - menu_width/2 + 16;
  float right = pos.x + menu_width/2 - 16;

  if(pitem.list.size() > 0) {
    list_width = (int) Resources::normal_font->get_text_width(pitem.list[pitem.selected]);
  }

  if (arrange_left)
    x_pos += 24 - menu_width/2 + (text_width + input_width + list_width)/2;

  if(index == active_item)
  {
    text_color = ColorScheme::Menu::active_color;
  }

  if(active_item == index)
  {
    float blink = (sinf(real_time * M_PI * 1.0f)/2.0f + 0.5f) * 0.5f + 0.25f;
    context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2 + 10 - 2, y_pos - 12 - 2),
                                   Vector(pos.x + menu_width/2 - 10 + 2, y_pos + 12 + 2)),
                             Color(1.0f, 1.0f, 1.0f, blink),
                             14.0f,
                             LAYER_GUI-10);
    context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2 + 10, y_pos - 12),
                                   Vector(pos.x + menu_width/2 - 10, y_pos + 12)),
                             Color(1.0f, 1.0f, 1.0f, 0.5f),
                             12.0f,
                             LAYER_GUI-10);
  }

  switch (pitem.kind)
  {
    case MN_INACTIVE:
    {
      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_CENTER, LAYER_GUI, ColorScheme::Menu::inactive_color);
      break;
    }

    case MN_HL:
    {
      // TODO
      float x = pos.x - menu_width/2;
      float y = y_pos - 12;
      /* Draw a horizontal line with a little 3d effect */
      context.draw_filled_rect(Vector(x, y + 6),
                               Vector(menu_width, 4),
                               Color(0.6f, 0.7f, 1.0f, 1.0f), LAYER_GUI);
      context.draw_filled_rect(Vector(x, y + 6),
                               Vector(menu_width, 2),
                               Color(1.0f, 1.0f, 1.0f, 1.0f), LAYER_GUI);
      break;
    }
    case MN_LABEL:
    {
      context.draw_text(Resources::big_font, pitem.text,
                        Vector(pos.x, y_pos - int(Resources::big_font->get_height()/2)),
                        ALIGN_CENTER, LAYER_GUI, ColorScheme::Menu::label_color);
      break;
    }
    case MN_TEXTFIELD:
    case MN_NUMFIELD:
    case MN_CONTROLFIELD:
    {
      if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD)
      {
        if(active_item == index)
          context.draw_text(Resources::normal_font,
                            pitem.get_input_with_symbol(true),
                            Vector(right, y_pos - int(Resources::normal_font->get_height()/2)),
                            ALIGN_RIGHT, LAYER_GUI, ColorScheme::Menu::field_color);
        else
          context.draw_text(Resources::normal_font,
                            pitem.get_input_with_symbol(false),
                            Vector(right, y_pos - int(Resources::normal_font->get_height()/2)),
                            ALIGN_RIGHT, LAYER_GUI, ColorScheme::Menu::field_color);
      }
      else
        context.draw_text(Resources::normal_font, pitem.input,
                          Vector(right, y_pos - int(Resources::normal_font->get_height()/2)),
                          ALIGN_RIGHT, LAYER_GUI, ColorScheme::Menu::field_color);

      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(left, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_LEFT, LAYER_GUI, text_color);
      break;
    }
    case MN_STRINGSELECT:
    {
      float roff = Resources::arrow_left->get_width();
      // Draw left side
      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(left, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_LEFT, LAYER_GUI, text_color);

      // Draw right side
      context.draw_surface(Resources::arrow_left,
                           Vector(right - list_width - roff - roff, y_pos - 8),
                           LAYER_GUI);
      context.draw_surface(Resources::arrow_right,
                           Vector(right - roff, y_pos - 8),
                           LAYER_GUI);
      context.draw_text(Resources::normal_font, pitem.list[pitem.selected],
                        Vector(right - roff, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_RIGHT, LAYER_GUI, text_color);
      break;
    }
    case MN_BACK:
    {
      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_CENTER, LAYER_GUI, text_color);
      context.draw_surface(Resources::back,
                           Vector(x_pos + text_width/2  + 16, y_pos - 8),
                           LAYER_GUI);
      break;
    }

    case MN_TOGGLE:
    {
      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(pos.x - menu_width/2 + 16, y_pos - (Resources::normal_font->get_height()/2)),
                        ALIGN_LEFT, LAYER_GUI, text_color);

      if(pitem.toggled)
        context.draw_surface(Resources::checkbox_checked,
                             Vector(x_pos + (menu_width/2-16) - Resources::checkbox->get_width(), y_pos - 8),
                             LAYER_GUI + 1);
      else
        context.draw_surface(Resources::checkbox,
                             Vector(x_pos + (menu_width/2-16) - Resources::checkbox->get_width(), y_pos - 8),
                             LAYER_GUI + 1);
      break;
    }
    case MN_ACTION:
      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_CENTER, LAYER_GUI, text_color);
      break;

    case MN_GOTO:
      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_CENTER, LAYER_GUI, text_color);
      break;
  }
}
示例#26
0
EnemyShip1::EnemyShip1(int arrivalTime, float hp, float atkspd, float xpos, float ypos, float xvel, float yvel,PlayerShip* p) : EnemyShip(arrivalTime,hp,atkspd,xpos,ypos,xvel,yvel,46,46,p)
{
	rec = Rectf( Vec2f(pos.x-width/2,pos.y-height/2), Vec2f(pos.x+width/2,pos.y+height/2));
	bulletType = 1;
}
示例#27
0
	void TextArea::updateModels()
	{
		if (!font.isValid())
		{
			return;
		}

		for (auto && model : models)
		{
			getScene()->destroyModel(model);
		}
		models.clear();
		meshes.clear();

		// A text area may use multiple textures for different code point areas. A separate model is created for each texture.
		std::map<Ptr<render::Image>, std::vector<float>> meshVertices;
		std::map<Ptr<render::Image>, std::vector<unsigned int>> meshIndices;
		Vector2i cursor {0, font->getLineHeight()};
		for (size_t i = 0; i < text.size();)
		{
			// Get the next character, move i forward.
			unsigned int c = getChar(text, i);

			if (c == '\n')
			{
				cursor[1] += font->getLineHeight();
				cursor[0] = 0;
				continue;
			}
			else if (c == '\r')
			{
				continue;
			}
			else if (c == '\t')
			{
				cursor[0] += font->getLineHeight();
				continue;
			}

			// Get the font information for the next character.
			render::Font::GlyphCoords const & glyphCoords = font->getGlyphCoordsFromChar(c);
			Ptr<render::Image> glyphImage = font->getImageFromChar(c);

			// Setup the vertice and indices for this glyph.
			Rectf glyphBounds;
			glyphBounds.min = Vector2f(cursor + glyphCoords.offset);
			glyphBounds.setSize(Vector2f(glyphCoords.uvBounds.getSize()));
			Rectf glyphUVBounds = Rectf(glyphCoords.uvBounds);
			glyphUVBounds.max += Vector2f {1, 1};
			std::vector<float> & vertices = meshVertices[glyphImage];
			int startingIndex = (int)vertices.size() / 4;
			vertices.push_back(glyphBounds.min[0]);
			vertices.push_back(glyphBounds.min[1]);
			vertices.push_back(glyphUVBounds.min[0]);
			vertices.push_back(glyphUVBounds.min[1]);
			vertices.push_back(glyphBounds.max[0]);
			vertices.push_back(glyphBounds.min[1]);
			vertices.push_back(glyphUVBounds.max[0]);
			vertices.push_back(glyphUVBounds.min[1]);
			vertices.push_back(glyphBounds.max[0]);
			vertices.push_back(glyphBounds.max[1]);
			vertices.push_back(glyphUVBounds.max[0]);
			vertices.push_back(glyphUVBounds.max[1]);
			vertices.push_back(glyphBounds.min[0]);
			vertices.push_back(glyphBounds.max[1]);
			vertices.push_back(glyphUVBounds.min[0]);
			vertices.push_back(glyphUVBounds.max[1]);
			std::vector<unsigned int> & indices = meshIndices[glyphImage];
			indices.push_back(startingIndex + 0);
			indices.push_back(startingIndex + 2);
			indices.push_back(startingIndex + 1);
			indices.push_back(startingIndex + 0);
			indices.push_back(startingIndex + 3);
			indices.push_back(startingIndex + 2);
			cursor[0] += glyphCoords.advance;
		}

		// Construct the models form the text.
		for (auto const & pair : meshVertices)
		{
			auto image = pair.first;
			auto model = getScene()->createModel();
			meshes.push_back(std::move(OwnPtr<render::Mesh>::returnNew()));
			auto & mesh = meshes.back();
			meshes.back()->setVertices(0, meshVertices[image], sizeof(float) * 4, false);
			meshes.back()->setVertexComponent(0, 2, 0, 0);
			meshes.back()->setVertexComponent(1, 2, sizeof(float) * 2, 0);
			mesh->setIndices(meshIndices[image]);
			model->setMesh(mesh);
			model->setShader(getShader());
			model->setImageAtSlot(image, 0);
			model->setUniformsFunction([this, image](Ptr<render::Shader> const & shader)
			{
				shader->setUniformValue<Vector2f>(originUniformLocation, (Vector2f)bounds.min);
				shader->setUniformValue<Vector2f>(imageSizeUniformLocation, (Vector2f)image->getSize());
				shader->setUniformValue<int>(imageUniformLocation, 0);
				shader->setUniformValue<Vector4f>(colorUniformLocation, color);
			});
			model->setDepth(depth);
			models.push_back(model);
		}
	}
示例#28
0
	void PretzelTextField::updateBounds(const ci::vec2 &offset, const ci::Rectf &parentBounds) {
		BasePretzel::updateBounds(offset, parentBounds);

		// this could be cleaner
		mTextFieldBounds = Rectf(mLabelSize.x + 25, mBounds.y1 + 5, mBounds.x2 - 10, mBounds.y2 - 5);
	}
示例#29
0
void TextWidget::setText(const std::string & text) {
	m_text = text;
	Vec2i textSize = m_font->getTextSize(m_text);
	m_rect = Rectf(m_rect.topLeft(), float(textSize.x + 1), float(textSize.y + 1));
}
示例#30
0
void EERIEAddBitmap(const RenderMaterial & mat, const Vec3f & p, float sx, float sy, TextureContainer * tex, Color color) {
	TexturedQuad s;
	CreateBitmap(s, Rectf(Vec2f(p.x, p.y), sx, sy), p.z, tex, color, false);
	RenderBatcher::getInstance().add(mat, s);
}