#ifndef Schrift_H #define Schrift_H #include #include "Critical.h" #include "Point.h" #include "ReferenceCounter.h" namespace Framework { class Bild; //! Image.h class Text; //! Text.h class Buchstabe; //! from this file class Alphabet; //! from this file class Schrift; //! from this file //! Stores the alpha values of a character of a specific font. //! The other color values are determined by the font color. Hence only //! the alpha values. class Buchstabe : public virtual ReferenceCounter { private: Punkt size; unsigned char* alpha; int schriftSize; public: //! Creates a new empty object DLLEXPORT Buchstabe(); //! Deletes the object DLLEXPORT ~Buchstabe(); //! Creates a new character with a specific size //! \param size The size of the character in pixels DLLEXPORT void NeuBuchstabe(Punkt& size); //! Sets the alpha value of a specific pixel //! \param pos The position of the pixel //! \param alpha The value of the pixel DLLEXPORT void setPixel(Punkt& pos, unsigned char alpha); //! Sets the alpha value of a specific pixel //! \param x The x position of the pixel //! \param y The y position of the pixel //! \param alpha The value of the pixel DLLEXPORT void setPixel(int x, int y, unsigned char alpha); //! Sets the alpha value of a specific pixel //! \param i The index of the pixel. Calculated as x + y * //! width and ranges from 0 to width * height - 1 \param alpha The value //! of the pixel DLLEXPORT void setPixel(int i, unsigned char alpha); //! Sets the font size this character belongs to //! \param sg The font size of the character. DLLEXPORT void setSchriftSize(int sg); //! Returns the font size this character belongs to DLLEXPORT int getSchriftSize() const; //! Returns the alpha values of the character as an array where the //! values are stored row by row DLLEXPORT unsigned char* getBuff() const; //! Returns the unscaled size of the character in pixels. DLLEXPORT const Punkt& getSize() const; //! Returns the width of the character in pixels DLLEXPORT int getBreite() const; //! Returns the height of the character in pixels DLLEXPORT int getHeight() const; }; //! Stores all characters of the same font size. //! Used by the Schrift class class Alphabet : public virtual ReferenceCounter { private: Buchstabe** zeichen; int schriftSize; public: //! Creates an empty object DLLEXPORT Alphabet(); //! Deletes the object DLLEXPORT ~Alphabet(); //! Deletes all stored characters DLLEXPORT void NeuAlphabet(); //! Adds a character to the alphabet. //! If the added character already exists, it will be overwritten //! \param i The ASCII code of the character to add //! \param buchstabe The character to add DLLEXPORT void setBuchstabe(unsigned char i, Buchstabe* buchstabe); //! Sets the font size of the alphabet and its stored characters //! \param gr The font size of the alphabet DLLEXPORT void setSchriftSize(int gr); //! Returns the stored character for a specific ASCII code //! \param i The ASCII code of the character \return A pointer to //! the character with increased reference counter DLLEXPORT Buchstabe* getBuchstabe(unsigned char i) const; //! Returns the stored character for a specific ASCII code //! \param i The ASCII code of the character \return A pointer to //! the character without increased reference counter DLLEXPORT Buchstabe* zBuchstabe(unsigned char i) const; //! Checks whether a character exists for a specific ASCII code //! \param b The ASCII code to check //! \return (true) if a character was found for the code. (false) //! otherwise DLLEXPORT bool hatBuchstabe(unsigned char b) const; //! Returns the font size whose characters are stored in this alphabet DLLEXPORT int getSchriftSize() const; }; //! Stores a list of alphabets with different font sizes. //! Used by the Schrift class to store all characters sorted by font size. class AlphabetArray { private: Alphabet* alphabets[256]; public: //! Creates a new list DLLEXPORT AlphabetArray(); //! Adds an alphabet to the list. //! If an alphabet with the same font size already exists, //! the alphabet is not added \param alphabet The alphabet //! to add \return (true) if the alphabet was added. (false) otherwise. DLLEXPORT bool addAlphabet(Alphabet* alphabet); //! Removes an alphabet of a specific font size from the list //! \param sg The font size of the alphabet to remove //! \return (true) if an alphabet was removed. (false) otherwise DLLEXPORT bool removeAlphabet(unsigned char sg); //! Returns a specific alphabet with increased reference counter //! \param sg The font size whose alphabet is sought //! \return (0) if no matching alphabet was found DLLEXPORT Alphabet* getAlphabet(unsigned char sg) const; //! Returns a specific alphabet without increased reference counter //! \param sg The font size whose alphabet is sought //! \return (0) if no matching alphabet was found DLLEXPORT Alphabet* zAlphabet(unsigned char sg) const; }; //! Stores all characters of a font in different font sizes class Schrift : public virtual ReferenceCounter { private: unsigned char alphabetAnzahl; AlphabetArray* alphabet; public: //! Creates an empty font DLLEXPORT Schrift(); //! Deletes the object DLLEXPORT ~Schrift(); //! Adds an alphabet to the font. If an alphabet of the same font //! size already exists, the alphabet is not added //! \param alphabet The alphabet to add //! \return (true) if the alphabet was added. (false) otherwise DLLEXPORT bool addAlphabet(Alphabet* alphabet); //! Removes a specific alphabet from the font //! \param sg The font size whose alphabet should be removed DLLEXPORT void removeAlphabet(unsigned char sg); //! Returns a specific alphabet with increased reference counter //! \param sg The font size whose alphabet is sought //! \return (0) if no matching alphabet was found DLLEXPORT Alphabet* getAlphabet(unsigned char sg) const; //! Returns a specific alphabet without increased reference counter //! \param sg The font size whose alphabet is sought //! \return (0) if no matching alphabet was found DLLEXPORT Alphabet* zAlphabet(unsigned char sg) const; //! Returns how many alphabets (and thus font sizes) the font contains DLLEXPORT unsigned char getAlphabetAnzahl() const; }; class TextRenderer : public virtual ReferenceCounter { protected: Schrift* s; int schriftSize; int zeilenAbstand; int zeichenAbstand; int charWidths[256]; int charHeights[256]; public: DLLEXPORT TextRenderer(); DLLEXPORT TextRenderer(Schrift* schrift); DLLEXPORT virtual ~TextRenderer(); DLLEXPORT void setSchriftZ(Schrift* schrift); DLLEXPORT Schrift* getSchrift(); DLLEXPORT Schrift* zSchrift(); //! Sets the font size to draw with. The font automatically //! selects the appropriate alphabet for drawing \param sg The font size DLLEXPORT void setSchriftSize(int sg); //! Sets the line spacing to use for drawing //! \param za The line spacing to the bottom of the line above in pixels DLLEXPORT void setZeilenAbstand(int za); //! Sets the character spacing to use for drawing //! \param za The character spacing in pixels DLLEXPORT void setZeichenAbstand(int za); //! Inserts line breaks into the text so it is fully displayed //! at a given width \param zText The text to insert line breaks into //! \param maxBreite The width in pixels at which the text should be //! fully displayed DLLEXPORT virtual void textFormatieren(Text* zText, int maxBreite); //! Draws a specific text with cursor and coloring onto an image. //! Use (setPosition) and (setDrawSchriftGroesse) to change position //! and size \param x x position of the first character //! \param y y position of the first character //! \param txt The text to draw //! \param zRObj The image to draw on //! \param cpos The position of the cursor in the text //! \param cf The color of the cursor //! \param fbeg The position of the character in the text where coloring //! should begin. The text is colored from there to the cursor position //! \param ff The background color of the colored text //! \param f A function called for each character that returns its color DLLEXPORT virtual void renderText(int x, int y, const char* txt, Bild& zRObj, std::function f, int cpos = -1, int cf = 0, int fbeg = -1, int ff = 0); //! Draws a specific text with cursor and coloring onto an image. //! Use (setPosition) and (setDrawSchriftGroesse) to change position //! and size \param x x position of the first character //! \param y y position of the first character //! \param txt The text to draw //! \param zRObj The image to draw on //! \param cpos The position of the cursor in the text //! \param cf The color of the cursor //! \param fbeg The position of the character in the text where coloring //! should begin. The text is colored from there to the cursor position //! \param ff The background color of the colored text //! \param f The color in which the text should be drawn DLLEXPORT virtual void renderText(int x, int y, const char* txt, Bild& zRObj, int f, int cpos = -1, int cf = 0, int fbeg = -1, int ff = 0); //! Draws a specific character with coloring onto an image. //! Use (setPosition) and (setDrawSchriftGroesse) to change position //! and size \param x x position of the first character //! \param y y position of the first character //! \param txt The text to draw //! \param zRObj The image to draw on //! \param color The color in which the text should be drawn //! \param underlined 1 if the text should be underlined //! \param selected 1 if the character should be colored //! \param selectedBackgroundColor The background color of the //! colored text DLLEXPORT virtual void renderChar(int& x, int y, char c, Bild& zRObj, int color, bool underlined = 0, bool selected = 0, int selectedBackgroundColor = 0); //! Returns the font size used for drawing DLLEXPORT int getSchriftSize() const; //! Determines how many pixels are needed to fully display a specific text //! \param txt The text whose width in pixels should be determined DLLEXPORT virtual int getTextBreite(const char* txt) const; //! Determines how many pixels are needed to fully display a specific text //! \param txt The text whose height in pixels should be determined DLLEXPORT virtual int getTextHeight(const char* txt) const; //! Determines how many pixels are needed to fully display a specific //! character \param c The character whose width in pixels should be //! determined DLLEXPORT virtual int getCharWidth(const char c) const; //! Determines the maximum pixels needed to fully display a character DLLEXPORT virtual int getMaxCharWidth() const; //! Determines how many pixels are needed to fully display a specific //! character \param c The character whose height in pixels should be //! determined DLLEXPORT virtual int getCharHeight(const char c) const; //! Returns the line spacing in pixels to the bottom of the line above DLLEXPORT int getZeilenAbstand() const; //! Returns the character spacing in pixels on the x axis DLLEXPORT int getZeichenAbstand() const; //! Returns the scaled height needed by a drawn line in pixels DLLEXPORT int getZeilenHeight() const; //! Determines the character in the text that the mouse points to //! \param zTxt The text the mouse points to //! \param mausX The X position of the mouse in pixels relative to the //! position of the first character \param mausY The Y position of the //! mouse in pixels relative to the position of the first character DLLEXPORT virtual int textPos( const char* txt, int mausX, int mausY) const; }; class GravurTextRenderer : public TextRenderer { public: DLLEXPORT GravurTextRenderer(); DLLEXPORT GravurTextRenderer(Schrift* schrift); DLLEXPORT virtual ~GravurTextRenderer(); //! Draws a specific character with coloring onto an image. //! Use (setPosition) and (setDrawSchriftGroesse) to change position //! and size \param x x position of the first character //! \param y y position of the first character //! \param txt The text to draw //! \param zRObj The image to draw on //! \param color The color in which the text should be drawn //! \param underlined 1 if the text should be underlined //! \param selected 1 if the character should be colored //! \param selectedBackgroundColor The background color of the //! colored text DLLEXPORT virtual void renderChar(int& x, int y, char c, Bild& zRObj, int color, bool underlined = 0, bool selected = 0, int selectedBackgroundColor = 0) override; //! Determines how many pixels are needed to fully display a specific //! character \param c The character whose width in pixels should be //! determined DLLEXPORT virtual int getCharWidth(const char c) const override; //! Determines how many pixels are needed to fully display a specific //! character \param c The character whose height in pixels should be //! determined DLLEXPORT virtual int getCharHeight(const char c) const override; }; class KursivTextRenderer : public TextRenderer { public: DLLEXPORT KursivTextRenderer(); DLLEXPORT KursivTextRenderer(Schrift* schrift); DLLEXPORT virtual ~KursivTextRenderer(); //! Draws a specific character with coloring onto an image. //! Use (setPosition) and (setDrawSchriftGroesse) to change position //! and size \param x x position of the first character //! \param y y position of the first character //! \param txt The text to draw //! \param zRObj The image to draw on //! \param color The color in which the text should be drawn //! \param underlined 1 if the text should be underlined //! \param selected 1 if the character should be colored //! \param selectedBackgroundColor The background color of the //! colored text DLLEXPORT virtual void renderChar(int& x, int y, char c, Bild& zRObj, int color, bool underlined = 0, bool selected = 0, int selectedBackgroundColor = 0) override; //! Determines how many pixels are needed to fully display a specific //! character \param c The character whose width in pixels should be //! determined DLLEXPORT virtual int getCharWidth(const char c) const override; }; } // namespace Framework #endif