Beispiel #1
0
void createLevel(CLevel& level, CText& levelText) {
    levelText.loadFont(FONT_PATH);
    levelText.setString("Level: "+numberToString(level.getLevel()));
    levelText.setCharacterSize(24);
    levelText.setColor(sf::Color::Magenta);
    levelText.setPosition(300,0);
}
// reassign copper text to new layers
// enter with layer[] = table of new copper layers for each old copper layer
//
void CTextList::ReassignCopperLayers( int n_new_layers, int * layer )
{
	CText * t = GetFirstText();
	while( t )
	{
		int old_layer = t->m_layer;
		if( old_layer >= LAY_TOP_COPPER )
		{
					int index = old_layer - LAY_TOP_COPPER;
					int new_layer = layer[index];
					if( new_layer == old_layer )
					{
						// do nothing
					}
					else if( new_layer == -1 )
					{
						// delete this text
						t->Undraw();
						RemoveText( t );
					}
					else
					{
						// move to new layer
						t->Undraw();
						t->m_layer = new_layer + LAY_TOP_COPPER;
						t->Draw( m_dlist, m_smfontutil ); 
					}
		}
		t = GetNextText();
	}
}
void CTextList::TextUndoCallback( int type, void * ptr, BOOL undo )
{
	int ifound;
	undo_text * un_t = (undo_text*)ptr;
	CText * text = 0;
	if( undo )
	{
		CTextList * tlist = un_t->m_tlist;
		if( type == CTextList::UNDO_TEXT_ADD || type == CTextList::UNDO_TEXT_MODIFY )
		{
			// find existing CText object
			ifound = -1;
			for( int it=0; it<tlist->text_ptr.GetSize(); it++ )
			{
				text = tlist->text_ptr[it];
				if( text->m_guid == un_t->m_guid )
				{
					ifound = it;
					break;
				}
			}
			if( ifound == -1 )
				ASSERT(0);	// text string not found
			if( type == CTextList::UNDO_TEXT_ADD )
			{
				// delete text
				tlist->RemoveText( text );
			}
			else if( type == CTextList::UNDO_TEXT_MODIFY )
			{
				// modify text back
				CDisplayList * dl = text->m_dlist;
				SMFontUtil * smf = text->m_smfontutil;
				text->Undraw();
				text->m_guid = un_t->m_guid;
				text->m_x = un_t->m_x;
				text->m_y = un_t->m_y;
				text->m_angle = un_t->m_angle;
				text->m_layer = un_t->m_layer;
				text->m_mirror = un_t->m_mirror;
				text->m_font_size = un_t->m_font_size;
				text->m_stroke_width = un_t->m_stroke_width;
				text->m_nchars = un_t->m_str.GetLength();
				text->m_str = un_t->m_str;
				text->Draw( dl, smf );
			}
		}
		else if( type == CTextList::UNDO_TEXT_DELETE )
		{
			// add deleted text back into list
			CText * new_text = tlist->AddText( un_t->m_x, un_t->m_y, un_t->m_angle, 
				un_t->m_mirror, un_t->m_bNegative,
				un_t->m_layer, un_t->m_font_size, un_t->m_stroke_width, &un_t->m_str );
			new_text->m_guid = un_t->m_guid;
		}
	}
	delete un_t;
}
void CTextList::MoveOrigin( int x_off, int y_off )
{
	for( int it=0; it<text_ptr.GetSize(); it++ )
	{
		CText * t = text_ptr[it];
		t->Undraw();
		t->m_x += x_off;
		t->m_y += y_off;
		t->Draw( m_dlist, m_smfontutil );
	}
}
Beispiel #5
0
/* This function will update the level and the text related to it */
void nextLevel(CLevel& level, CText& text) {
    level.setLevel(level.getLevel()+1);
    level.setLenWord(level.getLenWord()+1);
    level.setPoints(level.getPoints()+level.getPoints());
    level.setPtsToNext(level.getPtsToNext()+level.getPtsToNext());
    text.setString("Level: "+numberToString(level.getLevel()));
}
Beispiel #6
0
	Component* CText::CreateFromXML(tinyxml2::XMLElement* element) {
		const char* fontName = element->Attribute("fontName");
		const char* fontPath = element->Attribute("fontPath");
		int size = element->IntAttribute("fontSize");

		CText* label = new CText(fontName, fontPath, size);

		unsigned int col = 0xFFFFFFFF;
		if (element->Attribute("fontColor"))
			col = std::stoul(element->Attribute("fontColor"), NULL, 16);

		std::string text("");
		if (element->Attribute("text"))
			text = element->Attribute("text");

		label->SetColor(col);
		label->SetText(text);

		return label;
	}
Beispiel #7
0
/**
 *  \brief
 */
