Hi I can't seem to adjust the D3DXFONT_DESC properties. Sometimes it breaks at getDesc(...). I want to be able
to have each text row have their own font description and be able to change it. Why is it not working???

Maybe I setting it in the wrong place or maybe it is not being 'set'. (See ::Add)

My great thanks to you who solves it!!!

Here is the class header and implementation:
CText.h

#ifndef CText_h
#define CText_h

#include <d3dx9.h>

#define MAX_TEXT_ROWS 20

class CText
{
public: 
    CText(void);
    ~CText(void);

    void Create(void);
    int  Add(char* cText);
    void Remove(void);
    void SetRow(int iRow, char* cText);

    LPD3DXFONT GetFont(void);
    void SetItalic(bool bItalic);

    void Draw(void);
    void DrawTable(void);


private:

    LPD3DXFONT  m_DXFontMaster;   // pointer to the font object

    RECT        m_TextBoxMaster;        // rect to contain the text

    struct TEXTROW_TYPE 
    {
        char*       m_cText;    // the text to be displayed 
        LPD3DXFONT  m_DXFont;   // pointer to the font object
        RECT        m_TextBox;
    };

    TEXTROW_TYPE*   m_pTextRow[MAX_TEXT_ROWS]; // array of structs

    int             m_EndRow;
    //int               m_iMaxRows;

};// CText

#endif // CText_h

CText.cpp

#include "CText.h"
#include "CApplication.h"

// ********************************************************************* //
// Name: CText                                                           //
// Description: Constructor                                              //
// ********************************************************************* //
CText::CText(void)
{
    m_EndRow = 0;

    // initialise array
    for (int i = 0; i < MAX_TEXT_ROWS; i++) 
    {
        m_pTextRow[i] = new TEXTROW_TYPE;                   // create new struct
        m_pTextRow[i]->m_cText = "This is NULL";            // choose blank string
        m_pTextRow[i]->m_DXFont = NULL;                     // NULL object
        SetRect(&m_pTextRow[i]->m_TextBox, 0, 0, 640, 480); // set size of rect
    }

}// CText

// ********************************************************************* //
// Name: Create                                                          //
// Description: Constructor                                              //
// ********************************************************************* //
void CText::Create(void)
{
    D3DXCreateFont(g_App.GetDevice(),           // the D3D Device
                   30,                          // font height of 30
                   0,                           // default font width
                   FW_NORMAL,                   // font weight
                   1,                           // not using MipLevels
                   true,                        // italic font
                   DEFAULT_CHARSET,             // default character set
                   OUT_DEFAULT_PRECIS,          // default OutputPrecision,
                   DEFAULT_QUALITY,             // default Quality
                   DEFAULT_PITCH | FF_DONTCARE, // default pitch and family
                   (LPCSTR)"Arial",             // use Facename Arial
                   //&m_pTextRow[m_EndRow]->m_DXFont);              // the font object
                   &m_DXFontMaster);                // the font object

}// Create

// ********************************************************************* //
// Name: Add                                                             //
// Description: Adds a new row pf text. Returns the row number           //
// ********************************************************************* //
int CText::Add(char* cText)
{
    if (m_EndRow < MAX_TEXT_ROWS)
    {
        D3DXFONT_DESC FontDesc;

        // calc previous element
        if ((m_EndRow - 1) < 0) 
        {
            // calc RECT at 0 as no previous rect
            SetRect(&m_pTextRow[m_EndRow]->m_TextBox, 0, 0, 640, 480);
        }
        else 
        {
            // get previous height
            m_pTextRow[m_EndRow-1]->m_DXFont->GetDesc(&FontDesc);

            // calc current RECT just below previous RECT
            SetRect(&m_pTextRow[m_EndRow]->m_TextBox, 
                    0, 
                    m_pTextRow[m_EndRow-1]->m_TextBox.top + FontDesc.Height, 
                    640, 
                    480);
        }

        m_pTextRow[m_EndRow]->m_cText = cText;  // add text to the table
        m_pTextRow[m_EndRow]->m_DXFont = m_DXFontMaster;

        // ****************** THIS DOESN'T WORK
        FontDesc.Italic = false;
        // ******************


        m_EndRow++;                             // increase to the next row
        return (m_EndRow-1);                    // return successful this row
    }
    else 
        return (0);

}// AddText

// ********************************************************************* //
// Name: RemoveText                                                          //
// Description: Display Hello World                                      //
// ********************************************************************* //
void CText::Remove(void)
{
}

// ********************************************************************* //
// Name: SetText                                                         //
// Description: Display Hello World                                      //
// ********************************************************************* //
void CText::SetRow(int iRow, char* cText)
{
}

LPD3DXFONT CText::GetFont(void) 
{ 
    return m_pTextRow[m_EndRow]->m_DXFont; 
}

void CText::SetItalic(bool bItalic)
{
    D3DXFONT_DESC FontDesc;
    m_pTextRow[m_EndRow]->m_DXFont->GetDesc(&FontDesc);

    // set Italicisation
    FontDesc.Italic = bItalic;

}

// ********************************************************************* //
// Name: Draw                                                            //
// Description: Display Hello World                                      //
// ********************************************************************* //
void CText::Draw(void)
{
    // create a RECT to contain the text
    SetRect(&m_TextBoxMaster, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); 

    // draw the Hello World text
    m_pTextRow[0]->m_DXFont->DrawTextA(NULL,
                             "Hello World...",
                             13,
                             &m_TextBoxMaster,
                             DT_TOP | DT_LEFT,
                             //DT_CENTER | DT_VCENTER,
                             D3DCOLOR_ARGB(255, 255, 255, 255));
}// Draw

// ********************************************************************* //
// Name: DrawTable                                                       //
// Description: Display all the texts stored                             //
// ********************************************************************* //
void CText::DrawTable(void)
{
    for (int i = 0; i < m_EndRow; i++)
        // draw the Hello World text
        m_pTextRow[i]->m_DXFont->DrawTextA(NULL,
                                m_pTextRow[i]->m_cText,
                                strlen(m_pTextRow[i]->m_cText),
                                &m_pTextRow[i]->m_TextBox,
                                DT_TOP | DT_LEFT,
                                //DT_CENTER | DT_VCENTER,
                                D3DCOLOR_ARGB(255, 255, 255, 255));
};


// ********************************************************************* //
// Name: ~CText                                                          //
// Description: Destructor                                               //
// ********************************************************************* //
CText::~CText(void)
{
    if(m_pTextRow[0]->m_DXFont)
    {
        m_pTextRow[0]->m_DXFont->Release();
        m_pTextRow[0]->m_DXFont=NULL;
    }
}// ~CText

It's not supposed to work like that.

You have to create the font again, replacing the old one.

So call CText::Create() with an italic parameter.

Congratulations! You're no longer a DaniWeb newbie.<br /> <br />
Your DaniWeb account has just been upgraded from newbie status and now you have the ability to take advantage of everything the community has to offer.<br /> <br />
You can now enjoy an advertisement-free DaniWeb by ticking the checkbox to Disable Ads in your profile. You will no longer have to fill out the human verification check when you post. You can also now send unlimited private messages, contribute new code snippets, and tag articles with never-before-used tags.

Thanks yet again dx9_programmer I have cleaned up the code and call a createcustom function. Each time i want to add I alter a saved font description then use that with the create function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.