00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #define GETTEXT_DOMAIN "wesnoth-editor"
00016
00017 #include "gui/dialogs/editor_resize_map.hpp"
00018
00019 #include "gui/dialogs/field.hpp"
00020 #include "gui/dialogs/helper.hpp"
00021 #include "gui/widgets/toggle_button.hpp"
00022 #include "gui/widgets/settings.hpp"
00023 #include "gui/widgets/slider.hpp"
00024
00025 #include <boost/bind.hpp>
00026
00027 namespace gui2 {
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 REGISTER_DIALOG(editor_resize_map)
00090
00091 teditor_resize_map::teditor_resize_map(
00092 int& width
00093 , int& height
00094 , EXPAND_DIRECTION& expand_direction
00095 , bool& copy_edge_terrain)
00096 : width_(register_integer("width", true, width))
00097 , height_(register_integer("height", true, height))
00098 , old_width_(width)
00099 , old_height_(height)
00100 , expand_direction_(expand_direction)
00101 {
00102 register_bool("copy_edge_terrain", false, copy_edge_terrain);
00103
00104 register_label("old_width", false, str_cast(width));
00105 register_label("old_height", false, str_cast(height));
00106 }
00107
00108 void teditor_resize_map::pre_show(CVideo& , twindow& window)
00109 {
00110 tslider& height = find_widget<tslider>(&window, "height", false);
00111 connect_signal_notify_modified(height
00112 , boost::bind(
00113 &teditor_resize_map::update_expand_direction
00114 , this
00115 , boost::ref(window)));
00116
00117 tslider& width = find_widget<tslider>(&window, "width", false);
00118 connect_signal_notify_modified(width
00119 , boost::bind(
00120 &teditor_resize_map::update_expand_direction
00121 , this
00122 , boost::ref(window)));
00123
00124 std::string name_prefix = "expand";
00125 for (int i = 0; i < 9; ++i) {
00126 std::string name = name_prefix + lexical_cast<std::string>(i);
00127 direction_buttons_[i] = find_widget<ttoggle_button>(
00128 &window, name, false, true);
00129
00130 direction_buttons_[i]->set_callback_state_change(
00131 dialog_callback<teditor_resize_map
00132 , &teditor_resize_map::update_expand_direction>);
00133 }
00134 direction_buttons_[0]->set_value(true);
00135 update_expand_direction(window);
00136 }
00137
00138
00139
00140
00141
00142 static int resize_grid_xy_to_idx(const int x, const int y)
00143 {
00144 if (x < 0 || x > 2 || y < 0 || y > 2) {
00145 return 9;
00146 } else {
00147 return y * 3 + x;
00148 }
00149 }
00150
00151 void teditor_resize_map::set_direction_icon(int index, std::string icon)
00152 {
00153 if (index < 9) {
00154 direction_buttons_[index]->set_icon_name(
00155 "buttons/resize-direction-" + icon + ".png");
00156 }
00157 }
00158
00159 void teditor_resize_map::update_expand_direction(twindow& window)
00160 {
00161 for (int i = 0; i < 9; ++i) {
00162 if (direction_buttons_[i]->get_value()
00163 && static_cast<int>(expand_direction_) != i) {
00164
00165 expand_direction_ = static_cast<EXPAND_DIRECTION>(i);
00166 break;
00167 }
00168 }
00169 for (int i = 0; i < static_cast<int>(expand_direction_); ++i) {
00170 direction_buttons_[i]->set_value(false);
00171 set_direction_icon(i, "none");
00172 }
00173 direction_buttons_[expand_direction_]->set_value(true);
00174 for (int i = expand_direction_ + 1; i < 9; ++i) {
00175 direction_buttons_[i]->set_value(false);
00176 set_direction_icon(i, "none");
00177 }
00178
00179 int xdiff = width_->get_widget_value(window) - old_width_ ;
00180 int ydiff = height_->get_widget_value(window) - old_height_ ;
00181 int x = static_cast<int>(expand_direction_) % 3;
00182 int y = static_cast<int>(expand_direction_) / 3;
00183 set_direction_icon(expand_direction_, "center");
00184 if (xdiff != 0) {
00185 int left = resize_grid_xy_to_idx(x - 1, y);
00186 int right = resize_grid_xy_to_idx(x + 1, y);
00187 if (xdiff < 0) std::swap(left, right);
00188 set_direction_icon(left, "left");
00189 set_direction_icon(right, "right");
00190 }
00191 if (ydiff != 0) {
00192 int top = resize_grid_xy_to_idx(x, y - 1);
00193 int bottom = resize_grid_xy_to_idx(x, y + 1);
00194 if (ydiff < 0) std::swap(top, bottom);
00195 set_direction_icon(top, "top");
00196 set_direction_icon(bottom, "bottom");
00197 }
00198 if (xdiff < 0 || ydiff < 0 || (xdiff > 0 && ydiff > 0)) {
00199 int nw = resize_grid_xy_to_idx(x - 1, y - 1);
00200 int ne = resize_grid_xy_to_idx(x + 1, y - 1);
00201 int sw = resize_grid_xy_to_idx(x - 1, y + 1);
00202 int se = resize_grid_xy_to_idx(x + 1, y + 1);
00203 if (xdiff < 0 || ydiff < 0) {
00204 std::swap(nw, se);
00205 std::swap(ne, sw);
00206 }
00207 set_direction_icon(nw, "top-left");
00208 set_direction_icon(ne, "top-right");
00209 set_direction_icon(sw, "bottom-left");
00210 set_direction_icon(se, "bottom-right");
00211 }
00212 }
00213
00214 }