const bool RegisterFont(const String& filename, int pointSize, const String& nickname)
{
	std::map<String,FTFont*>::iterator it = _fontCache.find(nickname);
	if(it != _fontCache.end())
	{
		UnRegisterFont(nickname);
	}
	
	if (theWorld.IsHighResScreen())
	{
		pointSize = pointSize * 2;
	}

	FTFont *font = new FTGLTextureFont(filename.c_str());
	if(font->Error())
	{
		sysLog.Log("Failed to open font " + filename);
		return false;
	}
	if(!font->FaceSize(pointSize))
	{
		sysLog.Log("Failed to set size.");
		return false;
	}
	font->CharMap(FT_ENCODING_NONE);
	font->UseDisplayList(true);

	_fontCache[nickname] = font;
	return true;
}
MOboolean
moFont::Init( moFontType p_Type, moText p_fontname, MOint p_size, MOuint glid ) {

  glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

	switch( (int)p_Type ) {
		case MO_FONT_OUTLINE://3d
			m_pFace = (FTFont*)new FTGLOutlineFont( p_fontname );
			break;
		case MO_FONT_TRANSLUCENT://2d
            m_pFace = (FTFont*)new FTGLBitmapFont( p_fontname );
			break;
		case MO_FONT_TRANSLUCENTTEXTURE://3d
            m_pFace = (FTFont*)new FTGLTextureFont( p_fontname );
			break;
		case MO_FONT_GRAYSCALE://2d
            m_pFace = (FTFont*)new FTGLPixmapFont( p_fontname );
			break;
		case MO_FONT_MONOCHROME://2d
            m_pFace = (FTFont*)new FTGLPixmapFont( p_fontname );
			break;
		case MO_FONT_SOLID://3d extruded (depth)
            m_pFace = (FTFont*)new FTGLExtrdFont( p_fontname );
			break;
		case MO_FONT_FILLED://3d
            m_pFace = (FTFont*)new FTGLPolygonFont( p_fontname );
			break;
    case MO_FONT_GLBUILD:
            m_FontGLId = glid;
            BuildFont();
			break;
    case MO_FONT_UNDEFINED:
            MODebug2->Error(moText(" FontManager:: UNDEFINED font type"));
            m_pFace = NULL;
            break;

	}


  FTFont* FF = (FTFont*) m_pFace;
  FT_Error FontError;
  if (FF)
    FontError = FF->Error();

	if ( ( p_Type!=MO_FONT_GLBUILD && ( FF == NULL || FontError!=0 ) ) ||
         ( p_Type==MO_FONT_UNDEFINED )  || (p_Type==MO_FONT_GLBUILD && (int)m_FontGLId==-1)) {
        MODebug2->Error(moText("FontManager: Could not construct face from ")+(moText)p_fontname);
        return false;
	} else {
		m_Name = p_fontname;
    if (FF) {
      SetSize(p_size);
      FF->Depth(20);
      //FF->CharMap(ft_encoding_unicode);
    }
		return true;
	}

	return false;
}
UIListCell *MainScreen::CellAtIndex(UIList *list, int32 index)
{
    UIListCell *c = list->GetReusableCell("UI info cell"); //try to get cell from the reusable cells store
    if(!c)
    {
        c = new UIListCell(Rect(0.0f, 0.0f, 2*buttonW, cellH), "UI info cell");
    }
    
    c->RemoveAllControls();
    
    WideString keyStr = (selectedControl ? selectedControl->GetSpecificInfoKeyText(index) : L"");
    WideString valueStr = (selectedControl ? selectedControl->GetSpecificInfoValueText(index) : L"");
    
    FTFont* font = FTFont::Create("~res:/Fonts/MyriadPro-Regular.otf");
    font->SetSize(20.0f);
    font->SetColor(0.8f, 0.8f, 0.8f, 1.0f);
    
    c->SetStateFont(UIControl::STATE_NORMAL, font);
    
    UIStaticText* cellKeyText = new UIStaticText(Rect(0.0f, 0.0f, buttonW, cellH));
    cellKeyText->SetFont(font);
    cellKeyText->SetText(keyStr);
    c->AddControl(cellKeyText);
    
    UIStaticText* cellValueText = new UIStaticText(Rect(buttonW, 0.0f, buttonW, cellH));
    cellValueText->SetFont(font);
    cellValueText->SetText(valueStr);
    c->AddControl(cellValueText);
    
    SafeRelease(font);
    
    return c;//returns cell
}
Exemple #4
0
bool OglRenderer::getStringBBox(char *font, double size, char *string, rectObj *rect, double** advances)
{
  FTFont* face = getFTFont(font, size);
  if (!face) {
    msSetError(MS_OGLERR, "Failed to load font (%s).", "OglRenderer::getStringBBox()", font);
    return false;
  }

  float llx =0.0f, lly=0.0f, llz=0.0f, urx=0.0f, ury=0.0f, urz=0.0f;
  glPushAttrib( GL_ALL_ATTRIB_BITS );
  FTBBox boundingBox = face->BBox(string);
  glPopAttrib();

  rect->minx = boundingBox.Lower().X();
  rect->maxx = boundingBox.Upper().X();
  rect->miny = -boundingBox.Upper().Y();
  rect->maxy = -boundingBox.Lower().Y();

  if (advances) {
    int length = strlen(string);
    *advances = new double[length];
    for (int i = 0; i < length; ++i) {
      (*advances)[i] = face->Advance(&string[i], 1);
    }
  }

  return true;
}
void
moFont::SetSize( MOfloat size ) {

    m_FontSize = size;

    FTFont* FF = (FTFont*) m_pFace;
    if (FF) FF->FaceSize(m_FontSize);

}
void TextPropertyGridWidget::UpdatePushButtonWidgetWithFont(QPushButton *pushButtonWidget, Font* font)
{
    if (pushButtonWidget != this->ui->fontSelectButton)
    {
        return; //Not font select button
    }
    
    if (font)
    {
        //Set button text
        Font::eFontType fontType = font->GetFontType();
        QString buttonText;
        
        switch (fontType)
        {
            case Font::TYPE_FT:
            {
                FTFont *ftFont = static_cast<FTFont*>(font);
                //Set pushbutton widget text
				buttonText = QString::fromStdString(ftFont->GetFontPath().GetFrameworkPath());
                break;
            }
            case Font::TYPE_GRAPHICAL:
            {
                GraphicsFont *gFont = static_cast<GraphicsFont*>(font);
                //Put into result string font definition and font sprite path
                Sprite *fontSprite = gFont->GetFontSprite();
                if (!fontSprite) //If no sprite available - quit
                {
                    pushButtonWidget->setText("Graphical font is not available");
                    return;
                }
                //Get font definition and sprite relative path
                QString fontDefinitionName = QString::fromStdString(gFont->GetFontDefinitionName().GetFrameworkPath());
                QString fontSpriteName =QString::fromStdString(fontSprite->GetRelativePathname().GetFrameworkPath());
                //Set push button widget text - for grapics font it contains font definition and sprite names
                buttonText = QString("%1\n%2").arg(fontDefinitionName, fontSpriteName);
                break;
            }
            case Font::TYPE_DISTANCE:
            {
                DFFont *dfFont = static_cast<DFFont*>(font);
                //Set pushbutton widget text
				buttonText = QString::fromStdString(dfFont->GetFontPath().GetFrameworkPath());
                break;
            }
            default:
            {
                //Do nothing if we can't determine font type
                return;
            }
        }
        
        pushButtonWidget->setText(buttonText);
    }
}
Exemple #7
0
	void Font::GetStringSize(const String &text, Vector2D *result) {
		if (mID < 0) {
			*result = kFastVector2DZero;
			return;
		}
		FTFont *tf =
			(FTFont*)GetCollection()->GetResource(mID)->GetFTFont();
		result->mX = tf->Advance(text.GetWString().mData);
		result->mY = tf->LineHeight();
	}
