Beispiel #1
0
		Gwen::Point SFML::MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString& text )
		{
			const sf::Font* pSFFont = (sf::Font*)(pFont->data);

			// If the font doesn't exist, or the font size should be changed
			if ( !pSFFont || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
			{
				FreeFont( pFont );
				LoadFont( pFont );
			}

			if  ( !pSFFont )
			{
				pSFFont = &(sf::Font::GetDefaultFont());
			}

			#if SFML_VERSION_MAJOR == 2
				sf::Text sfStr( text );
				sfStr.SetFont( *pSFFont );
				sfStr.SetCharacterSize( pFont->realsize );
				sf::FloatRect sz = sfStr.GetRect();
				return Gwen::Point( sz.Width, sz.Height );

			#else
				sf::String sfStr( text );
				sfStr.SetFont( *pSFFont );
				sfStr.SetSize( pFont->realsize );
				sf::FloatRect sz = sfStr.GetRect();
				return Gwen::Point( sz.GetWidth(), sz.GetHeight() );
			#endif
			
		}
Beispiel #2
0
		Gwen::Point DirectX9::MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString & text )
		{
			// If the font doesn't exist, or the font size should be changed
			if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
			{
				FreeFont( pFont );
				LoadFont( pFont );
			}

			FontData* pFontData = ( FontData* ) pFont->data;
			Gwen::Point size;

			if ( text.empty() )
			{
				RECT rct = {0, 0, 0, 0};
				pFontData->pFont->DrawTextW( NULL, L"W", -1, &rct, DT_CALCRECT, 0 );
				return Gwen::Point( 0, rct.bottom );
			}

			RECT rct = {0, 0, 0, 0};
			pFontData->pFont->DrawTextW( NULL, text.c_str(), -1, &rct, DT_CALCRECT | DT_LEFT | DT_TOP | DT_SINGLELINE, 0 );

			for ( int i = text.length() - 1; i >= 0 && text[i] == L' '; i-- )
			{
				rct.right += pFontData->iSpaceWidth;
			}

			return Gwen::Point( rct.right / Scale(), rct.bottom / Scale() );
		}
Beispiel #3
0
		void DirectX9::Release()
		{
			Font::List::iterator it = m_FontList.begin();

			while ( it != m_FontList.end() )
			{
				FreeFont( *it );
				it = m_FontList.begin();
			}
		}
Beispiel #4
0
		void DirectX9::RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString & text )
		{
			Flush();

			// If the font doesn't exist, or the font size should be changed
			if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
			{
				FreeFont( pFont );
				LoadFont( pFont );
			}

			FontData* pFontData = ( FontData* ) pFont->data;
			Translate( pos.x, pos.y );
			RECT ClipRect = { pos.x, pos.y, 0, 0 };
			pFontData->pFont->DrawTextW( NULL, text.c_str(), -1, &ClipRect, DT_LEFT | DT_TOP | DT_NOCLIP | DT_SINGLELINE, m_Color );
		}
Beispiel #5
0
		void GDIPlus::RenderText( gwen::Font* pFont, gwen::Point pos, const gwen::UnicodeString & text )
		{
			Translate( pos.x, pos.y );

			// If the font doesn't exist, or the font size should be changed
			if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
			{
				FreeFont( pFont );
				LoadFont( pFont );
			}

			Gdiplus::StringFormat strFormat( Gdiplus::StringFormat::GenericDefault() );
			Gdiplus::SolidBrush solidBrush( m_Colour );
			Gdiplus::RectF r( pos.x, pos.y, 1000, 1000 );
			Gdiplus::Font* pGDIFont = ( Gdiplus::Font* ) pFont->data;
			graphics->DrawString( text.c_str(), text.length() + 1, pGDIFont, r, &strFormat, &solidBrush );
		}
Beispiel #6
0
		gwen::Point GDIPlus::MeasureText( gwen::Font* pFont, const gwen::UnicodeString & text )
		{
			gwen::Point p( 1, 1 );

			if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
			{
				FreeFont( pFont );
				LoadFont( pFont );
			}

			Gdiplus::StringFormat strFormat( Gdiplus::StringFormat::GenericDefault() );
			strFormat.SetFormatFlags( Gdiplus::StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() );
			Gdiplus::SizeF size;
			Gdiplus::Graphics g( m_HWND );
			Gdiplus::Font* pGDIFont = ( Gdiplus::Font* ) pFont->data;
			g.MeasureString( text.c_str(), -1, pGDIFont, Gdiplus::SizeF( 10000, 10000 ), &strFormat, &size );
			return gwen::Point( size.Width + 1, size.Height + 1 );
		}