bool DbConfig::Write(FILE* fp) const
{
    bool success = false;

    CText libDbPaths;
    DbPathsToBuf(libDbPaths, _T(';'));

    CText pathFilters;
    FiltersToBuf(pathFilters, _T(';'));

    if (_ftprintf_s(fp, _T("%s\n"), cInfo) > 0)
    if (_ftprintf_s(fp, _T("%s%s\n"), cParserKey, Parser()) > 0)
    if (_ftprintf_s(fp, _T("%s%s\n"), cAutoUpdateKey, (_autoUpdate ? _T("yes") : _T("no"))) > 0)
    if (_ftprintf_s(fp, _T("%s%s\n"), cUseLibDbKey, (_useLibDb ? _T("yes") : _T("no"))) > 0)
    if (_ftprintf_s(fp, _T("%s%s\n"), cLibDbPathsKey, libDbPaths.C_str()) > 0)
    if (_ftprintf_s(fp, _T("%s%s\n"), cUsePathFilterKey, (_usePathFilter ? _T("yes") : _T("no"))) > 0)
    if (_ftprintf_s(fp, _T("%s%s\n"), cPathFiltersKey, pathFilters.C_str()) > 0)
        success = true;

    return success;
}
Beispiel #8
0
    /** HopperScreen, OnInit:
     *  Detailed description.
     *  @param argc TODO
     * @param argv TODO
     * @return TODO
     */
    bool HopperScreen::OnInit( int argc, char* argv[] ){
        // Master()->GetMainCanvas();
        CMainCanvas* m_pMainCanvas = Master()->GetMainCanvas();

        //m_pBackground = CCanvas::CreateRGBCompatible(NULL, 1024, 768 - 320);
        //m_pBackground = CCanvas::CreateRGBCompatible(NULL, NULL, NULL);
        // Todo: c:\program files\graphviz 2.28\bin\LIBFREETYPE-6.DLL copy from DEPS
        m_pArialfont = m_Loader.FL_LOADFONT("Fonts/ARIAL.TTF", 24);
        //m_pArialfont =
        // TTF_OpenFont("E:/Projects/C++/Humbug/projects/Humbug/Resources/Fonts/ARIAL.TTF", 24);
        mcol = CColor::White();
        SDL_Surface* tmpfsurf = ( m_Loader.FL_LOADIMG("Intro/HopperScreenBg.png") );

        //SDL_SetColorKey(tmpfsurf, SDL_TRUE, 0xff00ff);
        //SDL_SetColorKey(m_pMainCanvas->GetSurface(), SDL_TRUE, 0xff00ff);
        //SDL_SetSurfaceAlphaMod(tmpfsurf, 0);
        //SDL_SetSurfaceAlphaMod(m_pMainCanvas->GetSurface(), 128);
        m_pBackground.reset( new CCanvas( tmpfsurf ) );

        //CCanvas tmpCanvas( tmpfsurf );
        m_Loader.FreeLast();

        //m_pMainCanvas->Blit(m_pMainCanvas->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
        //m_pBackground->Blit(m_pBackground->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
        m_pMainCanvas->AddUpdateRect( m_pBackground->GetDimension() );

        //"\r\n"
        CColor m_colText = CColor::White();
        std::ostringstream outstring;
        outstring << "Jedzia";
        outstring << " .................... ";
        outstring << "328.123.847";

        CText* text = new CText(m_pArialfont, outstring.str(), m_colText);

        //const boost::function<void(CCanvas*, int)> textMo = mtextfloat;
        //text->AddAnimator(boost::ref( mtextfloat ));
        text->AddAnimator( WavyTextFloat(64) );
        m_pScrollText.reset(text);

        // ### Sprites ###
        m_pSprEye = new CSprite(m_Loader, "Sprites/male_sprites.png", m_pMainCanvas, CPoint(64, 0),
                CRectangle(0, 0, 64, 64) );
        m_pSprMgr->AddSprite(m_pSprEye, "mytag", hspriv::EyeMover(160, 8));
        //m_pSprMgr->AddSprite(m_pSprEye, boost::ref( pimpl_->eyemover ) );
        //m_pSprMgr->AddSprite(m_pSprEye);
        CSprite* m_pSprWormler = new CSprite(m_Loader, "Sprites/wormtiles.png", m_pMainCanvas, CPoint(0, 64),
                CRectangle(0, 0, 256, 64) );
        m_pSprWormler->SetColorAndAlpha(0xff00ff, 128);
        m_pSprMgr->AddSprite(m_pSprWormler, "mytag", hspriv::EyeMover(260, 40));

        //_CrtSetBreakAlloc(pimpl_->allocReqNum+4);
        //_crtBreakAlloc = pimpl_->allocReqNum+4;

        shost::ScriptHost shost;
        //shost.RunScript2(m_Loader.FL_LOADASSTRING("Lua/hello.lua"));
        // shost.RunScript(m_Loader.FL_LOADASSTRING("Lua/funcret.lua"));
        //shost.RunScript4(m_Loader.FL_LOADASSTRING("Lua/iowrite.lua"));
        //shost.RunScript(m_Loader.FL_LOADASSTRING("Lua/globalclass.lua"));
        //shost.RunScript6( m_Loader.FL_LOADASSTRING("Lua/globalclass.lua") );
		//shost.RunScript7( m_Loader.FL_LOADASSTRING("Lua/--FREE--.lua") );

		typedef shost::LuaScript<int, double, double> ScriptType;
		ScriptType::Script s = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
			"Lua/sprite1.lua"), "Ticks", "X", "Y" );
		pimpl_->script = s;

        world.FPS = CApplication::FramesCap();
        CRectangle screenRect = m_pMainCanvas->GetDimension();
        world.ScreenX = screenRect.GetW();
        world.ScreenY = screenRect.GetH();

		// Todo maybe an functor to initialize more global stuff
		(*s->AddStatic(world))("World")
			.def("greet", &greetHopper)
			.def_readonly("FPS", &World::FPS)
			.def_readonly("ScreenX", &World::ScreenX)
			.def_readonly("ScreenY", &World::ScreenY);



		ScriptType::Script sprInit = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
			"Sprites/male_sprites.spr"), "Ticks", "X", "Y" );
		//ScriptType::Script sprInit = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
		//	"Sprites/male_sprites.spr"), "Ticks", "X", "Y" );

		TestClass st(12,99);

		(*sprInit->AddStatic(st))("TestClass", "tc")
			.def(luabind::constructor<std::vector<int> >())
			.def(luabind::constructor<int, int>())
			.def("get", &TestClass::get);

		//boost::shared_ptr<shost::LuaScript::register_binder<SpriteFrame >>& bla=
		int xyz = 55;

		typedef shost::LuaVarCapsule<luabind::class_<SpriteFrame>> SprCapsule;
		SprCapsule maleSpriteCap = shost::makeFarm(sprInit,
		(*sprInit->Register<SpriteFrame>())("SpriteFrame")
			.def(luabind::constructor<int, int>())
			.def("X", &SpriteFrame::X)
			.def("Y", &SpriteFrame::Y));

		(*sprInit->Register<SpriteMovieOld>())("SpriteMovieOld")
			.def(luabind::constructor<std::string, SpriteFrame>())
			.def("X", &SpriteMovieOld::X)
			.def("Y", &SpriteMovieOld::Y);

		(*sprInit->Register<SpriteMovie>())("SpriteMovie")
			.def(luabind::constructor<std::string, std::vector<SpriteFrame>>())
			.def("X", &SpriteMovie::X)
			.def("Y", &SpriteMovie::Y);

		//luabind::class_<SpriteFrame>& xasd = maleSpriteCap.Value();
		//SprCapsule::ObjType mmy(1,2);
		//mmy.X();

		/*luabind::module(sprInit->L())
			[
				luabind::class_<TestClass>("TestClass_")
				.def(luabind::constructor<std::vector<int> >())
				.def(luabind::constructor<int, int>())
				.def("get", &TestClass::get)
			];*/


		int success = sprInit->run_script(99);

		luabind::object o3(luabind::globals(sprInit->L())["tcx"]);
		if (o3)
		{
			// is_valid
			// ...

			int luatype = luabind::type(o3);
			if (luabind::type(o3) == LUA_TUSERDATA)
			{
				TestClass otherValue = luabind::object_cast<TestClass>(o3);
				int abc = 4;
				abc++;
			}
		}

		SpriteFrame otherValue2(0,0);
		bool success3 = maleSpriteCap.GetLuaValue("spf", otherValue2);
		SpriteFrame otherValuex = maleSpriteCap.GetLuaValue("spf");

		SpriteFrame otherValue3(0,0);
		bool fsuccess = sprInit->GetLuaValue<SpriteFrame>("spf", otherValue3);

		luabind::object o4(luabind::globals(sprInit->L())["spf"]);
		if (o4)
		{
			// is_valid
			// ...

			int luatype = luabind::type(o4);
			if (luabind::type(o4) == LUA_TUSERDATA)
			{
				SpriteFrame otherValue = luabind::object_cast<SpriteFrame>(o4);
				int abc = 4;
				abc++;
			}
		}




		//SpriteMovie otherValue3(0,0);
		//fsuccess = sprInit->GetLuaValue<SpriteMovie>("spMovie", otherValue3);
		SpriteMovieOld smovieOld = sprInit->GetLuaValue<SpriteMovieOld>("spMovieOld");
		SpriteMovie smovie = sprInit->GetLuaValue<SpriteMovie>("spMovie");

		//int *x = new int(666);

        return Screen::OnInit(argc, argv);
    } // OnInit
