00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022
00023 #include "Text_button.h"
00024 #include "gamewin.h"
00025 #include "font.h"
00026 #include "iwin8.h"
00027 #include "Gump.h"
00028
00029 #define TB_FONTNUM 2
00030
00031
00032 #define TB_OUTER_BORDER 133
00033 #define TB_OUTER_BORDER_CORNER 142
00034 #define TB_OUTER_BORDER_PUSHED_TOP 144
00035 #define TB_OUTER_BORDER_PUSHED_LEFT 140
00036
00037 #define TB_INNER_BORDER_HIGHLIGHT 138
00038 #define TB_INNER_BORDER_LOWLIGHT 142
00039 #define TB_INNER_BORDER_CORNER 141
00040 #define TB_INNER_BORDER_TR_HIGH 137
00041 #define TB_INNER_BORDER_TR_CORNER 138
00042 #define TB_INNER_BORDER_BL_CORNER 144
00043
00044 #define TB_BACKGROUND 140
00045 #define TB_RT_HIGHLIGHT 139
00046
00047 Text_button::Text_button(Gump *p, const std::string &str, int x, int y, int w, int h)
00048 : Gump_button(p, 0, x, y, SF_OTHER), text(str), width(w), height(h)
00049 {
00050 init();
00051 }
00052
00053 void Text_button::init()
00054 {
00055
00056 if (height < 11) height = 11;
00057
00058
00059 text_y = 2 + (height - 11)/2;
00060
00061
00062 int text_width = sman->get_font(TB_FONTNUM)->get_text_width(
00063 text.c_str());
00064
00065 if (width < text_width + 4) width = text_width + 4;
00066
00067
00068 text_x = (width - text_width) >> 1;
00069 }
00070
00071 void Text_button::paint()
00072 {
00073 Image_window8 *iwin = gwin->get_win();
00074
00075 int offset = 0;
00076 int px = x;
00077 int py = y;
00078
00079 if (parent)
00080 {
00081 px += parent->get_x();
00082 py += parent->get_y();
00083 }
00084
00085
00086 if (pushed)
00087 {
00088
00089 iwin->fill8(TB_OUTER_BORDER_CORNER, 1, 1, px, py);
00090
00091 iwin->fill8(TB_OUTER_BORDER_CORNER, 1, 1, px, py+height-1);
00092
00093 iwin->fill8(TB_OUTER_BORDER_CORNER, 1, 1, px+width-1, py);
00094
00095 iwin->fill8(TB_OUTER_BORDER_PUSHED_TOP, width-2, 1, px+1, py);
00096
00097 iwin->fill8(TB_OUTER_BORDER_PUSHED_TOP, 1, height-2, px, py+1);
00098
00099 offset = 1;
00100 }
00101 else
00102 {
00103
00104 iwin->fill8(TB_OUTER_BORDER_CORNER, 1, 1, px+width-1, py+height-1);
00105
00106 iwin->fill8(TB_OUTER_BORDER_CORNER, 1, 1, px, py+height-1);
00107
00108 iwin->fill8(TB_OUTER_BORDER_CORNER, 1, 1, px+width-1, py+height-1);
00109
00110 iwin->fill8(TB_OUTER_BORDER, width-2, 1, px+1, py+height-1);
00111
00112 iwin->fill8(TB_OUTER_BORDER, 1, height-2, px+width-1, py+1);
00113 }
00114
00115
00116
00117
00118 iwin->fill8(TB_OUTER_BORDER_CORNER, 1, 1, px+offset, py+offset);
00119
00120 iwin->fill8(TB_OUTER_BORDER, width-2, 1, px+1+offset, py+offset);
00121
00122 iwin->fill8(TB_OUTER_BORDER, 1, height-2, px+offset, py+1+offset);
00123
00124
00125
00126
00127 iwin->fill8(TB_INNER_BORDER_CORNER, 1, 1, px+offset+1, py+offset+1);
00128
00129 iwin->fill8(TB_INNER_BORDER_TR_CORNER, 1, 1, px+width+offset-2, py+offset+1);
00130
00131 iwin->fill8(TB_INNER_BORDER_TR_HIGH, 1, 1, px+width+offset-3, py+offset+1);
00132
00133 iwin->fill8(TB_INNER_BORDER_TR_HIGH, 1, 1, px+width+offset-2, py+offset+2);
00134
00135 iwin->fill8(TB_INNER_BORDER_BL_CORNER, 1, 1, px+offset+1, py+height+offset-2);
00136
00137
00138 iwin->fill8(TB_INNER_BORDER_HIGHLIGHT, width-5, 1, px+2+offset, py+offset+1);
00139
00140 iwin->fill8(TB_INNER_BORDER_LOWLIGHT, 1, height-4, px+offset+1, py+2+offset);
00141
00142 iwin->fill8(TB_INNER_BORDER_HIGHLIGHT, 1, height-5, px+width+offset-2, py+3+offset);
00143
00144 iwin->fill8(TB_INNER_BORDER_LOWLIGHT, width-4, 1, px+2+offset, py+height+offset-2);
00145
00146
00147 iwin->fill8(TB_BACKGROUND, width-4, height-4, px+2+offset, py+2+offset);
00148
00149 iwin->fill8(TB_RT_HIGHLIGHT, 1, 1, px+width+offset-3, py+offset+2);
00150
00151 sman->paint_text(TB_FONTNUM, text.c_str(), px+text_x+offset,
00152 py+text_y+offset);
00153 }
00154
00155 int Text_button::on_widget(int mx, int my)
00156 {
00157 int px = x;
00158 int py = y;
00159
00160 if (parent)
00161 {
00162 px += parent->get_x();
00163 py += parent->get_y();
00164 }
00165
00166 if (mx < px || mx >= px + width) return 0;
00167 if (my < py || my >= py + height) return 0;
00168 return 1;
00169 }