[Aptitude-svn-commit] r3267 - in branches/aptitude-0.3/aptitude: . src/vscreen/config
Daniel Burrows
dburrows@costa.debian.org
Sat, 07 May 2005 15:38:56 +0000
Author: dburrows
Date: Sat May 7 15:38:53 2005
New Revision: 3267
Added:
branches/aptitude-0.3/aptitude/src/vscreen/config/style.cc
branches/aptitude-0.3/aptitude/src/vscreen/config/style.h
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/config/Makefile.am
Log:
Add basic support for styles.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Sat May 7 15:38:53 2005
@@ -1,3 +1,10 @@
+2005-05-07 Daniel Burrows <dburrows@debian.org>
+
+ * src/vscreen/config/Makefile.am, src/vscreen/config/styles.cc, src/vscreen/config/styles.h:
+
+ Add basic support for styles that allow you to override the
+ surrounding character attributes orthogonally.
+
2005-05-05 Daniel Burrows <dburrows@debian.org>
* src/main.cc:
Modified: branches/aptitude-0.3/aptitude/src/vscreen/config/Makefile.am
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/config/Makefile.am (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/config/Makefile.am Sat May 7 15:38:53 2005
@@ -13,4 +13,6 @@
column_definition.h\
column_definition.cc\
keybindings.h \
- keybindings.cc
+ keybindings.cc \
+ style.h \
+ style.cc
Added: branches/aptitude-0.3/aptitude/src/vscreen/config/style.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/vscreen/config/style.cc Sat May 7 15:38:53 2005
@@ -0,0 +1,37 @@
+// style.cc
+//
+// Copyright (C) 2005 Daniel Burrows
+//
+// 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., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+#include "style.h"
+
+// Be lazy, use the standard map.
+#include <map>
+
+using namespace std;
+
+map<string, style> styles;
+
+const style &get_style(const std::string &name)
+{
+ return styles[name];
+}
+
+void set_style(const std::string &name, const style &style)
+{
+ styles[name]=style;
+}
Added: branches/aptitude-0.3/aptitude/src/vscreen/config/style.h
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/vscreen/config/style.h Sat May 7 15:38:53 2005
@@ -0,0 +1,156 @@
+// style.h -*-c++-*-
+//
+// Copyright (C) 2005 Daniel Burrows
+//
+// 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., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+#ifndef STYLE_H
+#define STYLE_H
+
+#include <ncursesw/curses.h>
+
+#include <string>
+
+/** A "style" is a setting to be applied to a display element (widget,
+ * text, etc). This means color (foreground and background) and
+ * attributes. A style may contain settings for any or all of these;
+ * settings which are unspecified are taken from the context in which
+ * the display element occurs. For instance, the "button
+ * highlighted" style might simply toggle the REVERSE flag.
+ *
+ * The interface of styles is high-level: each style is viewed as a
+ * function that applies to the current text attributes; you can also
+ * extract the style's "current" state in order to merge it with a
+ * cchar (this is the style applied to the "null" or default style).
+ * However, as there are only a relatively limited number of things
+ * each style can change, the representation doesn't rely on virtual
+ * functions or even on keeping an array of operations to be applied;
+ * instead, it just keeps a summary of the operations it represents.
+ */
+class style
+{
+ /** The foreground color to be used. (if negative, no change) */
+ short fg;
+ /** The background color to be used. (if negative, no change) */
+ short bg;
+
+ /** Attributes to set. */
+ attr_t set_attrs;
+ /** Attributes to clear. */
+ attr_t clear_attrs;
+ /** Attributes to flip. These are always applied after set_attrs
+ * and clear_attrs.
+ */
+ attr_t flip_attrs;
+
+ // Note: it is assumed that set_attrs and clear_attrs are pairwise
+ // disjoint.
+
+public:
+ /** Initialize an "empty" style. */
+ style():fg(-1), bg(-1), set_attrs(0), clear_attrs(0), flip_attrs(0)
+ {
+ }
+
+ /** Set the foreground color. There is no change if the
+ * new foreground color is "empty".
+ */
+ void set_fg(short _fg) {if(fg>=0) fg=_fg;}
+
+ /** Set the background color. There is no change if the
+ * new background color is "empty".
+ */
+ void set_bg(short _bg) {if(bg>=0) bg=_bg;}
+
+ /** Set the given attribute(s). */
+ void attrs_on(attr_t attrs)
+ {
+ set_attrs|=attrs;
+ clear_attrs&=~attrs;
+ flip_attrs&=~attrs;
+ }
+
+ /** Clear the given attribute(s). */
+ void attrs_off(attr_t attrs)
+ {
+ clear_attrs|=attrs;
+ set_attrs&=~attrs;
+ flip_attrs&=~attrs;
+ }
+
+ /** Flip the given attribute(s). */
+ void attrs_flip(attr_t attrs)
+ {
+ flip_attrs^=attrs;
+ }
+
+ /** Update this style by applying the settings in the other
+ * style.
+ */
+ void apply_style(const style &other)
+ {
+ set_fg(other.fg);
+ set_bg(other.bg);
+ attrs_on(other.set_attrs);
+ attrs_off(other.clear_attrs);
+ attrs_flip(other.flip_attrs);
+ }
+
+ /** \return a new style formed by composing this style with other.
+ * Note that this is a noncommutative operator!
+ */
+ style operator+(const style &other)
+ {
+ style rval;
+ rval.apply_style(other);
+ return rval;
+ }
+
+ /** Shorthand for apply_style. */
+ style &operator+=(const style &other)
+ {
+ apply_style(other);
+ return *this;
+ }
+
+ /** \return the foreground color. */
+ short get_fg() const {return fg<0?0:fg;}
+ /** \return the background color. */
+ short get_bg() const {return bg<0?0:bg;}
+ /** \return the current attributes. */
+ attr_t get_attrs() const
+ {
+ attr_t rval=0;
+ rval|=set_attrs;
+ rval&=~clear_attrs;
+ rval^=flip_attrs;
+ return rval;
+ }
+};
+
+/** Look up a style in the global registry. If there is no style
+ * registered by this name, returns the empty style.
+ *
+ * WARNING: the current implementation will allocate entries in the
+ * style table if you pass an unregistered name. You probably don't
+ * want to do this unless you intend to eventually register it!
+ */
+const style &get_style(const std::string &name);
+
+/** Place a style in the global registry. */
+void set_style(const std::string &name, const style &style);
+
+#endif // STYLE_H