void UITextFieldPropertyGridWidget::UpdatePushButtonWidgetWithPropertyValue(QPushButton *pushButtonWidget, const QMetaProperty &curProperty)
{
    
    if (pushButtonWidget != this->ui->fontSelectButton)
    {
        return; //Not font select button
    }
    
    bool isPropertyValueDiffers = false;
    Font *fontPropertyValue = PropertiesHelper::GetPropertyValue<Font *>(this->activeMetadata,
                                                                         curProperty.name(), isPropertyValueDiffers);
    if (fontPropertyValue)
    {
        //Set button text
        WidgetSignalsBlocker blocker(pushButtonWidget);
        Font::eFontType fontType = fontPropertyValue->GetFontType();
        QString buttonText;
        
        switch (fontType)
        {
            case Font::TYPE_FT:
            {
                FTFont *ftFont = dynamic_cast<FTFont*>(fontPropertyValue);
                //Set pushbutton widget text
				buttonText = QString::fromStdString(ftFont->GetFontPath().GetFrameworkPath());
                break;
            }
            case Font::TYPE_GRAPHICAL:
            {
                GraphicsFont *gFont = dynamic_cast<GraphicsFont*>(fontPropertyValue);
                //Put into result string font definition and font sprite path
                Sprite *fontSprite = gFont->GetFontSprite();
                if (!fontSprite) //If no sprite available - quit
                {
                    pushButtonWidget->setText("Graphical font is not available");
                    return;
                }
                //Get font definition and sprite relative path
                QString fontDefinitionName = QString::fromStdString(gFont->GetFontDefinitionName().GetFrameworkPath());
                QString fontSpriteName =QString::fromStdString(fontSprite->GetRelativePathname().GetFrameworkPath());
                //Set push button widget text - for grapics font it contains font definition and sprite names
                buttonText = QString("%1\n%2").arg(fontDefinitionName, fontSpriteName);
                break;
            }
            default:
            {
                //Do nothing if we can't determine font type
                return;
            }
        }
        
        pushButtonWidget->setText(buttonText);
    }
}
Exemple #9
0
FTFont* FXFontManager::create(std::string font_file, int size) {

    FTFont* ft = new  FTTextureFont(font_file.c_str());

    if(ft->Error() || !ft->FaceSize(size)) {
        delete ft;
        throw FXFontException(font_file);
    }

    return ft;
}
Exemple #10
0
  void setup_font()
  {
    if
    (
      (cur_font != font_in->get()) ||
      (cur_render_type !=render_type->get()) ||
      (cur_glyph_size != glyph_size->get())
    )
    {
      vsx::file *fp;
      if ((fp = engine_state->filesystem->f_open(font_in->get().c_str())) == NULL)
      {
        printf("font not found: %s\n",cur_font.c_str());
        return;
      }
      cur_font = font_in->get();
      cur_render_type = render_type->get();
      cur_glyph_size = glyph_size->get();

      if (ftfont) {
        delete ftfont;
        ftfont = 0;
      }
      if (ftfont2) {
        delete ftfont2;
        ftfont2 = 0;
      }
      unsigned long size = engine_state->filesystem->f_get_size(fp);
      char* fdata = (char*)malloc(size);
      unsigned long bread = engine_state->filesystem->f_read((void*)fdata, size, fp);
      if (bread == size)
      {
        switch (cur_render_type)
        {
          case 0:
            ftfont = new FTGLTextureFont((unsigned char*)fdata, size);
          break;
          case 1:
            ftfont = new FTGLPolygonFont((unsigned char*)fdata, size);
            ftfont2 = new FTGLOutlineFont((unsigned char*)fdata, size);
          break;
        }
        ftfont->FaceSize((unsigned int)round(cur_glyph_size));
        ftfont->CharMap(ft_encoding_unicode);
        if (ftfont2) {
          ftfont2->FaceSize((unsigned int)round(cur_glyph_size));
          ftfont2->CharMap(ft_encoding_unicode);
        }
        loading_done = true;
      }
      engine_state->filesystem->f_close(fp);
    }
  }
