Add in panning/zooming transformed view controls

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2, Sig, Sigo 9 months ago
parent 6fcb24bda5
commit 6d0aa870c0
  1. 2
      TiledCollisionEditor.js
  2. BIN
      TiledCollisionEditor.wasm
  3. 30
      TiledCollisionEditor/main.cpp

File diff suppressed because one or more lines are too long

Binary file not shown.

@ -18,6 +18,8 @@ class TiledCollisionEditor : public olc::PixelGameEngine
std::string selectedObj=""; std::string selectedObj="";
int editingPoint=4; //Which point we are editing (0-3.) int editingPoint=4; //Which point we are editing (0-3.)
TransformedView view;
public: public:
TiledCollisionEditor() TiledCollisionEditor()
{ {
@ -43,13 +45,15 @@ public:
{ {
Clear(VERY_DARK_BLUE); Clear(VERY_DARK_BLUE);
view.HandlePanAndZoom();
const Tileset&tileset=tilesets[activeTileset]; const Tileset&tileset=tilesets[activeTileset];
DrawDecal({0,0},images[activeTileset].Decal()); view.DrawDecal({0,0},images[activeTileset].Decal());
for(int y=0;y<tileset.tilecount/tileset.columns;y++){ for(int y=0;y<tileset.tilecount/tileset.columns;y++){
for(int x=0;x<tileset.columns;x++){ for(int x=0;x<tileset.columns;x++){
DrawRectDecal(vf2d{float(x),float(y)}*tileset.tilewidth,vf2d{float(tileset.tilewidth),float(tileset.tileheight)},GREY); view.DrawRectDecal(vf2d{float(x),float(y)}*tileset.tilewidth,vf2d{float(tileset.tilewidth),float(tileset.tileheight)},GREY);
} }
} }
@ -58,15 +62,15 @@ public:
} }
for(auto&[objName,obj]:tileset.objects){ for(auto&[objName,obj]:tileset.objects){
FillRectDecal(obj.bounds.pos,vf2d{2.f,float(obj.bounds.size.y)},YELLOW); view.FillRectDecal(obj.bounds.pos,vf2d{2.f,float(obj.bounds.size.y)},YELLOW);
FillRectDecal(obj.bounds.pos,vf2d{float(obj.bounds.size.x),2},YELLOW); view.FillRectDecal(obj.bounds.pos,vf2d{float(obj.bounds.size.x),2},YELLOW);
FillRectDecal(obj.bounds.pos+obj.bounds.size,vf2d{-2.f,-float(obj.bounds.size.y)},YELLOW); view.FillRectDecal(obj.bounds.pos+obj.bounds.size,vf2d{-2.f,-float(obj.bounds.size.y)},YELLOW);
FillRectDecal(obj.bounds.pos+obj.bounds.size,vf2d{-float(obj.bounds.size.x),-2.f},YELLOW); view.FillRectDecal(obj.bounds.pos+obj.bounds.size,vf2d{-float(obj.bounds.size.x),-2.f},YELLOW);
vi2d nameTextSize=GetTextSizeProp(objName)*0.25f; vi2d nameTextSize=GetTextSizeProp(objName)*0.25f;
GradientFillRectDecal(obj.bounds.pos,nameTextSize+vf2d{2,2},RED,{255,0,0,64},{255,0,0,64},RED); view.GradientFillRectDecal(obj.bounds.pos,nameTextSize+vf2d{2,2},RED,{255,0,0,64},{255,0,0,64},RED);
DrawStringPropDecal(obj.bounds.pos+vf2d{1.25f,1.25f},objName,BLACK,vf2d{0.25f,0.25f}); view.DrawStringPropDecal(obj.bounds.pos+vf2d{1.25f,1.25f},objName,BLACK,vf2d{0.25f,0.25f});
DrawStringPropDecal(obj.bounds.pos+vf2d{1,1},objName,WHITE,vf2d{0.25f,0.25f}); view.DrawStringPropDecal(obj.bounds.pos+vf2d{1,1},objName,WHITE,vf2d{0.25f,0.25f});
if(geom2d::contains(obj.bounds,GetMousePos())){ if(geom2d::contains(obj.bounds,GetMousePos())){
selectedObj=objName; selectedObj=objName;
@ -77,7 +81,7 @@ public:
for(int y=0;y<tileset.tilecount/tileset.columns;y++){ for(int y=0;y<tileset.tilecount/tileset.columns;y++){
for(int x=0;x<tileset.columns;x++){ for(int x=0;x<tileset.columns;x++){
if(!geom2d::contains(tileset.objects.at(selectedObj).bounds,vf2d{float(x*tileset.tilewidth)+tileset.tilewidth/2,float(y*tileset.tileheight)+tileset.tileheight/2})){ if(!geom2d::contains(tileset.objects.at(selectedObj).bounds,vf2d{float(x*tileset.tilewidth)+tileset.tilewidth/2,float(y*tileset.tileheight)+tileset.tileheight/2})){
FillRectDecal(vf2d{float(x),float(y)}*tileset.tilewidth,vf2d{float(tileset.tilewidth),float(tileset.tileheight)},{0,0,0,128}); view.FillRectDecal(vf2d{float(x),float(y)}*tileset.tilewidth,vf2d{float(tileset.tilewidth),float(tileset.tileheight)},{0,0,0,128});
} }
} }
} }
@ -86,12 +90,12 @@ public:
const bool EditingQuad=editingPoint<4&&editingQuad!=nullptr; const bool EditingQuad=editingPoint<4&&editingQuad!=nullptr;
if(EditingQuad){ if(EditingQuad){
(*editingQuad)[editingPoint]=GetMousePos(); (*editingQuad)[editingPoint]=view.ScreenToWorld(GetMousePos());
} }
if(GetMouse(Mouse::LEFT).bPressed){ if(GetMouse(Mouse::LEFT).bPressed){
if(EditingQuad){ if(EditingQuad){
(*editingQuad)[editingPoint]=GetMousePos(); (*editingQuad)[editingPoint]=view.ScreenToWorld(GetMousePos());
editingPoint++; editingPoint++;
}else{ }else{
if(obj.collisionTiles.size()==0){ if(obj.collisionTiles.size()==0){
@ -120,7 +124,7 @@ public:
points.assign(quad.begin(),quad.end()); points.assign(quad.begin(),quad.end());
uvs.assign(4,{0.f,0.f}); uvs.assign(4,{0.f,0.f});
cols.assign(4,{255,40,40,128}); cols.assign(4,{255,40,40,128});
DrawPolygonDecal(nullptr,points,uvs,cols); view.DrawPolygonDecal(nullptr,points,uvs,cols);
} }
} }

Loading…
Cancel
Save