00001
00002
00003
00004
00005
00006
00007
00009
00010 #ifndef DRAWUTILS_H_
00011 #define DRAWUTILS_H_
00012
00020 inline static void DrawTextCenter(wxDC &dc, wxCoord x, wxCoord y, wxString text)
00021 {
00022 wxSize textExtent = dc.GetTextExtent(text);
00023
00024 x -= textExtent.x / 2;
00025 y -= textExtent.y / 2;
00026
00027 dc.DrawText(text, x, y);
00028 }
00029
00036 inline static void DrawTextCenter(wxDC &dc, wxRect &rc, wxString text)
00037 {
00038 wxSize textExtent = dc.GetTextExtent(text);
00039
00040 wxCoord x = rc.x + (rc.GetWidth() - textExtent.x) / 2;
00041 wxCoord y = rc.y + (rc.GetHeight() - textExtent.y) / 2;
00042
00043 dc.DrawText(text, x, y);
00044 }
00045
00052 inline static void CheckFixRect(wxRect &rc)
00053 {
00054 if (rc.x < 0)
00055 rc.x = 0;
00056 if (rc.y < 0)
00057 rc.y = 0;
00058 if (rc.width < 0)
00059 rc.width = 0;
00060 if (rc.height < 0)
00061 rc.height = 0;
00062 }
00063
00072 inline static void Margins(wxRect &rc, wxCoord left, wxCoord top, wxCoord right, wxCoord bottom)
00073 {
00074 if ((left + right) > rc.width) {
00075 rc.x = left;
00076 rc.width = 0;
00077 }
00078 else {
00079 rc.x += left;
00080 rc.width -= (left + right);
00081 }
00082
00083 if ((top + bottom) > rc.height) {
00084 rc.y = top;
00085 rc.height = 0;
00086 }
00087 else {
00088 rc.y += top;
00089 rc.height -= (top + bottom);
00090 }
00091
00092 CheckFixRect(rc);
00093 }
00094
00103 inline static void SetupRect(wxRect &rc, wxCoord x0, wxCoord y0, wxCoord x1, wxCoord y1)
00104 {
00105 if (x0 < x1) {
00106 rc.x = x0;
00107 rc.width = x1 - x0;
00108 }
00109 else {
00110 rc.x = x1;
00111 rc.width = x0 - x1;
00112 }
00113
00114 if (y0 < y1) {
00115 rc.y = y0;
00116 rc.height = y1 - y0;
00117 }
00118 else {
00119 rc.y = y1;
00120 rc.height = y0 - y1;
00121 }
00122 }
00123
00124 #endif