summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/window.cpp64
-rw-r--r--src/window.h152
2 files changed, 216 insertions, 0 deletions
diff --git a/src/window.cpp b/src/window.cpp
index 789ef9603..b12e69b21 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -80,6 +80,70 @@ void RaiseWindowButtons(Window *w)
}
}
+void CDECL Window::SetWidgetsDisabledState(bool disab_stat, int widgets, ...)
+{
+ va_list wdg_list;
+
+ va_start(wdg_list, widgets);
+
+ while (widgets != WIDGET_LIST_END) {
+ SetWidgetDisabledState(widgets, disab_stat);
+ widgets = va_arg(wdg_list, int);
+ }
+
+ va_end(wdg_list);
+}
+
+void CDECL Window::SetWidgetsHiddenState(bool hidden_stat, int widgets, ...)
+{
+ va_list wdg_list;
+
+ va_start(wdg_list, widgets);
+
+ while (widgets != WIDGET_LIST_END) {
+ SetWidgetHiddenState(widgets, hidden_stat);
+ widgets = va_arg(wdg_list, int);
+ }
+
+ va_end(wdg_list);
+}
+
+void CDECL Window::SetWidgetsLoweredState(bool lowered_stat, int widgets, ...)
+{
+ va_list wdg_list;
+
+ va_start(wdg_list, widgets);
+
+ while (widgets != WIDGET_LIST_END) {
+ SetWidgetLoweredState(widgets, lowered_stat);
+ widgets = va_arg(wdg_list, int);
+ }
+
+ va_end(wdg_list);
+}
+
+void Window::RaiseButtons()
+{
+ uint i;
+
+ for (i = 0; i < this->widget_count; i++) {
+ if (IsWidgetLowered(i)) {
+ RaiseWidget(i);
+ InvalidateWidget(i);
+ }
+ }
+}
+
+void Window::InvalidateWidget(byte widget_index)
+{
+ const Widget *wi = &this->widget[widget_index];
+
+ /* Don't redraw the window if the widget is invisible or of no-type */
+ if (wi->type == WWT_EMPTY || IsWidgetHidden(widget_index)) return;
+
+ SetDirtyBlocks(this->left + wi->left, this->top + wi->top, this->left + wi->right + 1, this->top + wi->bottom + 1);
+}
+
void HandleButtonClick(Window *w, byte widget)
{
LowerWindowWidget(w, widget);
diff --git a/src/window.h b/src/window.h
index 9a80c44be..0036f6955 100644
--- a/src/window.h
+++ b/src/window.h
@@ -278,6 +278,26 @@ struct Window {
WindowMessage message;
Window *parent;
byte custom[WINDOW_CUSTOM_SIZE];
+
+ void SetWidgetDisabledState(byte widget_index, bool disab_stat);
+ void DisableWidget(byte widget_index);
+ void EnableWidget(byte widget_index);
+ bool IsWidgetDisabled(byte widget_index);
+ void SetWidgetHiddenState(byte widget_index, bool hidden_stat);
+ void HideWidget(byte widget_index);
+ void ShowWidget(byte widget_index);
+ bool IsWidgetHidden(byte widget_index);
+ void SetWidgetLoweredState(byte widget_index, bool lowered_stat);
+ void ToggleLoweredState(byte widget_index);
+ void LowerWidget(byte widget_index);
+ void RaiseWidget(byte widget_index);
+ bool IsWidgetLowered(byte widget_index);
+
+ void RaiseButtons();
+ void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...);
+ void CDECL SetWidgetsHiddenState(bool hidden_stat, int widgets, ...);
+ void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets, ...);
+ void InvalidateWidget(byte widget_index);
};
struct querystr_d {
@@ -818,4 +838,136 @@ void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y);
*/
void ResizeButtons(Window *w, byte left, byte right);
+
+/**
+ * Sets the enabled/disabled status of a widget.
+ * By default, widgets are enabled.
+ * On certain conditions, they have to be disabled.
+ * @param widget_index : index of this widget in the window
+ * @param disab_stat : status to use ie: disabled = true, enabled = false
+ */
+inline void Window::SetWidgetDisabledState(byte widget_index, bool disab_stat)
+{
+ assert(widget_index < this->widget_count);
+ SB(this->widget[widget_index].display_flags, WIDG_DISABLED, 1, !!disab_stat);
+}
+
+/**
+ * Sets a widget to disabled.
+ * @param widget_index : index of this widget in the window
+ */
+inline void Window::DisableWidget(byte widget_index)
+{
+ SetWidgetDisabledState(widget_index, true);
+}
+
+/**
+ * Sets a widget to Enabled.
+ * @param widget_index : index of this widget in the window
+ */
+inline void Window::EnableWidget(byte widget_index) { SetWidgetDisabledState(widget_index, false); }
+
+/**
+ * Gets the enabled/disabled status of a widget.
+ * @param widget_index : index of this widget in the window
+ * @return status of the widget ie: disabled = true, enabled = false
+ */
+inline bool Window::IsWidgetDisabled(byte widget_index)
+{
+ assert(widget_index < this->widget_count);
+ return HasBit(this->widget[widget_index].display_flags, WIDG_DISABLED);
+}
+
+/**
+ * Sets the hidden/shown status of a widget.
+ * By default, widgets are visible.
+ * On certain conditions, they have to be hidden.
+ * @param widget_index index of this widget in the window
+ * @param hidden_stat status to use ie. hidden = true, visible = false
+ */
+inline void Window::SetWidgetHiddenState(byte widget_index, bool hidden_stat)
+{
+ assert(widget_index < this->widget_count);
+ SB(this->widget[widget_index].display_flags, WIDG_HIDDEN, 1, !!hidden_stat);
+}
+
+/**
+ * Sets a widget hidden.
+ * @param widget_index : index of this widget in the window
+ */
+inline void Window::HideWidget(byte widget_index)
+{
+ SetWidgetHiddenState(widget_index, true);
+}
+
+/**
+ * Sets a widget visible.
+ * @param widget_index : index of this widget in the window
+ */
+inline void Window::ShowWidget(byte widget_index)
+{
+ SetWidgetHiddenState(widget_index, false);
+}
+
+/**
+ * Gets the visibility of a widget.
+ * @param widget_index : index of this widget in the window
+ * @return status of the widget ie: hidden = true, visible = false
+ */
+inline bool Window::IsWidgetHidden(byte widget_index)
+{
+ assert(widget_index < this->widget_count);
+ return HasBit(this->widget[widget_index].display_flags, WIDG_HIDDEN);
+}
+
+/**
+ * Sets the lowered/raised status of a widget.
+ * @param widget_index : index of this widget in the window
+ * @param lowered_stat : status to use ie: lowered = true, raised = false
+ */
+inline void Window::SetWidgetLoweredState(byte widget_index, bool lowered_stat)
+{
+ assert(widget_index < this->widget_count);
+ SB(this->widget[widget_index].display_flags, WIDG_LOWERED, 1, !!lowered_stat);
+}
+
+/**
+ * Invert the lowered/raised status of a widget.
+ * @param widget_index : index of this widget in the window
+ */
+inline void Window::ToggleLoweredState(byte widget_index)
+{
+ assert(widget_index < this->widget_count);
+ ToggleBit(this->widget[widget_index].display_flags, WIDG_LOWERED);
+}
+
+/**
+ * Marks a widget as lowered.
+ * @param widget_index : index of this widget in the window
+ */
+inline void Window::LowerWidget(byte widget_index)
+{
+ SetWidgetLoweredState(widget_index, true);
+}
+
+/**
+ * Marks a widget as raised.
+ * @param widget_index : index of this widget in the window
+ */
+inline void Window::RaiseWidget(byte widget_index)
+{
+ SetWidgetLoweredState(widget_index, false);
+}
+
+/**
+ * Gets the lowered state of a widget.
+ * @param widget_index : index of this widget in the window
+ * @return status of the widget ie: lowered = true, raised= false
+ */
+inline bool Window::IsWidgetLowered(byte widget_index)
+{
+ assert(widget_index < this->widget_count);
+ return HasBit(this->widget[widget_index].display_flags, WIDG_LOWERED);
+}
+
#endif /* WINDOW_H */