Update to 12.0-beta1
This commit is contained in:
+85
-28
@@ -10,6 +10,8 @@
|
||||
#ifndef WINDOW_GUI_H
|
||||
#define WINDOW_GUI_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "vehicle_type.h"
|
||||
#include "viewport_type.h"
|
||||
#include "company_type.h"
|
||||
@@ -140,11 +142,11 @@ enum WidgetDrawDistances {
|
||||
|
||||
/* widget.cpp */
|
||||
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags);
|
||||
void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str);
|
||||
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align);
|
||||
|
||||
/* window.cpp */
|
||||
extern Window *_z_front_window;
|
||||
extern Window *_z_back_window;
|
||||
using WindowList = std::list<Window *>;
|
||||
extern WindowList _z_windows;
|
||||
extern Window *_focused_window;
|
||||
|
||||
|
||||
@@ -275,6 +277,9 @@ enum TooltipCloseCondition {
|
||||
* Data structure for an opened window
|
||||
*/
|
||||
struct Window : ZeroedMemoryAllocator {
|
||||
private:
|
||||
static std::vector<Window *> closed_windows;
|
||||
|
||||
protected:
|
||||
void InitializeData(WindowNumber window_number);
|
||||
void InitializePositionSize(int x, int y, int min_width, int min_height);
|
||||
@@ -282,30 +287,19 @@ protected:
|
||||
|
||||
std::vector<int> scheduled_invalidation_data; ///< Data of scheduled OnInvalidateData() calls.
|
||||
|
||||
/* Protected to prevent deletion anywhere outside Window::DeleteClosedWindows(). */
|
||||
virtual ~Window();
|
||||
|
||||
public:
|
||||
Window(WindowDesc *desc);
|
||||
|
||||
virtual ~Window();
|
||||
|
||||
/**
|
||||
* Helper allocation function to disallow something.
|
||||
* Don't allow arrays; arrays of Windows are pointless as you need
|
||||
* to destruct them all at the same time too, which is kinda hard.
|
||||
* @param size the amount of space not to allocate
|
||||
*/
|
||||
inline void *operator new[](size_t size)
|
||||
{
|
||||
NOT_REACHED();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper allocation function to disallow something.
|
||||
* Don't free the window directly; it corrupts the linked list when iterating
|
||||
* @param ptr the pointer not to free
|
||||
*/
|
||||
inline void operator delete(void *ptr)
|
||||
{
|
||||
}
|
||||
inline void *operator new[](size_t size) = delete;
|
||||
|
||||
WindowDesc *window_desc; ///< Window description
|
||||
WindowFlags flags; ///< Window flags
|
||||
@@ -336,8 +330,7 @@ public:
|
||||
int mouse_capture_widget; ///< Widgetindex of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse capture.
|
||||
|
||||
Window *parent; ///< Parent window.
|
||||
Window *z_front; ///< The window in front of us in z-order.
|
||||
Window *z_back; ///< The window behind us in z-order.
|
||||
WindowList::iterator z_position;
|
||||
|
||||
template <class NWID>
|
||||
inline const NWID *GetWidget(uint widnum) const;
|
||||
@@ -516,7 +509,9 @@ public:
|
||||
void DrawSortButtonState(int widget, SortButtonState state) const;
|
||||
static int SortButtonWidth();
|
||||
|
||||
void DeleteChildWindows(WindowClass wc = WC_INVALID) const;
|
||||
void CloseChildWindows(WindowClass wc = WC_INVALID) const;
|
||||
virtual void Close();
|
||||
static void DeleteClosedWindows();
|
||||
|
||||
void SetDirty() const;
|
||||
void ReInit(int rx = 0, int ry = 0);
|
||||
@@ -810,6 +805,74 @@ public:
|
||||
* @pre this->IsNewGRFInspectable()
|
||||
*/
|
||||
virtual void ShowNewGRFInspectWindow() const { NOT_REACHED(); }
|
||||
|
||||
/**
|
||||
* Iterator to iterate all valid Windows
|
||||
* @tparam TtoBack whether we iterate towards the back.
|
||||
*/
|
||||
template <bool TtoBack>
|
||||
struct WindowIterator {
|
||||
typedef Window *value_type;
|
||||
typedef value_type *pointer;
|
||||
typedef value_type &reference;
|
||||
typedef size_t difference_type;
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
|
||||
explicit WindowIterator(WindowList::iterator start) : it(start)
|
||||
{
|
||||
this->Validate();
|
||||
}
|
||||
explicit WindowIterator(const Window *w) : it(w->z_position) {}
|
||||
|
||||
bool operator==(const WindowIterator &other) const { return this->it == other.it; }
|
||||
bool operator!=(const WindowIterator &other) const { return !(*this == other); }
|
||||
Window * operator*() const { return *this->it; }
|
||||
WindowIterator & operator++() { this->Next(); this->Validate(); return *this; }
|
||||
|
||||
bool IsEnd() const { return this->it == _z_windows.end(); }
|
||||
|
||||
private:
|
||||
WindowList::iterator it;
|
||||
void Validate()
|
||||
{
|
||||
while (!this->IsEnd() && *this->it == nullptr) this->Next();
|
||||
}
|
||||
void Next()
|
||||
{
|
||||
if constexpr (!TtoBack) {
|
||||
++this->it;
|
||||
} else if (this->it == _z_windows.begin()) {
|
||||
this->it = _z_windows.end();
|
||||
} else {
|
||||
--this->it;
|
||||
}
|
||||
}
|
||||
};
|
||||
using IteratorToFront = WindowIterator<false>; //!< Iterate in Z order towards front.
|
||||
using IteratorToBack = WindowIterator<true>; //!< Iterate in Z order towards back.
|
||||
|
||||
/**
|
||||
* Iterable ensemble of all valid Windows
|
||||
* @tparam Tfront Wether we iterate from front
|
||||
*/
|
||||
template <bool Tfront>
|
||||
struct AllWindows {
|
||||
AllWindows() {}
|
||||
WindowIterator<Tfront> begin()
|
||||
{
|
||||
if constexpr (Tfront) {
|
||||
auto back = _z_windows.end();
|
||||
if (back != _z_windows.begin()) --back;
|
||||
return WindowIterator<Tfront>(back);
|
||||
} else {
|
||||
return WindowIterator<Tfront>(_z_windows.begin());
|
||||
}
|
||||
}
|
||||
WindowIterator<Tfront> end() { return WindowIterator<Tfront>(_z_windows.end()); }
|
||||
};
|
||||
using Iterate = AllWindows<false>; //!< Iterate all windows in whatever order is easiest.
|
||||
using IterateFromBack = AllWindows<false>; //!< Iterate all windows in Z order from back to front.
|
||||
using IterateFromFront = AllWindows<true>; //!< Iterate all windows in Z order from front to back.
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -859,7 +922,7 @@ public:
|
||||
this->parent = parent;
|
||||
}
|
||||
|
||||
virtual ~PickerWindowBase();
|
||||
void Close() override;
|
||||
};
|
||||
|
||||
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
|
||||
@@ -888,12 +951,6 @@ void GuiShowTooltips(Window *parent, StringID str, uint paramcount = 0, const ui
|
||||
/* widget.cpp */
|
||||
int GetWidgetFromPos(const Window *w, int x, int y);
|
||||
|
||||
/** Iterate over all windows */
|
||||
#define FOR_ALL_WINDOWS_FROM_BACK_FROM(w, start) for (w = start; w != nullptr; w = w->z_front) if (w->window_class != WC_INVALID)
|
||||
#define FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, start) for (w = start; w != nullptr; w = w->z_back) if (w->window_class != WC_INVALID)
|
||||
#define FOR_ALL_WINDOWS_FROM_BACK(w) FOR_ALL_WINDOWS_FROM_BACK_FROM(w, _z_back_window)
|
||||
#define FOR_ALL_WINDOWS_FROM_FRONT(w) FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, _z_front_window)
|
||||
|
||||
extern Point _cursorpos_drag_start;
|
||||
|
||||
extern int _scrollbar_start_pos;
|
||||
|
||||
Reference in New Issue
Block a user