Beispiel #9
0
void CRenderList::refresh()
{
    m_draw.clear();

    m_drawAlpha.clear();
    m_drawStatic.clear();
    m_drawTransparency.clear();

    u32 size = (u32)m_list.size();
    m_drawAlpha.reserve(size);
    m_drawStatic.reserve(size);
    m_drawTransparency.reserve(size);

    for (std::vector<SNodeList>::iterator iter = m_list.begin(); iter < m_list.end(); ++iter)
    {
        CNode* node = (*iter)._node;
        switch (node->getNodeType())
        {
            case ENodeType::eShape:
            case ENodeType::eMesh:
            case ENodeType::eBillboard:
            case ENodeType::eParticleSystem:
            {
                f32 priority = 0.0f;
                CMesh* mesh = static_cast<CMesh*>(node);
                const MaterialPtr& material = mesh->getMaterial();
                if (material->getTransparency() < 1.0f)
                {
                    if (m_camera)
                    {
                        priority = (node->getAbsPosition() - m_camera->getAbsPosition()).length();
                    }
                    else
                    {
                        priority = node->getAbsPosition().z;
                    }
                    node->setPriority(priority);

                    if (checkDistance(node, priority))
                    {
                        m_drawTransparency.push_back((*iter));
                    }
                }
                else if (mesh->getRenderTechique()->getRenderPass((*iter)._passIndex)->getRenderState()->isBlend())
                {
                    if (m_camera)
                    {
                        priority = (node->getAbsPosition() - m_camera->getAbsPosition()).length();
                    }
                    else
                    {
                        priority = node->getAbsPosition().z;
                    }
                    node->setPriority(priority);

                    if (checkDistance(node, priority))
                    {
                        m_drawAlpha.push_back((*iter));
                    }
                }
                else
                {
                    if (checkDistance(node, priority))
                    {
                        m_drawStatic.push_back((*iter));
                    }
                }
            }
                break;

            case ENodeType::eCamera:
            {
                /*node->setPriority(k_maxPriority);
                if (static_cast<CCamera*>(node)->isActive())
                {
                    m_update.push_back(node);
                }*/
            }
                break;

            case ENodeType::eSkyBox:
            {
                node->setPriority(k_maxPriority);
                m_drawStatic.push_back((*iter));
            }
                break;

            case ENodeType::eLight:
            case ENodeType::eFog:
            {
                node->setPriority(-k_maxPriority);
            }
                break;

            case ENodeType::eText:
            {
                node->setPriority(0.0f);

                CText* text = static_cast<CText*>(node);
                const MaterialPtr& material = text->getMaterial();
                if (material->getTransparency() < 1.0f)
                {
                    m_drawTransparency.push_back((*iter));
                }
                else if (text->getRenderTechique()->getRenderPass((*iter)._passIndex)->getRenderState()->isBlend())
                {
                    m_drawAlpha.push_back((*iter));
                }
                else
                {
                    m_drawStatic.push_back((*iter));
                }
            }
                break;

            case ENodeType::eModel:
            default:
                break;
        }
    }

    m_drawStatic.shrink_to_fit();
    m_draw.insert(m_draw.begin(), m_drawStatic.begin(), m_drawStatic.end());

    if (!m_drawTransparency.empty())
    {
        m_drawTransparency.shrink_to_fit();
        std::sort(m_drawTransparency.begin(), m_drawTransparency.end(), [](const SNodeList& node0, const SNodeList& node1) -> bool
        {
            return  (node0._node->getPriority() > node1._node->getPriority());
        });
        m_drawAlpha.insert(m_drawAlpha.end(), m_drawTransparency.begin(), m_drawTransparency.end());
    }

    if (!m_drawAlpha.empty())
    {
        m_drawAlpha.shrink_to_fit();
        std::sort(m_drawAlpha.begin(), m_drawAlpha.end(), [](const SNodeList& node0, const SNodeList& node1) -> bool
        {
            return  (node0._node->getPriority() > node1._node->getPriority());
        });
        m_draw.insert(m_draw.end(), m_drawAlpha.begin(), m_drawAlpha.end());
    }
}
Beispiel #10
0
/**
**  Get text data.
**
**  @param l  Lua state.
*/
static int CclGetTextData(lua_State *l)
{
	if (lua_gettop(l) < 2) {
		LuaError(l, "incorrect argument");
	}
	std::string text_name = LuaToString(l, 1);
//	const CText *text = GetText(text_name);
	CText *text = GetText(text_name);
	if (!text) {
		LuaError(l, "Text \"%s\" doesn't exist." _C_ text_name.c_str());
	}
	const char *data = LuaToString(l, 2);

	if (!strcmp(data, "Author")) {
		lua_pushstring(l, text->Author.c_str());
		return 1;
	} else if (!strcmp(data, "Translator")) {
		lua_pushstring(l, text->Translator.c_str());
		return 1;
	} else if (!strcmp(data, "Publisher")) {
		lua_pushstring(l, text->Publisher.c_str());
		return 1;
	} else if (!strcmp(data, "CopyrightNotice")) {
		lua_pushstring(l, text->CopyrightNotice.c_str());
		return 1;
	} else if (!strcmp(data, "Notes")) {
		lua_pushstring(l, text->Notes.c_str());
		return 1;
	} else if (!strcmp(data, "Year")) {
		lua_pushnumber(l, text->Year);
		return 1;
	} else if (!strcmp(data, "InitialPage")) {
		lua_pushnumber(l, text->InitialPage);
		return 1;
	} else if (!strcmp(data, "Chapters")) {
		lua_createtable(l, text->Chapters.size(), 0);
		for (size_t i = 1; i <= text->Chapters.size(); ++i)
		{
			lua_pushstring(l, text->Chapters[i-1]->Name.c_str());
			lua_rawseti(l, -2, i);
		}
		return 1;
	} else if (!strcmp(data, "ChapterQuantity")) {
		lua_pushnumber(l, text->Chapters.size());
		return 1;
	} else if (!strcmp(data, "ChapterIndex")) {
		LuaCheckArgs(l, 3);
		std::string chapter_name = LuaToString(l, 3);
		if (text->GetChapter(chapter_name) != nullptr) {
			lua_pushnumber(l, text->GetChapter(chapter_name)->ID);
		} else {
			LuaError(l, "Chapter \"%s\" doesn't exist for text \"%s\"" _C_ chapter_name.c_str() _C_ text->Name.c_str());
		}
		return 1;
	} else if (!strcmp(data, "ChapterIntroduction")) {
		LuaCheckArgs(l, 3);
		std::string chapter_name = LuaToString(l, 3);
		if (text->GetChapter(chapter_name) != nullptr) {
			lua_pushboolean(l, text->GetChapter(chapter_name)->Introduction);
		} else {
			LuaError(l, "Chapter \"%s\" doesn't exist for text \"%s\"" _C_ chapter_name.c_str() _C_ text->Name.c_str());
		}
		return 1;
	} else if (!strcmp(data, "ChapterPage")) {
		LuaCheckArgs(l, 4);
		
		std::string chapter_name = LuaToString(l, 3);
		if (text->GetChapter(chapter_name) != nullptr) {
			int page = LuaToNumber(l, 4) - 1;
			
			lua_pushstring(l, text->GetChapter(chapter_name)->Pages[page].c_str());
		} else {
			LuaError(l, "Chapter \"%s\" doesn't exist for text \"%s\"" _C_ chapter_name.c_str() _C_ text->Name.c_str());
		}
		return 1;
	} else if (!strcmp(data, "ChapterPageQuantity")) {
		LuaCheckArgs(l, 3);
		std::string chapter_name = LuaToString(l, 3);
		if (text->GetChapter(chapter_name) != nullptr) {
			lua_pushnumber(l, text->GetChapter(chapter_name)->Pages.size());
		} else {
			LuaError(l, "Chapter \"%s\" doesn't exist for text \"%s\"" _C_ chapter_name.c_str() _C_ text->Name.c_str());
		}
		return 1;
	} else {
		LuaError(l, "Invalid field: %s" _C_ data);
	}

	return 0;
}
Beispiel #11
0
BOOL CItemList::DrawItem( DWORD i, HDC hDC, LPRECT pRect)
{
	CText				text;
	RECT				rect;
	LPLISTSUBITEMINFO	plsii = m_pIndex[ i ]->head;
	LPHEADERITEMINFO	phii = NULL;

	text.SetFlags( DT_SINGLELINE | DT_VCENTER );
	text.SetColor( m_rgbText );

	// Use bold text for group names
	if ( ( m_pIndex[ i ]->flags & LIF_GROUP ) != 0 )
		text.SetWeight( FW_BOLD );

	// Rect
	CopyRect( &rect, pRect ); InflateRect( &rect, 0, -1 );

	if ( ( m_pIndex[ i ]->flags & LIF_SELECTED ) != 0 &&
		 ( m_pIndex[ i ]->flags & LIF_GROUP ) == 0 )
	{
		CGrDC::VertGradientFill( hDC, &rect, m_rgbSelTop, m_rgbSelBottom );
	} // end if

	// Adjust for horz scroll
	rect.left -= m_lHScroll;

//	rect.top += 1;

	BOOL bSpecialFont = TRUE;

	// Draw all items
	while ( ( phii = m_header.GetNext( phii ) ) != NULL && 
			plsii != NULL && rect.left < pRect->right )
	{
		// Set special font
		if ( plsii->pfont != NULL ) { bSpecialFont = TRUE; text.SetFont( plsii->pfont ); }

		// Set default font
		else if ( bSpecialFont ) { bSpecialFont = FALSE; text.SetFont( 16, "Arial" ); }

		if ( m_bGroups && ( m_pIndex[ i ]->flags & LIF_GROUP ) != 0 )
			rect.right = pRect->right;

		else
		{	// Calculate item width
			rect.right = rect.left + phii->width;
			if ( rect.right > pRect->right ) rect.right = pRect->right;
		} // end else

		if ( rect.right > pRect->left )
		{
			// Fill in bck if needed
			if ( ( m_pIndex[ i ]->flags & LIF_SELECTED ) != 0 &&
				 ( m_pIndex[ i ]->flags & LIF_GROUP ) == 0 )
			{
				if ( plsii->rgbbck != MAXDWORD )
				{		
					RECT b;
					CopyRect( &b, &rect );
					InflateRect( &b, -2, -1 ); b.top++; b.right--;
					CGrDC::FillSolidRect( hDC, &b, plsii->rgbbck );
//					COLORREF bottom = CGrDC::ScaleColor( plsii->rgbbck, -50 );
//					CGrDC::GradientFill( hDC, &rect, plsii->rgbbck, bottom );
				} // end if
			} // end if
			else
			{
				if ( plsii->rgbbck != MAXDWORD )
				{
					RECT b;
					CopyRect( &b, &rect );
					InflateRect( &b, -2, -1 ); b.top++; b.right--;
					CGrDC::FillSolidRect( hDC, &b, plsii->rgbbck );
//					CGrDC::GradientFill( hDC, &rect, plsii->rgbbck, m_rgbSelBottom );
				} // end if
			} // end else

			// Draw icon if needed
			if ( plsii->icon != NULL )
			{
				DrawIconEx( hDC, rect.left + 2, rect.top + 2, plsii->icon, 
							16, 16, 0, NULL, DI_NORMAL );
				rect.left += 17;
			} // end if

			if ( plsii->type == SIT_TEXT )
			{
				rect.left += 3;

				// Did the user specify a color?
				if ( plsii->rgbtext != MAXDWORD ) text.SetColor( plsii->rgbtext );

				// Is Item selected?
				else if (	( m_pIndex[ i ]->flags & LIF_SELECTED ) != 0 &&
							( m_pIndex[ i ]->flags & LIF_GROUP ) == 0 )

					text.SetColor( m_rgbSelText );

				// Set default text color
				else text.SetColor( m_rgbText );


				text.DrawText( hDC, (char*)plsii->data, &rect );			
			} // end if

		} // end if

		// Shift rect
		rect.left = rect.right;

		// Next sub-item
		plsii = plsii->pNext; 

	} // end while

	return TRUE;
}
Beispiel #12
0
 // Function to display a message
 void ShowIt() const
 {
   text.ShowIt();
 }
