aboutsummaryrefslogtreecommitdiffstats
path: root/src/menu
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-03-22 16:34:49 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:51 +0100
commit4f31d71c8164a84a45aa1e2408e0e2cb54ff30bb (patch)
tree4847572741b88e33251a9fcc1d2c5da1a6462560 /src/menu
parentbbdbced8470bc374e79a5d5914291f8ff7dc3dc3 (diff)
downloadusdx-4f31d71c8164a84a45aa1e2408e0e2cb54ff30bb.tar.gz
usdx-4f31d71c8164a84a45aa1e2408e0e2cb54ff30bb.tar.xz
usdx-4f31d71c8164a84a45aa1e2408e0e2cb54ff30bb.zip
menu/clipping_helper: helper class for stacked clipping setup and teardown
Diffstat (limited to 'src/menu')
-rw-r--r--src/menu/clipping_helper.cpp70
-rw-r--r--src/menu/clipping_helper.hpp51
2 files changed, 121 insertions, 0 deletions
diff --git a/src/menu/clipping_helper.cpp b/src/menu/clipping_helper.cpp
new file mode 100644
index 00000000..b03a4e8c
--- /dev/null
+++ b/src/menu/clipping_helper.cpp
@@ -0,0 +1,70 @@
+/*
+ * UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#include "clipping_helper.hpp"
+
+namespace usdx
+{
+ log4cpp::Category& ClippingHelper::log =
+ log4cpp::Category::getInstance("usdx.menu.clipping_helper");
+
+ ClippingHelper::ClippingHelper(const Rectangle<int> &rect)
+ {
+ was_enabled = glIsEnabled(GL_SCISSOR_TEST);
+
+ // calculate intersection of old clipping and requested clipping
+ Rectangle<int> new_scissor_box(rect);
+
+ if (was_enabled) {
+ glGetIntegerv(GL_SCISSOR_BOX, scissor_box);
+ new_scissor_box = rect.intersect(Rectangle<int>(scissor_box));
+ }
+
+ log << log4cpp::Priority::DEBUG << "Clipping ("
+ << new_scissor_box.get_width() << ", "
+ << new_scissor_box.get_height() << ") at window offset: ("
+ << new_scissor_box.get_x() << ", "
+ << new_scissor_box.get_y() << ")";
+
+ // setup clipping box
+ glScissor(new_scissor_box.get_x(), new_scissor_box.get_y(),
+ new_scissor_box.get_width(), new_scissor_box.get_height());
+
+ // enable clipping
+ glEnable(GL_SCISSOR_TEST);
+ }
+
+ ClippingHelper::~ClippingHelper()
+ {
+ // restore old clipping settings
+ glScissor(scissor_box[0], scissor_box[1], scissor_box[2],
+ scissor_box[3]);
+
+ if (! was_enabled) {
+ glDisable(GL_SCISSOR_TEST);
+ }
+ }
+};
diff --git a/src/menu/clipping_helper.hpp b/src/menu/clipping_helper.hpp
new file mode 100644
index 00000000..119cc3c2
--- /dev/null
+++ b/src/menu/clipping_helper.hpp
@@ -0,0 +1,51 @@
+/*
+ * UltraStar Deluxe - Karaoke Game
+ *
+ * UltraStar Deluxe is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef CLIPPING_HELPER_HPP
+#define CLIPPING_HELPER_HPP
+
+#include <GL/gl.h>
+#include <log4cpp/Category.hh>
+
+#include "utils/rectangle.hpp"
+
+namespace usdx
+{
+ class ClippingHelper
+ {
+ private:
+ static log4cpp::Category& log;
+
+ GLboolean was_enabled;
+ GLint scissor_box[4];
+
+ public:
+ ClippingHelper(const Rectangle<int>&);
+ virtual ~ClippingHelper();
+ };
+};
+
+#endif