summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-09-02 20:28:41 +0000
committeralberth <alberth@openttd.org>2009-09-02 20:28:41 +0000
commit0847b338c691a825ba05d506a08089c3b9cebe9f (patch)
tree9c4eb2e0f9fd3fd28549c41077169ecef81b0d42
parent4bbb0234639e889e1ba77294f1c538f849a50151 (diff)
downloadopenttd-0847b338c691a825ba05d506a08089c3b9cebe9f.tar.xz
(svn r17389) -Codechange: Add support for shaded viewports.
-rw-r--r--src/widget.cpp17
-rw-r--r--src/widget_type.h18
2 files changed, 29 insertions, 6 deletions
diff --git a/src/widget.cpp b/src/widget.cpp
index 19509e040..77f2da21a 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -10,6 +10,7 @@
/** @file widget.cpp Handling of the default/simple widgets. */
#include "stdafx.h"
+#include "openttd.h"
#include "company_func.h"
#include "gfx_func.h"
#include "window_gui.h"
@@ -17,6 +18,7 @@
#include "zoom_func.h"
#include "debug.h"
#include "strings_func.h"
+#include "transparency.h"
#include "table/sprites.h"
#include "table/strings.h"
@@ -1866,7 +1868,20 @@ void NWidgetViewport::StoreWidgets(Widget *widgets, int length, bool left_moving
void NWidgetViewport::Draw(const Window *w)
{
- w->DrawViewport();
+ if (this->disp_flags & ND_NO_TRANSPARENCY) {
+ TransparencyOptionBits to_backup = _transparency_opt;
+ _transparency_opt = 0; // Disable all transparency
+ w->DrawViewport();
+ _transparency_opt = to_backup;
+ } else {
+ w->DrawViewport();
+ }
+
+ /* Optionally shade the viewport. */
+ if (this->disp_flags & (ND_SHADE_GREY | ND_SHADE_DIMMED)) {
+ GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1,
+ (this->disp_flags & ND_SHADE_DIMMED) ? PALETTE_TO_TRANSPARENT : PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
+ }
}
Scrollbar *NWidgetViewport::FindScrollbar(Window *w, bool allow_next)
diff --git a/src/widget_type.h b/src/widget_type.h
index a7a9812c7..8c07b0b43 100644
--- a/src/widget_type.h
+++ b/src/widget_type.h
@@ -281,11 +281,17 @@ public:
/** Nested widget flags that affect display and interaction withe 'real' widgets. */
enum NWidgetDisplay {
- NDB_LOWERED = 0, ///< Widget is lowered (pressed down) bit.
- NDB_DISABLED = 1, ///< Widget is disabled (greyed out) bit.
-
- ND_LOWERED = 1 << NDB_LOWERED, ///< Bit value of the lowered flag.
- ND_DISABLED = 1 << NDB_DISABLED, ///< Bit value of the disabled flag.
+ NDB_LOWERED = 0, ///< Widget is lowered (pressed down) bit.
+ NDB_DISABLED = 1, ///< Widget is disabled (greyed out) bit.
+ NDB_NO_TRANSPARENCY = 2, ///< Viewport is never transparent.
+ NDB_SHADE_GREY = 3, ///< Shade viewport to grey-scale.
+ NDB_SHADE_DIMMED = 4, ///< Display dimmed colours in the viewport.
+
+ ND_LOWERED = 1 << NDB_LOWERED, ///< Bit value of the lowered flag.
+ ND_DISABLED = 1 << NDB_DISABLED, ///< Bit value of the disabled flag.
+ ND_NO_TRANSPARENCY = 1 << NDB_NO_TRANSPARENCY, ///< Bit value of the 'no transparency' flag.
+ ND_SHADE_GREY = 1 << NDB_SHADE_GREY, ///< Bit value of the 'shade to grey' flag.
+ ND_SHADE_DIMMED = 1 << NDB_SHADE_DIMMED, ///< Bit value of the 'dimmed colours' flag.
};
DECLARE_ENUM_AS_BIT_SET(NWidgetDisplay);
@@ -488,6 +494,8 @@ private:
* Nested widget to display a viewport in a window.
* After initializing the nested widget tree, call #InitializeViewport(). After changing the window size,
* call #UpdateViewportCoordinates() eg from Window::OnResize().
+ * If the #display_flags field contains the #ND_NO_TRANSPARENCY bit, the viewport will disable transparency.
+ * Shading to grey-scale is controlled with the #ND_SHADE_GREY bit (used for B&W news papers), the #ND_SHADE_DIMMED gives dimmed colours (for colour news papers).
* @todo Class derives from #NWidgetCore, but does not use #colour, #widget_data, or #tool_tip.
* @ingroup NestedWidgets */
class NWidgetViewport : public NWidgetCore {