Ability to drag windows around.

master
sigonasr2 1 year ago
parent bc55854b83
commit afd1d88d64
  1. 18
      FiestaOnlineEditor/FiestaOnlineEditor.cpp
  2. 4
      FiestaOnlineEditor/ItemEditor.cpp
  3. 1
      FiestaOnlineEditor/ItemEditor.h
  4. 26
      FiestaOnlineEditor/Window.cpp
  5. 5
      FiestaOnlineEditor/Window.h

@ -132,16 +132,34 @@ bool FiestaOnlineEditor::OnUserUpdate(float fElapsedTime){
SetDrawTarget(1);
//BACKGROUND DRAWING
bool internalMouseFocus=false;
for(Window*w:windows){
if(!w->IsFocusedWindow()){
SetDrawTarget(1);
} else {
SetDrawTarget(nullptr);
if(w->IsInBounds(GetMousePos())){
w->InternalMouseFocus(this);
w->MouseFocus(this);
internalMouseFocus=true;
}
}
w->InternalUpdate(this,fElapsedTime);
w->Draw(this);
}
if(!internalMouseFocus){
for(Window*w:windows){ //A second iteration through the windows because windows without focus should only have priority after a window with focus.
if(!w->IsFocusedWindow()){
if(w->IsInBounds(GetMousePos())){
w->InternalMouseFocus(this);
w->MouseFocus(this);
}
}
}
}
SetDrawTarget(nullptr);
//FOREGROUND DRAWING
manager.Draw(sprMenu,{64,64});

@ -33,3 +33,7 @@ void ItemEditor::Update(FiestaOnlineEditor*pge,float fElapsedTime){
void ItemEditor::Refresh(FiestaOnlineEditor*pge){
pge->DrawRect(pos,{16,16},WHITE);
}
void ItemEditor::MouseFocus(FiestaOnlineEditor*pge){
}

@ -13,4 +13,5 @@ public:
void Load(std::string basePath);
void Refresh(FiestaOnlineEditor*pge)override;
void Update(FiestaOnlineEditor*pge,float fElapsedTime)override;
void MouseFocus(FiestaOnlineEditor*pge)override;
};

@ -14,6 +14,9 @@ void Window::InternalUpdate(FiestaOnlineEditor*pge,float fElapsedTime){
if(this==focusedWindow){
Update(pge,fElapsedTime);
}
if(dragging){
pos=pge->GetMousePos()-dragPoint;
}
}
void Window::InternalRefresh(FiestaOnlineEditor*pge){
@ -55,3 +58,26 @@ void Window::Cleanup(){
delete sprWindow;
delete decWindow;
}
bool Window::IsInBounds(vf2d point){
return point.x>=pos.x&&point.x<=pos.x+size.x&&point.y>=pos.y&&point.y<=pos.y+size.y+headerHeight;
}
void Window::InternalMouseFocus(FiestaOnlineEditor*pge){
if(pge->GetMouse(0).bPressed){
if(pge->GetMouseY()<pos.y+headerHeight){
dragging=true;
dragPoint=pge->GetMousePos()-pos;
}
if(focusedWindow!=this){
Window*prevFocusedWindow=focusedWindow;
focusedWindow=this;
InternalRefresh(pge);
prevFocusedWindow->InternalRefresh(pge);
}
}
if(pge->GetMouse(0).bReleased){
dragging=false;
}
}
void Window::MouseFocus(FiestaOnlineEditor*pge){}

@ -8,6 +8,8 @@ private:
vi2d pos;
Decal*decWindow;
const int headerHeight=12;
bool dragging=false;
vf2d dragPoint;
protected:
vi2d size;
Sprite*sprWindow;
@ -22,4 +24,7 @@ public:
void Draw(FiestaOnlineEditor*pge);
bool IsFocusedWindow();
void Cleanup();
bool IsInBounds(vf2d point);
void InternalMouseFocus(FiestaOnlineEditor*pge);
virtual void MouseFocus(FiestaOnlineEditor*pge);
};
Loading…
Cancel
Save