Added region highlighting
This commit is contained in:
+24
-21
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ void EditorScene::FrameEnd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EditorScene::Render(SDL_Surface* const screen) {
|
void EditorScene::Render(SDL_Surface* const screen) {
|
||||||
pager.DrawTo(screen, &sheetList, 0, 0);
|
pager.DrawTo(screen, &sheetList, camera.x, camera.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -93,34 +94,36 @@ void EditorScene::Render(SDL_Surface* const screen) {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void EditorScene::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
void EditorScene::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
//
|
if (motion.state & SDL_BUTTON_LMASK) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
else if (motion.state & SDL_BUTTON_RMASK) {
|
||||||
|
camera.x += motion.xrel;
|
||||||
|
camera.y += motion.yrel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorScene::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
void EditorScene::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||||
switch(button.button) {
|
switch(button.button) {
|
||||||
case SDL_BUTTON_LEFT: {
|
case SDL_BUTTON_LEFT: {
|
||||||
Region* ptr = pager.GetRegion(
|
Region* ptr = pager.GetRegion(
|
||||||
snapToBase(pager.GetWidth(), button.x),
|
snapToBase(pager.GetWidth(), button.x - camera.x),
|
||||||
snapToBase(pager.GetHeight(), button.y)
|
snapToBase(pager.GetHeight(), button.y - camera.y)
|
||||||
);
|
);
|
||||||
|
|
||||||
cout << "New Tile: " <<
|
ptr->NewTileA({
|
||||||
ptr->NewTileA({
|
snapToBase(32, button.x - camera.x),
|
||||||
snapToBase(32, button.x),
|
snapToBase(32, button.y - camera.y),
|
||||||
snapToBase(32, button.y),
|
0,
|
||||||
0,
|
32,
|
||||||
32,
|
32,
|
||||||
32,
|
incrementer
|
||||||
incrementer
|
});
|
||||||
})
|
|
||||||
<< endl;
|
|
||||||
;
|
|
||||||
|
|
||||||
if (++incrementer >= TileSheet::GetRangeEnd()) {
|
if (++incrementer >= TileSheet::GetRangeEnd()) {
|
||||||
incrementer = 0;
|
incrementer = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ protected:
|
|||||||
RegionPager pager;
|
RegionPager pager;
|
||||||
std::list<TileSheet> sheetList;
|
std::list<TileSheet> sheetList;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
int x = 0, y = 0;
|
||||||
|
} camera;
|
||||||
|
|
||||||
//debugging
|
//debugging
|
||||||
int incrementer = 0;
|
int incrementer = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
+13
-1
@@ -43,7 +43,12 @@ Region::Region(int _x, int _y, int _w, int _h):
|
|||||||
int Region::NewTileR(Tile const& tile) {
|
int Region::NewTileR(Tile const& tile) {
|
||||||
//return 1 for overwrite, 0 for insert
|
//return 1 for overwrite, 0 for insert
|
||||||
if (!InBoundsR(tile.x, tile.y)) {
|
if (!InBoundsR(tile.x, tile.y)) {
|
||||||
throw(std::runtime_error("New tile location out of bounds"));
|
std::ostringstream os;
|
||||||
|
os << "New tile location out of bounds: " <<
|
||||||
|
"(" << x << "," << y << ")->" <<
|
||||||
|
"(" << tile.x << "," << tile.y << ")"
|
||||||
|
;
|
||||||
|
throw(std::runtime_error(os.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = tiles.erase(tile);
|
int ret = tiles.erase(tile);
|
||||||
@@ -83,6 +88,13 @@ Tile Region::GetTileR(int tx, int ty, int minDepth) {
|
|||||||
int Region::DeleteTileR(Tile const& tile) {
|
int Region::DeleteTileR(Tile const& tile) {
|
||||||
if (!InBoundsR(tile.x, tile.y)) {
|
if (!InBoundsR(tile.x, tile.y)) {
|
||||||
throw(std::runtime_error("Deleted tile location out of bounds"));
|
throw(std::runtime_error("Deleted tile location out of bounds"));
|
||||||
|
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "Deleted tile location out of bounds: " <<
|
||||||
|
"(" << x << "," << y << ")->" <<
|
||||||
|
"(" << tile.x << "," << tile.y << ")"
|
||||||
|
;
|
||||||
|
throw(std::runtime_error(os.str()));
|
||||||
}
|
}
|
||||||
//sentinel/error code
|
//sentinel/error code
|
||||||
if (tile.tileIndex == -1) {
|
if (tile.tileIndex == -1) {
|
||||||
|
|||||||
@@ -85,6 +85,16 @@ void RegionPager::DrawTo(SDL_Surface* const dest, std::list<TileSheet>* const sh
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (auto& regionIter : regionList) {
|
for (auto& regionIter : regionList) {
|
||||||
|
//draw the region's location
|
||||||
|
SDL_Rect box = {
|
||||||
|
Sint16(regionIter.GetX() + camX),
|
||||||
|
Sint16(regionIter.GetY() + camY),
|
||||||
|
Uint16(regionIter.GetWidth()),
|
||||||
|
Uint16(regionIter.GetHeight())
|
||||||
|
};
|
||||||
|
SDL_FillRect(dest, &box, SDL_MapRGB(dest->format, 10, 10, 20));
|
||||||
|
|
||||||
|
//draw each tile
|
||||||
for (auto& tileIter : *regionIter.GetTiles()) {
|
for (auto& tileIter : *regionIter.GetTiles()) {
|
||||||
for (auto& sheetIter : *sheetList) {
|
for (auto& sheetIter : *sheetList) {
|
||||||
if (sheetIter.InRange(tileIter.tileIndex)) {
|
if (sheetIter.InRange(tileIter.tileIndex)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user