Beispiel #7
0
		Gwen::Point ClanLib::MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString & text )
		{
			// If the font doesn't exist, or the font size should be changed
			if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
			{
				FreeFont( pFont );
				LoadFont( pFont );
			}

			const clan::Font* pCLFont = ( clan::Font* )( pFont->data );

			if ( !pCLFont )
			{
				pCLFont = &defaultFont;
			}

			auto size = pCLFont->get_text_size(m_Target, Gwen::Utility::UnicodeToString(text));
			
			return Gwen::Point(size.width, size.height);			
		}
Beispiel #8
0
        Gwen::Point SDL2Renderer::MeasureText(Gwen::Font* pFont, const Gwen::String& text)
        {
            TTF_Font *tfont = static_cast<TTF_Font*>(pFont->data);

            // If the font doesn't exist, or the font size should be changed.
            if (!tfont || pFont->realsize != pFont->size*Scale())
            {
                FreeFont(pFont);
                LoadFont(pFont);
                tfont = static_cast<TTF_Font*>(pFont->data);
            }

            if (!tfont)
                return Gwen::Point(0, 0);

            int w,h;
            TTF_SizeUTF8(tfont, text.c_str(), &w,&h);
            
            return Point(w,h);
        }
Beispiel #9
0
		void ClanLib::RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString & text )
		{
			Translate( pos.x, pos.y );

			// If the font doesn't exist, or the font size should be changed
			if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
			{
				FreeFont( pFont );
				LoadFont( pFont );
			}

			const clan::Font* pCLFont = ( clan::Font* )( pFont->data );

			if ( !pCLFont )
			{
				pCLFont = &defaultFont;
				//pCLFont = NULL;
			}

			pCLFont->draw_text(m_Target, clan::Pointf(pos.x, pos.y), Gwen::Utility::UnicodeToString(text), clan::Colorf(m_Color));
		}
