MCPcopy Create free account
hub / github.com/DFHack/dfhack / get_pen

Function get_pen

plugins/design.cpp:157–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157void get_pen(Screen::Pen * tile_pen, int * highlight_tile,
158 int x, int y, ShapeMap &arr, const std::string &type = "")
159{
160 bool n = false, w = false, e = false, s = false;
161 if (has_point(x, y)) {
162 if (y == 0 || !has_point(x, y - 1)) n = true;
163 if (x == 0 || !has_point(x - 1, y)) w = true;
164 if (!has_point(x + 1, y)) e = true; // TODO check map size
165 if (!has_point(x, y + 1)) s = true; // TODO check map size
166 }
167
168 bool is_drag_point = type == "drag_point";
169 bool is_extra = type == "extra_point";
170 bool is_in_shape = has_point(x, y);
171 auto mouse_pos = Gui::getMousePos();
172 bool mouse_over = mouse_pos.x == x && mouse_pos.y == y;
173
174 uint32_t pen_key = gen_pen_key(n, s, e, w, is_drag_point, mouse_over,
175 is_in_shape, is_extra);
176
177 if (CURSORS_MAP.count({n, w, e, s}) > 0 && has_point(x, y)) {
178 arr[x][y].cursor_coords = CURSORS_MAP.at({n, w, e, s});
179 }
180
181 if (PENS.find(pen_key) == PENS.end()) {
182 std::pair<int, int> cursor{-1, -1};
183
184 if (type != "") {
185 *tile_pen = make_pen(CURSORS_MAP.at({n, w, e, s}), is_drag_point,
186 mouse_over, is_in_shape, is_extra);
187 if (highlight_tile)
188 *highlight_tile = mouse_over ? point_hover_highlight_tile : point_highlight_tile;
189 return;
190 }
191
192 if (CURSORS_MAP.count({n, w, e, s}) > 0) {
193 PENS.emplace(pen_key,
194 make_pen(CURSORS_MAP.at({n, w, e, s}), is_drag_point,
195 mouse_over, is_in_shape, is_extra));
196 if (type == "" && has_point(x, y)) {
197 arr[x][y].penKey = pen_key;
198 }
199 }
200 }
201
202 *tile_pen = PENS.at(pen_key);
203}
204
205static int design_load_shape(lua_State *L) {
206 if (lua_istable(L, -1)) {

Callers 2

design_draw_shapeFunction · 0.85
design_draw_pointsFunction · 0.85

Calls 6

has_pointFunction · 0.85
gen_pen_keyFunction · 0.85
make_penFunction · 0.85
countMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected