Add in some radius to the mouse cursor when comparing to quad overlapping for hovering.

master
sigonasr2 9 months ago
parent e1773faaf4
commit 2fe116efa7
  1. 1
      TiledCollisionEditor/TiledCollisionEditor.vcxproj
  2. 87
      TiledCollisionEditor/main.cpp

@ -119,6 +119,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

@ -40,8 +40,8 @@ public:
Manager gui;
ImageCheckBox*createNewButton;
ImageCheckBox*editButton;
ImageCheckBox*createNewButton=nullptr;
ImageCheckBox*editButton=nullptr;
public:
bool OnUserCreate() override
@ -73,13 +73,6 @@ public:
return true;
}
float hundredsDigit=0.f;
float tensDigit=0.f;
float onesDigit=0.f;
float currentHealth=0;
float targetHealth=60;
void Update(){
const Tileset&tileset=tilesets[activeTileset];
@ -145,7 +138,7 @@ public:
geom2d::triangle<float>{quad[0],quad[2],quad[3]},
};
for(geom2d::triangle<float>&tri:collisionTris){
if(geom2d::contains(tri,view.ScreenToWorld(GetMousePos()))){
if(geom2d::overlaps(tri,geom2d::circle<float>(view.ScreenToWorld(GetMousePos()),3.f))){
dragTranslate=true;
editingQuad=const_cast<Quadrilateral*>(&quad);
upperLeftDragOffset=GetSnapPoint()-quad[0];
@ -188,7 +181,7 @@ public:
geom2d::triangle<float>{quad[0],quad[2],quad[3]},
};
for(geom2d::triangle<float>&tri:collisionTris){
if(geom2d::contains(tri,view.ScreenToWorld(GetMousePos()))){
if(geom2d::overlaps(tri,geom2d::circle<float>(view.ScreenToWorld(GetMousePos()),3.f))){
//Delete this quad, the mouse is overlapping it!
quadsToBeRemoved.push_back(const_cast<Quadrilateral*>(&quad));
break;
@ -215,25 +208,50 @@ public:
editingPoint=4;
}
dragTranslate=false;
editingQuad=nullptr;
}
}
}
void NewObjectUpdate(){
const Tileset&tileset=tilesets[activeTileset];
if(GetMouse(Mouse::LEFT).bPressed){
const Tileset&tileset=tilesets[activeTileset];
vf2d worldCoords=view.ScreenToWorld(GetMousePos());
upperLeftObjTile=vf2d{round(worldCoords.x/tileset.tilewidth)*tileset.tilewidth,round(worldCoords.y/tileset.tileheight)*tileset.tileheight};
upperLeftObjTile=vi2d{int(round(worldCoords.x/tileset.tilewidth)*tileset.tilewidth),int(round(worldCoords.y/tileset.tileheight)*tileset.tileheight)};
dragNewObj=true;
}
if(GetMouse(Mouse::LEFT).bReleased){
dragNewObj=false;
vf2d worldCoords=view.ScreenToWorld(GetMousePos());
vi2d lowerRightObjTile=vi2d{int(round(worldCoords.x/tileset.tilewidth)*tileset.tilewidth),int(round(worldCoords.y/tileset.tileheight)*tileset.tileheight)};
geom2d::rect<int>newObjRect{upperLeftObjTile,lowerRightObjTile-upperLeftObjTile};
const Tileset&tileset=tilesets[activeTileset];
//Check for intersection with other objects, if found then we deny creating this object this way.
bool intersectionFound=false;
for(auto&[name,obj]:tileset.objects){
geom2d::rect<float>offsetBounds{obj.bounds.pos+vf2d{0.5f,0.5f},obj.bounds.size-vf2d{1.f,1.f}};
if(geom2d::overlaps(offsetBounds,newObjRect)){
intersectionFound=true;
break;
}
}
if(!intersectionFound){
std::string objName=std::format("Object{}",tilesets[activeTileset].objects.size());
TilesetObject&newObj=tilesets[activeTileset].objects[objName];
newObj.name=objName;
for(int y=0;y<newObjRect.size.y;y++){
for(int x=0;x<newObjRect.size.x;x++){
int tileX=upperLeftObjTile.x/tileset.tilewidth+x;
int tileY=upperLeftObjTile.y/tileset.tileheight+y;
int tileID=tileY*tileset.columns+tileX;
newObj.AddTile(tileset,tileID);
}
}
}
}
}
@ -261,7 +279,13 @@ public:
}
if(editingQuad==nullptr){
std::string selectedObj="";
selectedObj="";
for(auto&[objName,obj]:tileset.objects){
if(geom2d::contains(obj.bounds,view.ScreenToWorld(GetMousePos()))){
selectedObj=objName;
break;
}
}
}
if(createNewButton->bPressed)editButton->bChecked=false;
@ -291,7 +315,7 @@ public:
geom2d::triangle<float>{quad[0],quad[2],quad[3]},
};
for(geom2d::triangle<float>&tri:collisionTris){
if(geom2d::contains(tri,view.ScreenToWorld(GetMousePos()))){
if(geom2d::overlaps(tri,geom2d::circle<float>(view.ScreenToWorld(GetMousePos()),3.f))){
highlightedQuad=const_cast<Quadrilateral*>(&quad);
goto renderQuads;
}
@ -308,17 +332,36 @@ public:
view.DrawPolygonDecal(nullptr,points,uvs,cols);
for(bool highlighted=false;const vf2d&point:quad){
if(geom2d::line<float>(point,view.ScreenToWorld(GetMousePos())).length()<4&&!highlighted){
view.DrawRotatedDecal(point,circle.Decal(),0.f,circle.Sprite()->Size()/2,{1.f,1.f},YELLOW);
highlighted=true;
if(highlightedQuad==&quad){
if(geom2d::line<float>(point,view.ScreenToWorld(GetMousePos())).length()<4&&!highlighted){
view.DrawRotatedDecal(point,circle.Decal(),0.f,circle.Sprite()->Size()/2,{1.f,1.f},YELLOW);
highlighted=true;
}else{
view.DrawRotatedDecal(point,circle.Decal(),0.f,circle.Sprite()->Size()/2,{1.f,1.f},RED);
}
}else{
view.DrawRotatedDecal(point,circle.Decal(),0.f,circle.Sprite()->Size()/2,{1.f,1.f},RED);
view.DrawRotatedDecal(point,circle.Decal(),0.f,circle.Sprite()->Size()/2,{0.25f,0.25f},DARK_GREY);
}
}
}
}else
if(dragNewObj){
vf2d worldCoords=view.ScreenToWorld(GetMousePos());
vi2d lowerRightObjTile=vi2d{int(round(worldCoords.x/tileset.tilewidth)*tileset.tilewidth),int(round(worldCoords.y/tileset.tileheight)*tileset.tileheight)};
Pixel overlayCol={0,0,255,160};
geom2d::rect<int>newObjRect{upperLeftObjTile,lowerRightObjTile-upperLeftObjTile};
for(auto&[name,obj]:tileset.objects){
geom2d::rect<float>offsetBounds{obj.bounds.pos+vf2d{0.5f,0.5f},obj.bounds.size-vf2d{1.f,1.f}};
if(geom2d::overlaps(offsetBounds,newObjRect)){
overlayCol={255,0,0,160};
break;
}
}
view.FillRectDecal(upperLeftObjTile,lowerRightObjTile-upperLeftObjTile,overlayCol);
}
for(auto&[objName,obj]:tileset.objects){

Loading…
Cancel
Save