Exemple #11
0
Action::ResultE FTGLText::drawPrimitives(DrawActionBase *action )
{
    FTGLFontPtr font = getFont();
    
    if(font == NullFC)
    {
        FWARNING(("FTGLText::drawPrimitives: no font set!\n"));
        return Action::Continue;
    }
   
    action->getWindow()->validateGLObject(font->getGLId());
    
    FTFont *ftf = font->_fonts[action->getWindow()];
    
    if(ftf == NULL)
    {
        FWARNING(("FTGLText::drawPrimitives: invalid font set!\n"));
        return Action::Continue;        
    }

    switch(font->getDrawType())
    {
    case FTGLFont::Texture:   
    case FTGLFont::Polygon:   
    case FTGLFont::Extrude:   
    case FTGLFont::Outline: glPushMatrix();
                            glTranslatef(getPosition()[0], 
                                         getPosition()[1], 
                                         getPosition()[2]);
                            glNormal3f(0,0,1);
                            break;
    case FTGLFont::Pixmap:   
    case FTGLFont::Bitmap:  glRasterPos3f(getPosition()[0], 
                                          getPosition()[1], 
                                          getPosition()[2]);
                            break;
    }
   
    ftf->Render(getText().c_str());
    
    switch(font->getDrawType())
    {
    case FTGLFont::Texture:   
    case FTGLFont::Polygon:   
    case FTGLFont::Extrude:   
    case FTGLFont::Outline: glPopMatrix();
                            break;
    case FTGLFont::Pixmap:   
    case FTGLFont::Bitmap:  break;
    }

    return Action::Continue;
}
void Writter::AddFont(string iname, string fontfile, int fontsize){

	FTFont* nfont = new FTTextureFont(fontfile.c_str());

	if(nfont->Error())
    {
        fprintf(stderr, "Failed to open font %s", fontfile);
        exit(1);
    }
	nfont->FaceSize(fontsize);
	
	m_font_list[iname] = nfont;
}
Exemple #13
0
 double kerning ( char a, char b ) { 
     //silly hack.
     //kerning = advance ( ab ) - ( advance ( a ) + advance ( b ) )
     static char st[7];
     double r; 
     // st = 'ab0a0b0'
     st[2] = st[4] = st[6] = 0;
     st[0] = st[3] = a;
     st[1] = st[5] = b;
     r  = m_font->Advance ( st );
     r -= m_font->Advance ( st+3 );
     r -= m_font->Advance ( st+5 );
     return r;
 }
