12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- --[[
- @classmod Grid
- ]]
- return pl.class {
- _name = "Grid",
- _init = function (self, s, w, h)
- self.show = true
- self.sz = s
- self.x, self.y = 0, 0
- self.selection = {}
- self.w, self.h = w, h
- self.show_coords = false
- end,
-
- reset = function (self)
- self.sz = Sled.tile_size
- self.x, self.y = 0, 0
- end,
-
- snap = function (self, x, y)
- return math.floor(x/self.sz)*self.sz, y and math.floor(y/self.sz)*self.sz
- end,
-
- highlight = function (self, x, y, c)
- self.selection_color = c or {1, 1, 1}
- local tx, ty = self:snap(x, y)
- self.tx, self.ty = tx, ty
- end,
-
- get_highlighted_tile_pos = function (self)
- return self.tx, self.ty
- end,
-
- update = function (self)
- if not Cursor then return end
- end,
-
- draw_coordinates = function (self)
- if not self.show_coords then return end
- local tx, ty = self.tx, self.ty
- local w, h = self.w, self.h
- _lg.setLineWidth(.1)
- _lg.setColor(.1, .1, .1, 1)
- _lg.line(tx, self.x, tx, ty)
- _lg.line(tx, ty, self.x, ty)
-
- end,
-
- resize = function (self, w, h)
- self.w, self.h = w, h
- end,
-
- move = function (self, x, y)
- self.x, self.y = x, y
- end,
-
- draw = function (self)
- if self.show then
- local w, h = self.w, self.h
- _lg.setColor(.2, .2, .2, .5)
- _lg.setLineWidth(.1)
- for y = self.y, self.y + h, self.sz do
- _lg.line(self.x, y, self.x + w, y)
- end
- for x = self.x, self.x + w, self.sz do
- _lg.line(x, self.y, x, self.y + h)
- end
- end
- if self.tx and self.ty then
- self:draw_coordinates ()
- _lg.setColor(.5, .5, .5)
- _lg.rectangle("line", self.tx, self.ty, Sled.tile_size, Sled.tile_size)
-
- end
- end
- }
|