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); SetDrawTarget(1);
//BACKGROUND DRAWING //BACKGROUND DRAWING
bool internalMouseFocus=false;
for(Window*w:windows){ for(Window*w:windows){
if(!w->IsFocusedWindow()){ if(!w->IsFocusedWindow()){
SetDrawTarget(1); SetDrawTarget(1);
} else { } else {
SetDrawTarget(nullptr); SetDrawTarget(nullptr);
if(w->IsInBounds(GetMousePos())){
w->InternalMouseFocus(this);
w->MouseFocus(this);
internalMouseFocus=true;
}
} }
w->InternalUpdate(this,fElapsedTime); w->InternalUpdate(this,fElapsedTime);
w->Draw(this); 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); SetDrawTarget(nullptr);
//FOREGROUND DRAWING //FOREGROUND DRAWING
manager.Draw(sprMenu,{64,64}); manager.Draw(sprMenu,{64,64});

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

@ -13,4 +13,5 @@ public:
void Load(std::string basePath); void Load(std::string basePath);
void Refresh(FiestaOnlineEditor*pge)override; void Refresh(FiestaOnlineEditor*pge)override;
void Update(FiestaOnlineEditor*pge,float fElapsedTime)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){ if(this==focusedWindow){
Update(pge,fElapsedTime); Update(pge,fElapsedTime);
} }
if(dragging){
pos=pge->GetMousePos()-dragPoint;
}
} }
void Window::InternalRefresh(FiestaOnlineEditor*pge){ void Window::InternalRefresh(FiestaOnlineEditor*pge){
@ -55,3 +58,26 @@ void Window::Cleanup(){
delete sprWindow; delete sprWindow;
delete decWindow; 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; vi2d pos;
Decal*decWindow; Decal*decWindow;
const int headerHeight=12; const int headerHeight=12;
bool dragging=false;
vf2d dragPoint;
protected: protected:
vi2d size; vi2d size;
Sprite*sprWindow; Sprite*sprWindow;
@ -22,4 +24,7 @@ public:
void Draw(FiestaOnlineEditor*pge); void Draw(FiestaOnlineEditor*pge);
bool IsFocusedWindow(); bool IsFocusedWindow();
void Cleanup(); void Cleanup();
bool IsInBounds(vf2d point);
void InternalMouseFocus(FiestaOnlineEditor*pge);
virtual void MouseFocus(FiestaOnlineEditor*pge);
}; };
Loading…
Cancel
Save