UIStaticText * PropertyPanel::AddHeader(const WideString & string, float32 fontSize)
{
    FTFont * font = FTFont::Create("~res:/Fonts/MyriadPro-Regular.otf");
    font->SetSize(fontSize);
    font->SetColor(Color(0.2f, 0.2f, 0.2f, 1.0f));

    UIStaticText * text = new UIStaticText(Rect(10, 0, GetRect().dx - 20, 20));
    text->SetAlign(ALIGN_LEFT | ALIGN_VCENTER);
    text->SetFont(font);
    text->SetText(string);
    SafeRelease(font);
    AddPropertyControl(text);
    text->Release();
    return text;
}
Exemple #15
0
void
moFont::Draw( MOfloat x, MOfloat y, moText& text, moFontSize p_fontsize, MOint set, MOfloat sx, MOfloat sy, MOfloat rt ) {

    FTFont* FF = (FTFont*) m_pFace;
    if (FF) {
        SetSize(p_fontsize);
        FF->Render( text, text.Length(), FTPoint(x,y) );
    }

    else {
      if (m_FontGLId>=0) {
          this->glPrint( (int)x, (int)y, text, set, sx, sy, rt );
      }
    }
}
void Writter::Draw(string iname, string str, float x, float y, float mangle){
	FTFont* nfont = m_font_list[iname];

	if (nfont != NULL){
		glPushMatrix();

		glTranslatef(x, -y - nfont->LineHeight(), 0);
		glRotatef(mangle, 0.0, 0.0, 1);
		
		nfont->Render(str.c_str());

		glPopMatrix();

	}else{
		fprintf(stderr, "Failed to draw using name '%s': %s\n", iname.c_str(), str.c_str());
	}
}
Exemple #17
0
QString EditorFontManager::GetDefaultFontName() const
{		
	Font::eFontType fontType = defaultFont->GetFontType();
    switch (fontType)
    {
    	case Font::TYPE_FT:
        {
        	FTFont *ftFont = dynamic_cast<FTFont*>(defaultFont);
			return QString::fromStdString(ftFont->GetFontPath().GetAbsolutePathname());
        }
		case Font::TYPE_GRAPHICAL:
        {
        	GraphicsFont *gFont = dynamic_cast<GraphicsFont*>(defaultFont);
			return QString::fromStdString(gFont->GetFontDefinitionName().GetAbsolutePathname());
		}
	}
	return QString::fromStdString(DEFAULT_FONT_PATH);
}
EditorFontManager::DefaultFontPath EditorFontManager::GetDefaultFontPath()
{
	FilePath defFontPath;
	FilePath defFontSpritePath;

	if (defaultFont)
	{
		Font::eFontType fontType = defaultFont->GetFontType();		
        switch (fontType)
        {
            case Font::TYPE_FT:
            {
                FTFont *ftFont = dynamic_cast<FTFont*>(defaultFont);
				FilePath ftFontPath = ftFont->GetFontPath();
				// Don't save standart default font
				if (ftFontPath.GetAbsolutePathname().find(DEFAULT_FONT_NAME) == String::npos)
				{
					// Set font path
					defFontPath = ftFontPath;
				}
                break;
            }
            case Font::TYPE_GRAPHICAL:
            {
                GraphicsFont *gFont = dynamic_cast<GraphicsFont*>(defaultFont);
                // Try to get font sprite
                Sprite *fontSprite = gFont->GetFontSprite();
				// Save font only if sprite is available
                if (fontSprite)
                {
					// Set font definition and sprite relative path
					defFontPath = gFont->GetFontDefinitionName();
					defFontSpritePath = fontSprite->GetRelativePathname();
                }
				break;
            }
        }	
	}
	
	return DefaultFontPath(defFontPath, defFontSpritePath);
}
Exemple #19
0
    GLCharacter * operator[ ]( char const xCharacter )
    {
        GLCharacter * ret = NULL;

        if ( mCharacters.find( xCharacter ) == mCharacters.end( ) )
        {
//#ifdef ANDROID
#if 1
            mFont.loadGlyph( xCharacter, 0.0f );

            PNGImage output( { mFont.getGlyphWidth( ), mFont.getGlyphHeight( ) } );

            mFont.printSpans( output, mOutlineColor, mFillColor );

            mCharacters[ xCharacter ] = ret = new GLCharacter( xCharacter
                    , output.toGLTextureBuffer( )
                    , mFont.getGlyphWidth( )
                    , mFont.getGlyphHeight( ) );
#else
            while ( !fileExists( filename.str( ).c_str( ) ) ) {
                _makePNG( xCharacter );
            }
            mCharacters[ xCharacter ] = ret = new GLCharacter( xCharacter, filename.str( ).c_str( ) );
#endif

        }
        else
        {
            ret = mCharacters[ xCharacter ];
        }

        return ret;
    }