Beispiel #13
0
void RevealedElem::displayBoard(sf::RenderWindow& window, sf::Font& mainScreenFont)
{
    int i, j;// variabile intermediare pentru a parcurge toate celule
    //tablei de joc

    //X , Y variabile intermediare pentru parcurgearea saltata a tablei,
    //X,si Y reprezentand  coltul stang al fiecarei celule

    sf::CircleShape cerc(cellSize/2);
    cerc.setPointCount(25);

    CText numarMine;
    numarMine.setFont(mainScreenFont);
    numarMine.setSize(fontSize);

    CText semnIntrebare;
    semnIntrebare.setFont(mainScreenFont);
    semnIntrebare.setSize(fontSize);

    sf::Texture imgBomba;
    imgBomba.loadFromFile("data/images/bomb.png");
    sf::Transform transformareImagine;
    transformareImagine.scale(5,5);
    sf::Sprite bomba;
    bomba.setTexture(imgBomba);
    bomba.setOrigin(imgBomba.getSize().x / 2, imgBomba.getSize().y / 2);
    float bombScale = remap(fontSize , 1 , bomba.getLocalBounds().width, 0, 1);
    bomba.setScale(bombScale, bombScale);

    for(int Y = startGridY, i = 1; i <= size; Y +=cellSize, i++)
    {
        for(int X = startGridX, j = 1; j <= size; X += cellSize, j++)
        {
            switch(board[i][j])
            {

            case hidden:

                cerc.setPosition(X, Y);
                cerc.setFillColor(sf::Color::White);

                semnIntrebare.setColor(sf::Color::Black);
                semnIntrebare.setPosition(sf::Vector2f(X + cellSize/2, Y + cellSize/2));//
                semnIntrebare.setString("?");
                //semnIntrebare.setSize(20);
                semnIntrebare.centerTextOrigin();


                //std::cout << X << " " << Y << std::endl;
                break;
            case empty:

                cerc.setPosition(X, Y);
                cerc.setFillColor(sf::Color(209, 209, 209));
                //std::cout << X << " " << Y << std::endl;
                break;
            case mine:
                cerc.setPosition(X, Y);
                cerc.setFillColor(sf::Color::Red);
                bomba.setPosition(X + cellSize / 2, Y + cellSize / 2);
                break;
            default:

                cerc.setPosition(X, Y);
                cerc.setFillColor(sf::Color::Yellow);


                numarMine.setColor(sf::Color::Red);
                //numarMine.setSize(20);

                numarMine.setPosition(sf::Vector2f(X + cellSize/2, Y + cellSize/2));//
                std::stringstream strStream;
                strStream << board[i][j];
                std::string temp = strStream.str();
                numarMine.setString(temp.c_str());
                numarMine.centerTextOrigin();

            }
            window.draw(cerc);

            switch(board[i][j])
            {
                case empty:

                case mine:
                    window.draw(bomba);
                    break;
                case hidden:
                    semnIntrebare.draw(window);
                    break;
                default:
                    numarMine.draw(window);

            }

            // Setari temporare pentru a vedea daca pozitiile calculate
            // sunt corecte

        }
    }
    //std::cout << cellSize << std::endl;
}
Beispiel #14
0
BOOL CWinMenu::DrawMenuItems(HDC hDC, LPRECT pRect)
{
	if ( hDC == NULL || pRect == NULL ) return FALSE;

	BOOL bFirst = m_bFirstDraw;
	m_bFirstDraw = FALSE;

	CText		text;
	long		x = pRect->left + 4;
	long		y = pRect->top + 4;
	long		w = pRect->right - pRect->left - 8;

	long		bx = x;
	long		by = y;

	// Set colors
	COLORREF rgbMenu, rgbMenuText, rgbSel, rgbSelText;

	if ( m_bSystemColors )
	{	rgbMenu = GetSysColor( COLOR_MENU );
		rgbMenuText = GetSysColor( COLOR_MENUTEXT );
		rgbSel = GetSysColor( COLOR_HIGHLIGHT );
		rgbSelText = GetSysColor( COLOR_HIGHLIGHTTEXT );
	} // end if
	else
	{	rgbMenu = m_rgbMenu;
		rgbMenuText = m_rgbMenuText;
		rgbSel = m_rgbSel;
		rgbSelText = m_rgbSelText;
	} // end else


	COLORREF	rgbLightPen = ScaleColor( rgbMenu, 100 );
	COLORREF	rgbDarkPen = ScaleColor( rgbMenu, -150 );

	COLORREF	rgbBck = rgbMenu;
	COLORREF	rgbBckLt = ScaleColor( rgbBck, 40 );
	COLORREF	rgbBckDk = ScaleColor( rgbBck, -40 );
	COLORREF	rgbSelLt = ScaleColor( rgbSel, 80 );
	COLORREF	rgbSelDk = ScaleColor( rgbSel, -120 );
	COLORREF	rgbSelTextLt = ScaleColor( rgbSelText, 80 );
	COLORREF	rgbSelTextDk = ScaleColor( rgbSelText, -150 );
	COLORREF	rgbBumpLt = ScaleColor( rgbBck, 120 );
	COLORREF	rgbBumpDk = ScaleColor( rgbBck, -120 );

	COLORREF	rgbText = rgbMenuText;
	COLORREF	rgbTextLt = ScaleColor( rgbBck, 100 );
	COLORREF	rgbTextDk = ScaleColor( rgbBck, -100 );

	if ( GetColorAvg( rgbSel ) > 128 )
	{	COLORREF swap = rgbSelTextLt;
		rgbSelTextLt = rgbSelTextDk; rgbSelTextDk = swap;
	} // end if


	// What font does the user want for menu's?
	NONCLIENTMETRICS info;
	info.cbSize = sizeof(info);			
	SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof( info ), &info, 0 );

	// Check for empty menu	
	if ( m_mitems.Size() == 0 )
	{
		COLORREF rgbEmptyLt = ScaleColor( rgbBck, 120 );
		COLORREF rgbEmptyDk = ScaleColor( rgbBck, -120 );

		if ( GetColorAvg( rgbBck ) < 128 ) 
		{	COLORREF swap = rgbEmptyLt;
			rgbEmptyLt = rgbEmptyDk; rgbEmptyDk = swap;
		} // end if

		RECT t;
		CopyRect( &t, pRect );

		text.SetWeight( FW_BOLD );
		text.SetFont( &info.lfMenuFont );
		text.SetFlags( DT_SINGLELINE | DT_CENTER | DT_VCENTER );

		// Make text look recessed
		OffsetRect( &t, -1, -1 );
		text.SetColor( rgbEmptyDk );
		text.DrawText( hDC, EMPTY_STR, &t );

		OffsetRect( &t, 1, 1 );
		text.SetColor( rgbEmptyLt );
		text.DrawText( hDC, EMPTY_STR, &t );

	} // end if
	
	
	// This kinda bites, but we need to know how far to offset the text
	BOOL islots = 0;
	LPMITEMINFO	pmi = NULL;
	while(	islots < 2 && ( pmi = (LPMITEMINFO)m_mitems.GetNext( pmi ) ) != NULL )
	{
		// Do we need both icon slots?
		if ( pmi->icon != NULL && pmi->b != NULL ) islots = 2;

		// Do we have one islot already?
		else if ( islots < 1 )
		{
			if ( pmi->icon != NULL ) islots = 1;
			
			else if ( pmi->b != NULL && m_hCheck == NULL && m_hUncheck == NULL )
				islots = 1;
		} // end else if

	} // end while

	
	// The icon size
	long iconsize = m_th - 4;

	// Draw each item
	pmi = NULL;
	while(	( pmi = (LPMITEMINFO)m_mitems.GetNext( pmi ) ) != NULL &&
			x < pRect->right && y < pRect->bottom )
	{
		// Set base coords
		bx = x; by = y;

		if ( *pmi->name != NULL )
		{
			POINT	pt;
			GetCursorPos( &pt );
			ScreenToClient( &pt );

			// Is this item being selected?
			BOOL bSelected = FALSE;
			RECT hl;
			hl.left = pRect->left + 3;
			hl.right = pRect->right - 4;
			hl.top = by;
			hl.bottom = by + m_th;
//			if (	pt.x > hl.left && pt.x < hl.right &&
//					pt.y > hl.top && pt.y < hl.bottom )

			// Add for toolbar
			if ( pmi->toolbar != NULL && pmi->toolbar->GetNumButtons() )
				hl.left += pmi->toolbar->GetWidth();


			if ( pmi == m_itemover )
			{
				bSelected = TRUE;
//				HPEN whitepen = CreatePen( PS_SOLID, 1, RGB( 255, 255, 255 ) );
//				HPEN dkgraypen = CreatePen( PS_SOLID, 1, RGB( 50, 50, 50 ) );
				HPEN whitepen = CreatePen( PS_SOLID, 1, rgbLightPen );
				HPEN dkgraypen = CreatePen( PS_SOLID, 1, rgbDarkPen );
				HPEN oldpen = (HPEN)SelectObject( hDC, whitepen );

				// Draw white line
				MoveToEx( hDC, hl.right, hl.top, NULL );
				LineTo( hDC, hl.right, hl.bottom  );
				LineTo( hDC, hl.left, hl.bottom  );

				// Draw dark gray line
				SelectObject( hDC, dkgraypen );
				MoveToEx( hDC, hl.right, hl.top, NULL );
				LineTo( hDC, hl.left, hl.top  );
				LineTo( hDC, hl.left, hl.bottom  );

				SelectObject( hDC, oldpen );
				DeleteObject( whitepen );
				DeleteObject( dkgraypen );

//				InflateRect( &hl, -1, -1 );
				hl.left += 1;
				hl.top += 1;

//				GradientFill( hDC, &hl, RGB( 170, 170, 190 ), RGB( 110, 110, 110 ) );
				CGrDC::VertGradientFill( hDC, &hl, rgbSelLt, rgbSelDk );
/*				HBRUSH brush = CreateSolidBrush( RGB( 120, 120, 120 ) );
				FillRect( hDC, &hl, brush );
				DeleteObject( brush );
*/

			} // end if

			// Draw toolbar
			if ( pmi->toolbar != NULL && pmi->toolbar->GetNumButtons() )
			{	pmi->toolbar->SetHeight( m_th );

				RECT tbar;
				SetRect( &tbar, bx, by, bx + pmi->toolbar->GetWidth(), 
									by + pmi->toolbar->GetHeight() );

				if ( bFirst ) pmi->toolbar->CreateToolTips( GetSafeHwnd(), &tbar );
				pmi->toolbar->SetMessageTarget( GetSafeHwnd(), WM_MENUCMD );
				pmi->toolbar->Draw( GetSafeHwnd(), hDC, &tbar );
			
				bx += pmi->toolbar->GetWidth();
			} // end if

			RECT t;

			// Calc text box
			t.left = bx + 4;
			t.left += islots * iconsize;
			t.right = pRect->right;
			t.top = by;
			t.bottom = by + m_th;

			// Draw Check
			if ( pmi->b != NULL )
			{
				RECT icon;
				SetRect( &icon, bx + 2, by + 2, bx + 2 + iconsize, by + 2 + iconsize );

				if ( *pmi->b != FALSE )
				{
					if ( bSelected && m_hHotCheck != NULL )
						CGrDC::DrawIcon( hDC, &icon, m_hHotCheck );
//						DrawIconEx( hDC, bx + 2, by + 2, m_hHotCheck, iconsize, iconsize, 0, 0, DI_NORMAL );

					else if ( m_hCheck != NULL )
						CGrDC::DrawIcon( hDC, &icon, m_hCheck );
//						DrawIconEx( hDC, bx + 2, by + 2, m_hCheck, iconsize, iconsize, 0, 0, DI_NORMAL );
				} // end if
				else 
				{
					if ( bSelected && m_hHotUncheck != NULL )
						CGrDC::DrawIcon( hDC, &icon, m_hHotUncheck );
//						DrawIconEx( hDC, bx + 2, by + 2, m_hHotUncheck, iconsize, iconsize, 0, 0, DI_NORMAL );

					else if ( m_hUncheck != NULL )
						CGrDC::DrawIcon( hDC, &icon, m_hUncheck );
//						DrawIconEx( hDC, bx + 2, by + 2, m_hUncheck, iconsize, iconsize, 0, 0, DI_NORMAL );
				} // end else
			} // end if

			// Draw icon
			if ( pmi->icon != NULL ) 
			{
				long xoff = 2;
				xoff += iconsize * ( islots - 1 ) + 1;


//				DrawIconEx( hDC, x + xoff, y + 2, pmi->icon,
//							16, 16, 0, 0, DI_NORMAL );

				DrawIconEx( hDC, bx + xoff, by + 2, pmi->icon,
							iconsize, iconsize, 0, 0, DI_NORMAL );



			} // end if

			// Setup the text object
			text.SetFlags( DT_SINGLELINE | DT_VCENTER );

			if ( bSelected )
			{
				text.SetWeight( FW_BOLD );
				text.SetFont( &info.lfMenuFont );
	
				// Make text look recessed
				OffsetRect( &t, -1, -1 );
//				text.SetColor( RGB( 0, 0, 0 ) );
				text.SetColor( rgbSelTextDk );
				text.DrawText( hDC, pmi->name, &t );

				OffsetRect( &t, 1, 1 );
				text.SetColor( rgbSelTextLt );
			} // end if
			else
			{
//				text.SetItalic( FALSE );
				text.SetWeight( FW_BOLD );
				text.SetFont( &info.lfMenuFont );
//				text.SetFont( TFONTSIZE, TFONTTYPE );
//				text.SetColor( RGB( 0, 50, 128 ) );
				text.SetColor( rgbText );
			} // end else
//			else text.SetColor( rgbText );
//			text.SetColor( RGB( 0, 50, 128 ) );
			text.DrawText( hDC, pmi->name, &t );

			// Draw sub menu indicator
			if ( pmi->submenu != NULL )
			{
				// Do we have a tick mark icon?
				if ( m_hTick != NULL )
				{
					RECT ic;
					SetRect( &ic, t.right - 18, t.top + 5, t.right - 8, t.bottom - 7 );

					// Colorize tick icon
					HICON hMono = NULL;
					if ( !pmi->submenu->IsEmpty() ) 
						hMono = CGrDC::CreateMonoChromeIcon( m_hTick, GetSysColor( COLOR_ACTIVECAPTION ) );
					else hMono = CGrDC::CreateMonoChromeIcon( m_hTick, GetSysColor( COLOR_INACTIVECAPTION ) );
//						hMono = CGrDC::CreateMonoChromeIcon( m_hTick, rgbSel );
//					else hMono = CGrDC::CreateMonoChromeIcon( m_hTick, rgbBck );

					// Draw the icon
					if ( hMono != NULL )
					{	
						CGrDC::DrawIcon( hDC, &ic, hMono );
						DestroyIcon( hMono );
					} // end if

				} // end if
				else
				{
					HPEN whitepen = CreatePen( PS_SOLID, 1, rgbLightPen );
					HPEN dkgraypen = CreatePen( PS_SOLID, 1, ScaleColor( rgbBck, -10 ) );
					HPEN blackpen = CreatePen( PS_SOLID, 1, ScaleColor( rgbBck, -40 ) );
					HPEN oldpen = (HPEN)SelectObject( hDC, whitepen );				
					HBRUSH mbrush;
					if ( !pmi->submenu->IsEmpty() ) mbrush = CreateSolidBrush( rgbBck );
					else mbrush = CreateSolidBrush( ScaleColor( rgbBck, -80 ) );
					HBRUSH oldbrush = (HBRUSH)SelectObject( hDC, mbrush );

					POINT	pts[ 3 ];

					pts[ 0 ].x = t.right - 14;
					pts[ 0 ].y = t.top + 5;
					pts[ 1 ].x = t.right - 14;
					pts[ 1 ].y = t.bottom - 7;
					pts[ 2 ].x = t.right - 8;
					pts[ 2 ].y = t.top + ( ( t.bottom - t.top ) / 2 );

					// Draw the shape
					Polygon( hDC, pts, sizeof( pts ) / sizeof( POINT ) );

					// Draw border
					MoveToEx( hDC, pts[ 0 ].x, pts[ 0 ].y, NULL );
					LineTo( hDC, pts[ 1 ].x, pts[ 1 ].y );
					SelectObject( hDC, blackpen );
					LineTo( hDC, pts[ 2 ].x, pts[ 2 ].y );
					SelectObject( hDC, dkgraypen );
					LineTo( hDC, pts[ 0 ].x, pts[ 0 ].y ); 


					// Release drawing objects
					SelectObject( hDC, oldpen );
					DeleteObject( whitepen );
					DeleteObject( dkgraypen );
					DeleteObject( blackpen );
					SelectObject( hDC, oldbrush );
					DeleteObject( mbrush );

				} // end if

			} // end if

			// Next menu item position
			y += m_th;
		} // end if

		else // separator
		{
//			HPEN whitepen = CreatePen( PS_SOLID, 1, RGB( 255, 255, 255 ) );
//			HPEN dkgraypen = CreatePen( PS_SOLID, 1, RGB( 50, 50, 50 ) );
			HPEN whitepen = CreatePen( PS_SOLID, 1, rgbBumpLt );
			HPEN dkgraypen = CreatePen( PS_SOLID, 1, rgbBumpDk );
			HPEN oldpen = (HPEN)SelectObject( hDC, whitepen );

			// Draw white line
			MoveToEx( hDC, bx + 2, by + 2, NULL );
			LineTo( hDC, ( pRect->right - pRect->left ) - 2, by + 2 );

			// Draw dark gray line
			SelectObject( hDC, dkgraypen );
			MoveToEx( hDC, bx + 2, by + 3, NULL );
			LineTo( hDC, ( pRect->right - pRect->left ) - 2, by + 3 );

			SelectObject( hDC, oldpen );
			DeleteObject( whitepen );
			DeleteObject( dkgraypen );

			y += 6;

		} // end else

	} // end while

	return TRUE;
}
Beispiel #15
0
BOOL CWinMenu::GetMenuRect(long x, long y, LPRECT pRect)
{
	if ( pRect == NULL ) return FALSE;

	long	w = 0;
	long	h = 8;
	RECT	rect;
	CText	text;
	HDC		hDC = ::GetDC( NULL );

	// Punt if no dc
	if ( hDC == NULL ) return FALSE;

	m_tw = w;
	m_th = 20;

	// What font does the user want for menu's?
	NONCLIENTMETRICS info;
	info.cbSize = sizeof(info);			
	SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof( info ), &info, 0 );

	text.SetWeight( FW_BOLD );
	text.SetFont( &info.lfMenuFont );

	// Handle NULL menu
	if ( m_mitems.Size() == 0 )
	{
		// Get size of empty string
		SetRect( &rect, 0, 0, 10, 10 );
//		text.SetFlags( DT_SINGLELINE | DT_CENTER | DT_VCENTER );
		text.SetFlags( 0 );
		text.CalcRect( hDC, EMPTY_STR, &rect );

		// Save text params
		w = ( rect.right - rect.left );
		if ( rect.bottom - rect.top > 20 )
		{
			m_th = rect.bottom - rect.top;
			h += m_th;
		} else h += 20;

	} // end if

	LPMITEMINFO	pmi = NULL;
	while(	( pmi = (LPMITEMINFO)m_mitems.GetNext( pmi ) ) != NULL )
	{
		if ( *pmi->name != NULL )
		{
			// Acc. width
			SetRect( &rect, 0, 0, 10, 10 );
//			text.SetFlags( DT_SINGLELINE | DT_CENTER | DT_VCENTER );
			text.SetFlags( DT_SINGLELINE | DT_VCENTER );
			text.CalcRect( hDC, pmi->name, &rect );
			
			RECT rrect;
			if ( *pmi->rtext != 0 )
			{	SetRect( &rect, 0, 0, 10, 10 );
				text.CalcRect( hDC, pmi->rtext, &rrect );
			} // end if
			else ZeroMemory( &rrect, sizeof( rrect ) );

			long cw = ( ( rect.right - rect.left ) + MARGIN );
			
			// Add toolbar size
			if ( pmi->toolbar != NULL ) cw += pmi->toolbar->GetWidth();

			// Track width
			if ( cw > w ) w = cw;

			if ( ( rect.bottom - rect.top ) > 20 )
			{	m_th = rect.bottom - rect.top;
				h += m_th;
			} // end if
			else h += 20;

		} // end if
		else h += 6;

	} // end while

	// Correct width
	w += ( m_th * 3 );
	if ( w < 80 ) w = 80;

	m_tw = w;

	::ReleaseDC( NULL, hDC );

	pRect->left = x;
	pRect->right = x + w;
	pRect->top = y;
	pRect->bottom = y + h;

	// Correct if drifting offscreen
	if ( m_bCorrectOverhang	)
	{
		long ox = 0, oy = 0;
		if ( pRect->left < 10 ) ox = 10 - pRect->left;
		if ( pRect->top < 10 ) oy = 10 - pRect->top;

		// Offset rect if needed
		if ( ox || oy ) 
			OffsetRect( pRect, ox, oy );
	} // end if
	
	return TRUE;
}