Beispiel #10
0
Gwen::Point Gwen::Renderer::SFML2::MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString& text )
{
	// If the font doesn't exist, or the font size should be changed
	if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
	{
		FreeFont( pFont );
		LoadFont( pFont );
	}

	const sf::Font* pSFFont = reinterpret_cast<sf::Font*>( pFont->data );

	if ( pSFFont ) {
		sf::Text sfStr;
		sfStr.setString( text );
		sfStr.setFont( *pSFFont );
		sfStr.setCharacterSize( pFont->realsize );
		return Gwen::Point( sfStr.getLocalBounds().width, pSFFont->getLineSpacing( pFont->realsize ) );
	}

	return Gwen::Point();
}
Beispiel #11
0
		void SFML::RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString& text )
		{
			Translate( pos.x, pos.y );

			const sf::Font* pSFFont = (sf::Font*)(pFont->data);

			// If the font doesn't exist, or the font size should be changed
			if ( !pSFFont || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
			{
				FreeFont( pFont );
				LoadFont( pFont );
			}

			if  ( !pSFFont )
			{
				pSFFont = &(sf::Font::GetDefaultFont());
			}

			#if SFML_VERSION_MAJOR == 2
				m_Target.SaveGLStates();
					sf::Text sfStr( text );
					sfStr.SetFont( *pSFFont );
					sfStr.Move( pos.x, pos.y );
					sfStr.SetCharacterSize( pFont->realsize );
					sfStr.SetColor( m_Color );
					m_Target.Draw( sfStr );
				m_Target.RestoreGLStates();
			#else
				sf::String sfStr( text );
				sfStr.SetFont( *pSFFont );
				sfStr.Move( pos.x, pos.y );
				sfStr.SetSize( pFont->realsize );
				sfStr.SetColor( m_Color );
				m_Target.Draw( sfStr );
			#endif

			
		}
Beispiel #12
0
void Gwen::Renderer::SFML2::RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString& text )
{
	Flush();

	Translate( pos.x, pos.y );

	// If the font doesn't exist, or the font size should be changed
	if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
	{
		FreeFont( pFont );
		LoadFont( pFont );
	}

	const sf::Font* pSFFont = reinterpret_cast<sf::Font*>( pFont->data );

	sf::Text sfStr;
	sfStr.setString( text );
	sfStr.setFont( *pSFFont );
	sfStr.move( pos.x, pos.y );
	sfStr.setCharacterSize( pFont->realsize );
	sfStr.setColor( m_Color );

	m_Target.draw( sfStr );
}
int main(int argc, char *const argv[])
{
	int i;
	struct stat buf;
	_font fx;
    char *name, *cfonts, *ptr;;
	// Dump font ascii preview
	int font_preview = 0;
	int font_adjust_full = 0;
	int font_adjust_small = 0;
	// Glyph code of first font to process - we ignore fonts less then this
	int lower_bound = 32;
	// Glyph code of last font to process - we ignore fonts greater then this 
	int upper_bound = 127;

	// We always emit fonts specs and info parts
	// These flags just determin if we emit them in the converted font file
	int fontinfo_f = 0;
	int fontspecs_f = 0;

	char str[MAXLINE];

	int bdfind = 0;
	int find = 0;
	FILE *FI;

	FILE *FO = NULL;
	cfonts = NULL;

	for(i=1;i<argc;++i)
	{
		ptr = argv[i];
		if(*ptr == '-')
		{
			ptr++;
			if(*ptr == 'o')
			{
				++ptr;
				if(*ptr)
				{
					cfonts = ptr;
				}
				else
				{
					cfonts = argv[++i];

				}
				continue;
			}
			if(*ptr == 'l')
			{
				++ptr;
				if(*ptr)
				{
					lower_bound = atoi(ptr);
				}
				else
				{
					lower_bound = atoi(argv[++i]);
				}
				continue;
			}
			if(*ptr == 'u')
			{
				++ptr;
				if(*ptr)
				{
					upper_bound = atoi(ptr);
				}
				else
				{
					upper_bound = atoi(argv[++i]);
				}
				continue;
			}
			if(*ptr == 'p')
			{
				++ptr;
				if(*ptr)
				{
					font_preview = atoi(ptr);
				}
				else
				{
					font_preview = atoi(argv[++i]);
				}
				continue;
			}
			if(*ptr == 'f')
			{
				++ptr;
				font_adjust_full = 1;
				continue;
			}
			if(*ptr == 's')
			{
				++ptr;
				font_adjust_small = 1;
				continue;
			}
		}
		else
		{
			if(find < MAXFONTS)
			{
				if(stat(argv[i], (struct stat *) &buf) != 0)
				{
					fprintf(stderr,"File:[%s] missing, skipping\n", argv[i]);
					continue;
				}
				fnames[find++] = stralloc(argv[i]);
			}
		}
	}

	if(font_adjust_full && font_adjust_small)
	{
		fprintf(stderr,"Can not have -f and -s set at the same time\n");	
		exit(1);
	}

	if(!find)
	{
		usage(basename(argv[0]));
		fprintf(stderr,"No font files specified\n");
		exit(1);
	}

	if(cfonts == NULL)
	{
		FO = stdout;
		cfonts = "stdout";
	}
	else
	{
        if(stat(cfonts, (struct stat *) &buf) == 0)
		{
			fprintf(stderr,"Font file: %s - exists - not overwritting\n", cfonts);
			exit(1);

		}
		FO = fopen(cfonts,"w");
		if(!FO)
		{
			fprintf(stderr,"Can't open: %s\n", cfonts);
			exit(1);
		}
	}

	
	bdfind = 0;
	for(i=0;i<find;++i)
	{
		int ret;
		name = fnames[i];

		if(!ReadBdf(name, &fx, lower_bound, upper_bound))
		{
			FreeFont(&fx);
			fprintf(stderr,"Can't open:[%s]\n", name);
			continue;
		}
		ret = FindFontName(fx.info->STRUCT_NAME);
		if(ret != -1)
		{
			fprintf(stderr,"Duplicate font:[%s] in file:[%s], skipping\n", fx.info->STRUCT_NAME, name);
			fprintf(stderr,"Exists in font:[%s] in file:[%s]\n\n", 
				BDFnames[ret].structname,
				BDFnames[ret].filename
			);
			FreeFont(&fx);
			continue;
		}

	
		if(font_adjust_full)
		{
			//fprintf(stderr,"Bytes:%d\n", fx.Bytes);
			FontAdjustFull(&fx);
			fontspecs_f = 0;
			//fprintf(stderr,"New Bytes:%d\n", fx.Bytes);
		}

		if(font_adjust_small)
		{
			//fprintf(stderr,"Bytes:%d\n", fx.Bytes);
			FontAdjustSmall(&fx);
			fontspecs_f = 1;
			//fprintf(stderr,"New Bytes:%d\n", fx.Bytes);
		}

		BDFnames[bdfind].filename = name;
		BDFnames[bdfind].structname = stralloc(fx.info->STRUCT_NAME);

		ComputeGapSize(&fx);
		
		FontHeaderInfo(FO, &fx, argv[0], cfonts);

		if(fontinfo_f = 0)
		{
			fprintf(FO,"#ifndef FONTINFO\n");
			fprintf(FO,"   #define FONTINFO\n");
			fprintf(FO,"#endif\n");
		}
		if(fontspecs_f)
		{
			fprintf(FO,"#ifndef FONTSPECS\n");
			fprintf(FO,"   #define FONTSPECS\n");
			fprintf(FO,"#endif\n");
		}

		Convert_Font2c(FO, &fx);
		WriteFontBitsPreview ( FO, &fx, font_preview);
		FreeFont(&fx);
		++bdfind;
	}

	fprintf(FO, "\n\n\n");
	fprintf(FO, "/* All cfonts */\n");
	fprintf(FO, "_font *allfonts[%d] = {\n", bdfind+1);
	for(i=0;i<bdfind;++i)
	{
		fprintf(FO, "\t&%s,\n", BDFnames[i].structname);
	}
	fprintf(FO, "\tNULL\n");
	fprintf(FO, "};\n");

	if(FO != stdout)
		fclose(FO);
	return(0);
}
Beispiel #14
0
/*=========================================================================
// Name: main()
// Desc: Entrypoint
//=======================================================================*/
int main(int argc, char *argv[])
{
    printf("-----------------------------------------------------\n");
    printf(" BlueCube (improved version v0.9 hosted on github)   \n");
    printf("    just another tetris clone,                       \n");
    printf("    written by Sebastian Falbesoner <theStack>       \n");
    printf("-----------------------------------------------------\n");
    
    /* First, check whether sound should be activated */
    bSoundActivated = 1;
    if ((argc == 2) && (strcmp(argv[1], "--nosound") == 0)) {
        printf("No sound is used!\n");
        bSoundActivated = 0;
    }

    /* Init randomizer */
    printf("Initializing randomizer... ");
    srand(time(NULL));
    printf("done.\n");
    
    /* Let's init the graphics and sound system */
    printf("Starting up SDL... ");
    InitSDLex();
    printf("done.\n");
    if (bSoundActivated) {
        printf("Initializing sound subsystem... ");
        InitSound();
        printf("done.\n");
    }
    
    /* Load font */
    printf("Loading font files... ");
    font = LoadFontfile("font/font.dat", "font/widths.dat");
    printf("done.\n");

    /* Load soundfiles */
    if (bSoundActivated) {
        printf("Loading sound files... ");
        LoadSound("sound/killline.snd", &sndLine);
        LoadSound("sound/nextlev.snd",  &sndNextlevel);
        printf("done.\n");
    }
    printf("=== Let the fun begin! ===\n");

    /* Init star background */
    InitStars();

    if (bSoundActivated) {
        ClearPlayingSounds();
        SDL_PauseAudio(0);
    }

    /* Start menu first, please... */
    gamestate = STATE_MENU;

    /* Call main loop */
    Mainloop();

    /* Free sounds again */
    if (bSoundActivated) {
        printf("Releasing memory for sound samples... ");
        SDL_FreeWAV(sndLine.samples); 
        SDL_FreeWAV(sndNextlevel.samples);
        printf("done.\n");
    }

    /* Free font again */
    printf("Releasing memory for fonts... ");
    FreeFont(font);
    printf("done.\n");

    return 0;
}