Exemple #20
0
void OglRenderer::renderGlyphs(double x, double y, colorObj *color,
                               colorObj *outlinecolor, double size, const char* font, char *thechars, double angle,
                               colorObj *shadowcolor, double shdx, double shdy)
{
  makeCurrent();
  FTFont* face = getFTFont(font, size);
  if (!face) {
    msSetError(MS_OGLERR, "Failed to load font (%s).", "OglRenderer::renderGlyphs()", font);
    return;
  }

  glPushAttrib(GL_ALL_ATTRIB_BITS);
  glPushMatrix();

  glTranslated(floor(x), floor(y), 0);
  glScaled(1.0, -1.0, 1);
  glRotated(angle * (180 / OGL_PI), 0, 0, 1);

  if (outlinecolor && MS_VALID_COLOR(*outlinecolor)) {
    setColor(outlinecolor);
    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        if (i || j) {
          glPushMatrix();
          glTranslated(i, j, 0);
          face->Render(thechars);
          glPopMatrix();
        }
      }
    }
  }
  if (color != NULL && MS_VALID_COLOR(*color)) {
    setColor(color);
    face->Render(thechars);
  }

  glPopMatrix();
  glPopAttrib();
}
UIFileTreeCell::UIFileTreeCell(const Rect &rect, const String &cellIdentifier)
:	UIListCell(rect, cellIdentifier)
{
	FTFont * fnt = FTFont::Create("~res:/Fonts/MyriadPro-Regular.otf");
	fnt->SetColor(0, 0, 0, 1);
	fnt->SetSize(14);
	SetStateFont(STATE_NORMAL, fnt);
	SafeRelease(fnt);
	
	
	//Rect iconSize = Rect(0, 0, rect.dy, rect.dy);
	//icon = new UIControl(rect);
	//text = new UIStaticText(rect);
	
	
	// icon = UIControl(, <#bool rectInAbsoluteCoordinates#>)
	// 
	//GetStateBackground(STATE_NORMAL)->SetDrawType(UIControlBackground::DRAW_FILL);
	//GetStateBackground(STATE_NORMAL)->SetColor(Color(0.0, 0.0, 0.0, 1.0f));
	//SetStateText(UIControl::STATE_NORMAL, L"Mega test!");

}
Exemple #22
0
void FTGLText::adjustVolume(Volume & volume)
{
    FTGLFontPtr font = getFont();
    
    if(font == NullFC)
    {
        FWARNING(("FTGLText::adjustVolume: no font set!\n"));
        return;
    }

    FTFont *f = font->_fonts[NULL];
    if(f == NULL)
    {
        font->handleGL(NULL, Window::reinitialize);
        f = font->_fonts[NULL];
    }
    
    volume.setValid();
    volume.setEmpty();

    volume.extendBy(getPosition());
    
    float x1, y1, z1, x2, y2, z2, px, py, pz;
    f->BBox(getText().c_str(), x1, y1, z1, x2, y2, z2);

    px = getPosition()[0];
    py = getPosition()[1];
    pz = getPosition()[2];
    
    volume.extendBy(Pnt3f(px + x1, py + y1, pz + z1));
    volume.extendBy(Pnt3f(px + x2, py + y1, pz + z1));
    volume.extendBy(Pnt3f(px + x1, py + y2, pz + z1));
    volume.extendBy(Pnt3f(px + x2, py + y2, pz + z1));
    volume.extendBy(Pnt3f(px + x1, py + y1, pz + z2));
    volume.extendBy(Pnt3f(px + x2, py + y1, pz + z2));
    volume.extendBy(Pnt3f(px + x1, py + y2, pz + z2));
    volume.extendBy(Pnt3f(px + x2, py + y2, pz + z2));
}
Exemple #23
0
    std::vector<uint8_t> _makePNG( char const xC )
    {
        mFont.loadGlyph( xC, 0.0f );

        PNGImage output( { mFont.getGlyphWidth( ), mFont.getGlyphHeight( ) } );

        mFont.printSpans( output, mOutlineColor, mFillColor );

#if 0
        SISULOG("Creating filename.");
        std::stringstream filename;

        _makeFilename( filename, xC );
#endif

        SISULOG("Blitting.");
        output.blit( );

        uint8_t *    data = output.getData( );
        size_t const size = output.getDataSize( );

        SISULOG("Writing to file for posterity.");

        std::cout << "Output data size was: " << size << std::endl;

#if 0
        memoryToFile( filename.str( ).c_str( ), data, size );
#endif

        std::vector<uint8_t> buffer;

        buffer.assign( data, data + size );

        SISULOG("_makePNG OUT");

        return buffer;
    }
	static void draw(const k3d::mesh& Mesh, const k3d::typed_array<k3d::point3>& Points, const k3d::color& Color, FunctorT PointTest, FTFont& Font)
	{
		k3d::gl::color3d(Color);

		const size_t point_begin = 0;
		const size_t point_end = point_begin + Points.size();
		for(size_t point = point_begin; point != point_end; ++point)
		{
			if(PointTest(*Mesh.point_selection, point))
			{
				const k3d::point3 position = Points[point];
				glRasterPos3d(position[0], position[1], position[2]);
				Font.Render(k3d::string_cast(point).c_str());
			}
		}
	}
