3 #include <Base/Common/BIASpragma.hh>
4 #include <Gui/DrawTextWx.hh>
5 #include <Base/Image/Image.hh>
6 #include <Base/Image/ColourRGB.hh>
7 #include <Gui/StringConv.hh>
13 template <
class StorageType>
16 unsigned &width,
unsigned &height,
17 const unsigned point_size)
22 BIASERR(
"DrawTextWx::Text(): wxMemoryDC is not OK\n");
25 wxFont font = dc.GetFont();
26 font.SetPointSize(point_size);
33 dc.GetTextExtent(str,&x,&y);
37 wxSize size = dc.GetTextExtent(str);
38 width = size.GetWidth();
39 height = size.GetHeight();
45 template <
class StorageType>
48 const unsigned &pos_x,
const unsigned &pos_y,
51 const unsigned point_size,
56 BIASERR(
"DrawTextWx::Text(): Cannot draw text in single channel image.\n");
57 return DTWX_INVALID_ARGUMENT;
60 BIASERR(
"DrawTextWx::Text(): Works only with RGB images.\n");
61 return DTWX_INVALID_ARGUMENT;
64 const bool static_data =
true;
68 BIASERR(
"DrawTextWx::Text(): wxImage is not OK\n");
76 BIASERR(
"DrawTextWx::Text(): wxBitmap is not OK\n");
81 BIASERR(
"DrawTextWx::Text(): wxMemoryDC is not OK\n");
85 dc.SetTextForeground(wxColor(foreground_color[0],
87 foreground_color[2]));
88 dc.SetTextBackground(wxColour(background_color[0],
90 background_color[2]));
92 wxFont font = dc.GetFont();
93 font.SetPointSize(point_size);
100 dc.GetTextExtent(str,&w,&h);
103 wxSize size = dc.GetTextExtent(str);
106 switch (vertical_align){
107 case V_ALIGN_TOP: py = (int)pos_y;
break;
108 case V_ALIGN_CENTER: py = (int)pos_y - size.GetHeight()/2;
break;
109 case V_ALIGN_BOTTOM: py = (int)pos_y - size.GetHeight();
break;
110 default: cerr <<
"unkown vertical alignment: "<<vertical_align<<endl;
111 return DTWX_INVALID_ARGUMENT;
break;
113 if (py<0 || py+size.GetHeight()>=(int)im.
GetHeight()){
114 res = DTWX_OUT_OF_IMAGE;
116 switch (horizontal_align){
117 case H_ALIGN_LEFT: px = (int)pos_x;
break;
118 case H_ALIGN_CENTER: px = (int)pos_x - size.GetWidth()/2;
break;
119 case H_ALIGN_RIGHT: px = (int)pos_x - size.GetWidth();
break;
120 default: cerr <<
"unkown horizontal alignment: "<<horizontal_align<<endl;
121 return DTWX_INVALID_ARGUMENT;
break;
123 if (px<0 || px+size.GetWidth()>=(int)im.
GetWidth()){
124 res = DTWX_OUT_OF_IMAGE;
126 dc.DrawText(str, px, py);
128 dc.SelectObject(wxNullBitmap);
130 wxImage dst_img = bmp.ConvertToImage();
143 #define INST(type) template class BIASGui_EXPORT DrawTextWx<type>
static int GetTextExtend(const std::string &text, unsigned &width, unsigned &height, const unsigned point_size=8)
returns size of the bounding box of the text
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
static int Text(Image< StorageType > &im, const std::string &text, const unsigned &pos_x, const unsigned &pos_y, const ColourRGB< StorageType > &foreground_color=COLOR_WHITE, const ColourRGB< StorageType > &background_color=COLOR_BLACK, const unsigned point_size=8, const enum EVerticalAlign vertical_align=V_ALIGN_TOP, const enum EHorizontalAlign horizontal_align=H_ALIGN_LEFT)
write text in an image !!! Can only be used in wx-GUI applications which implement wxApp !!! ...
unsigned int GetSizeByte() const
returns the nr.
interface class used to ease handover in function calls
unsigned int GetWidth() const
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
color values, 3 channels, order: red,green,blue
unsigned int GetHeight() const
The image template class for specific storage types.
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
enum EColorModel GetColorModel() const