Exemple #25
0
 int process_lines()
 {
   if (!ftfont) return 0;
   vsx_string<>deli = "\n";
   vsx_nw_vector< vsx_string<> > t_lines;
   vsx_string_helper::explode(text_in->get(), deli, t_lines);
   lines.clear();
   for (unsigned long i = 0; i < t_lines.size(); ++i)
   {
     float x1, y1, z1, x2, y2, z2;
     lines[i].string = t_lines[i];
     ftfont->BBox(t_lines[i].c_str(), x1, y1, z1, x2, y2, z2);
     lines[i].size_x = x2 - x1;
     lines[i].size_y = y2 - y1;
   }
   return 1;
 }
Exemple #26
0
    GLCharacterMap( const char * xFontPath
                    , uint32_t const xFontSize // fixed for now
                    , const char * xTextureStoragePath
                    , _FontPixel32 const & xOutline = _FontPixel32( 255, 255, 255 )
                            , _FontPixel32 const & xFill    = _FontPixel32( 255, 255, 255 ) )// TODO: Hook in memory font support if it becomes necessary (like streaming from net)
        : mFont( xFontPath )
        , mFontSize( xFontSize )
        , mTextureStorage( xTextureStoragePath )
        , mOutlineColor( xOutline )
        , mFillColor( xFill )
    {
        if ( xTextureStoragePath == NULL )
        {
            SISULOG("Texture storage location was not specified (null).");
            exit( -1 );
        }

        mFont.setFontSize( xFontSize );
    }
Exemple #27
0
	int draw_text(int corner_x, int corner_y, int size, string text, int color){
	
		if((size > 4 || size < 1) && size < 10 ){
			cerr << "FutureGL Error: FutureGL only supports 4 core font sizes\nPlease adapt your code. Sorry.\n";
			return -1;
		}
	
		colors(1, color);
		glTranslated(corner_x, corner_y, 0);
	
		// Create a texture font from a TrueType file.

		FTFont *font;
		bool font_loaded = false;

		for(int i = 0; i < num_fonts; i++){
			font = new FTTextureFont(fonts[i].c_str());
			if(!(font->Error())){
				font_loaded = true;
				break;
			}
		}

		
		if(!font_loaded){
			cerr << "FutureGL Error: Font not found\nTried:\n";
			for(int i = 0; i < num_fonts; i++) cerr << "\t" << fonts[i] << "\n";
			return -1;
		}
	
		// Set the font size and render a small text.
		
		if(size == 1) font->FaceSize(60);
		else if(size == 2) font->FaceSize(29);
		else if(size == 3) font->FaceSize(10);
		else if(size == 4) font->FaceSize(10);
		else font->FaceSize(size);
		font->Render(text.c_str());

		delete(font);

		glTranslated(-corner_x, -corner_y, 0);
	
		return 0;
	}
Exemple #28
0
    AudicleFTGLFont( char * name ) { 
        
        glEnable ( GL_TEXTURE_2D );
        
        char fontlocation[512];
        strncpy ( fontlocation, fontpath, 512 );
        strncat ( fontlocation, name, 512 - strlen ( fontlocation ) );
        
        m_font = new FTGLTextureFont ( fontlocation );
        
        if ( m_font->Error() ) { 
            fprintf(stderr, "AudicleFTGLFont: font load error %d - exiting\n", m_font->Error() );
            exit(1);
        }
        else { 
            
        if ( !m_font->FaceSize(18) ) { 
            fprintf(stderr, "AudicleFTGLFont: font size error  %d - exiting\n", m_font->Error() );
            exit(1);
        }

        m_name = name;
        m_font->Depth(2);
        m_font->CharMap(ft_encoding_unicode);
    
        glDisable ( GL_TEXTURE_2D );
        
        float x1, y1, z1, x2, y2, z2;
        
        m_font->BBox( samplestring , x1, y1, z1, x2, y2, z2);
        m_height = y2;
        m_line_height = m_font->LineHeight();
        
        m_height_unit_scale = 1.0 / m_height ;
        m_line_unit_scale = 1.0 / m_line_height ;
        m_mono_width = m_height; 

        }
    }
Exemple #29
0
void RenderThread::coreRendering(FTFont& font, bool testMode)
{
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glDrawBuffer(GL_BACK);
	//Clear the back buffer
	RGB bg=sys->getBackground();
	glClearColor(bg.Red/255.0F,bg.Green/255.0F,bg.Blue/255.0F,1);
	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();

	m_sys->Render(false);
	assert(maskStack.empty());

	if(testMode && m_sys->showDebug)
	{
		glLoadIdentity();
		glScalef(1.0f/scaleX,-1.0f/scaleY,1);
		glTranslatef(-offsetX,(offsetY+windowHeight)*(-1.0f),0);
		glUseProgram(0);
		glDisable(GL_BLEND);
		glActiveTexture(GL_TEXTURE1);
		glDisable(GL_TEXTURE_2D);
		glActiveTexture(GL_TEXTURE0);
		glDisable(GL_TEXTURE_2D);
		if(selectedDebug)
			selectedDebug->debugRender(&font, true);
		else
			m_sys->debugRender(&font, true);
		glActiveTexture(GL_TEXTURE1);
		glEnable(GL_TEXTURE_2D);
		glActiveTexture(GL_TEXTURE0);
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glUseProgram(gpu_program);
	}

	if(m_sys->showProfilingData)
	{
		glLoadIdentity();
		glScalef(1.0f/scaleX,-1.0f/scaleY,1);
		glTranslatef(-offsetX,(offsetY+windowHeight)*(-1.0f),0);
		glUseProgram(0);
		glActiveTexture(GL_TEXTURE1);
		glDisable(GL_TEXTURE_2D);
		glActiveTexture(GL_TEXTURE0);
		glDisable(GL_TEXTURE_2D);
		glColor3f(0,0,0);
		char frameBuf[20];
		snprintf(frameBuf,20,"Frame %u",m_sys->state.FP);
		font.Render(frameBuf,-1,FTPoint(0,0));

		//Draw bars
		glColor4f(0.7,0.7,0.7,0.7);
		glBegin(GL_LINES);
		for(int i=1;i<10;i++)
		{
			glVertex2i(0,(i*windowHeight/10));
			glVertex2i(windowWidth,(i*windowHeight/10));
		}
		glEnd();
		
		list<ThreadProfile>::iterator it=m_sys->profilingData.begin();
		for(;it!=m_sys->profilingData.end();it++)
			it->plot(1000000/m_sys->getFrameRate(),&font);
		glActiveTexture(GL_TEXTURE1);
		glEnable(GL_TEXTURE_2D);
		glActiveTexture(GL_TEXTURE0);
		glEnable(GL_TEXTURE_2D);
		glUseProgram(gpu_program);
	}
}
void MainScreen::LoadResources()
{
    Vector2 screenSize(GetScreenWidth(), GetScreenHeight());
    
    cellH = GetScreenHeight() / 25;
    buttonW = GetScreenWidth() / 10;
    
    
    float32 infoAreaWidth = screenSize.x - 960.0f;

    Vector2 previewSize(screenSize.x - infoAreaWidth, screenSize.y - cellH);
    //Vector2 previewScale(previewSize.x/screenSize.x, previewSize.y/screenSize.y);
    
    preview = new PreviewControl(Rect(0.0f, cellH, previewSize.x, previewSize.y));
    //preview->SetScaledRect(Rect(0.0f, cellH, previewSize.x*0.9f, previewSize.y*0.9f));
    //preview->SetDebugDraw(true);
    
    AddControl(preview);
    
    FTFont* font = FTFont::Create("~res:/Fonts/MyriadPro-Regular.otf");
    font->SetSize(20.0f);
    font->SetColor(0.8f, 0.8f, 0.8f, 1.0f);
    
    chooseProject = new UIButton(Rect(0.0f, 0.0f, buttonW, cellH));
    chooseProject->SetStateDrawType(UIControl::STATE_NORMAL, UIControlBackground::DRAW_FILL);
    chooseProject->GetStateBackground(UIControl::STATE_NORMAL)->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f));
    chooseProject->SetStateDrawType(UIControl::STATE_PRESSED_INSIDE, UIControlBackground::DRAW_FILL);
    chooseProject->GetStateBackground(UIControl::STATE_PRESSED_INSIDE)->SetColor(Color(0.5, 0.5, 0.5, 0.5));
    chooseProject->SetStateFont(UIControl::STATE_NORMAL, font);
    chooseProject->SetStateText(UIControl::STATE_NORMAL, LocalizedString("Project"));
	chooseProject->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MainScreen::OnButtonPressed));
    AddControl(chooseProject);
    
	loadUI = new UIButton(Rect(2*buttonW, 0, buttonW, cellH));
    loadUI->SetStateDrawType(UIControl::STATE_NORMAL, UIControlBackground::DRAW_FILL);
    loadUI->GetStateBackground(UIControl::STATE_NORMAL)->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f));
    loadUI->SetStateDrawType(UIControl::STATE_PRESSED_INSIDE, UIControlBackground::DRAW_FILL);
    loadUI->GetStateBackground(UIControl::STATE_PRESSED_INSIDE)->SetColor(Color(0.5f, 0.5f, 0.5f, 0.5f));
    loadUI->SetStateFont(UIControl::STATE_NORMAL, font);
    loadUI->SetStateText(UIControl::STATE_NORMAL, LocalizedString("Load"));
	loadUI->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MainScreen::OnButtonPressed));
    AddControl(loadUI);
    loadUI->SetVisible(false);
    
    saveUI = new UIButton(Rect(buttonW*3, 0, buttonW, cellH));
    saveUI->SetStateDrawType(UIControl::STATE_NORMAL, UIControlBackground::DRAW_FILL);
    saveUI->GetStateBackground(UIControl::STATE_NORMAL)->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f));
    saveUI->SetStateDrawType(UIControl::STATE_PRESSED_INSIDE, UIControlBackground::DRAW_FILL);
    saveUI->GetStateBackground(UIControl::STATE_PRESSED_INSIDE)->SetColor(Color(0.5f, 0.5f, 0.5f, 0.5f));
    saveUI->SetStateFont(UIControl::STATE_NORMAL, font);
    saveUI->SetStateText(UIControl::STATE_NORMAL, LocalizedString("Save"));
	saveUI->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MainScreen::OnButtonPressed));
    //TODO: add saveUI when uiviewer becomes editor
    //AddControl(saveUI);
    
    selectHoverModeButton = new UIButton(Rect(buttonW*4, 0, 2*buttonW, cellH));
    
    selectHoverModeButton->SetStateDrawType(UIControl::STATE_NORMAL, UIControlBackground::DRAW_FILL);
    selectHoverModeButton->GetStateBackground(UIControl::STATE_NORMAL)->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f));
    selectHoverModeButton->SetStateFont(UIControl::STATE_NORMAL, font);
    selectHoverModeButton->SetStateText(UIControl::STATE_NORMAL, LocalizedString("selection.mode.click"));
    
    selectHoverModeButton->SetStateDrawType(UIControl::STATE_PRESSED_INSIDE, UIControlBackground::DRAW_FILL);
    selectHoverModeButton->GetStateBackground(UIControl::STATE_PRESSED_INSIDE)->SetColor(Color(0.5f, 0.5f, 0.5f, 0.5f));
    
    selectHoverModeButton->SetStateDrawType(UIControl::STATE_SELECTED, UIControlBackground::DRAW_FILL);
    selectHoverModeButton->GetStateBackground(UIControl::STATE_SELECTED)->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f));
    selectHoverModeButton->SetStateFont(UIControl::STATE_SELECTED, font);
    selectHoverModeButton->SetStateText(UIControl::STATE_SELECTED, LocalizedString("selection.mode.hover"));
    
	selectHoverModeButton->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MainScreen::OnButtonPressed));
    AddControl(selectHoverModeButton);
    selectHoverModeButton->SetVisible(false);
    
    for (int32 i = 0; i < InfoControl::INFO_TYPES_COUNT; ++i) 
    {
        keyTexts[i] = new UIStaticText(Rect(screenSize.x - infoAreaWidth, cellH*(2*i+1), infoAreaWidth, cellH));
        keyTexts[i]->SetFont(font);
        keyTexts[i]->SetText(keyNames[i]);
        AddControl(keyTexts[i]);
        
        valueTexts[i] = new UIStaticText(Rect(screenSize.x - infoAreaWidth, cellH*(2*i+2), infoAreaWidth, cellH));
        valueTexts[i]->SetFont(font);
        AddControl(valueTexts[i]);
    }
    
    additionalInfoList = new UIList(Rect(screenSize.x - infoAreaWidth, cellH*(2*InfoControl::INFO_TYPES_COUNT+2), infoAreaWidth, screenSize.y - cellH*(2*InfoControl::INFO_TYPES_COUNT+2) ), UIList::ORIENTATION_VERTICAL);
    additionalInfoList->SetDelegate(this);
    AddControl(additionalInfoList);
    
    fsDlg = new UIFileSystemDialog("~res:/Fonts/MyriadPro-Regular.otf");
    fsDlg->SetDelegate(this);
    Vector<String> filter;
    filter.push_back(".yaml");
    filter.push_back(".YAML");
    fsDlg->SetExtensionFilter(filter);
    fsDlg->SetTitle(LocalizedString("Dlg.Load"));
    fsDlg->SetCurrentDir(FileSystem::Instance()->SystemPathForFrameworkPath("~res:/")); 

    fsDlgProject = new UIFileSystemDialog("~res:/Fonts/MyriadPro-Regular.otf"); //default = GetCurrentWorkingDirectory 
    fsDlgProject->SetDelegate(this);
    fsDlgProject->SetOperationType(UIFileSystemDialog::OPERATION_CHOOSE_DIR);
    fsDlgProject->SetTitle(LocalizedString("Dlg.ChoosePrj"));
    
    KeyedArchive* archive = new KeyedArchive();
	if(archive->Load("~doc:/uiviewer.archive"))
    {
        if(archive->IsKeyExists("projectPath"))
        {
            projectPath = archive->GetString("projectPath");
            //TODO: different path formats on different OS
            OnLoadProject();
            fsDlgProject->SetCurrentDir(projectPath);
        }
    }
    SafeRelease(archive);

    
    SafeRelease(font);
}