Ardour  9.0-pre0-1320-gf48fe3f740
ardour_spacer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
4  * Copyright (C) 2018 Ben Loftis <ben@harrisonconsoles.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef _WIDGETS_ARDOUR_SPACER_H_
22 #define _WIDGETS_ARDOUR_SPACER_H_
23 
24 #include "gtkmm2ext/cairo_widget.h"
25 #include "gtkmm2ext/colors.h"
26 #include "widgets/ui_config.h"
27 
28 #include "widgets/visibility.h"
29 
30 namespace ArdourWidgets {
31 
33 {
34 public:
35  ArdourScalingSpacer (int natural_width = 16, int natural_height = 16);
36 
37 protected:
38  void render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*) {}
39 
41  if (_natural_width > 0) {
42  req->width = _natural_width * UIConfigurationBase::instance().get_ui_scale ();
43  }
44  if (_natural_height > 0) {
45  req->height = _natural_height * UIConfigurationBase::instance().get_ui_scale ();
46  }
48  }
49 
50 private:
53 };
54 
56 {
57 public:
58  ArdourVSpacer (float r = 0.75f);
59 
60 protected:
61  void render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*) {
62 
63  if (_ratio < 0) {
64  return;
65  }
66 
67  float height = get_height();
68 
69  float h = height * _ratio;
70  float t = .5f * (height - h);
71  ctx->rectangle (0, t, 1, h);
72  uint32_t c = UIConfigurationBase::instance().color ("neutral:backgroundest");
74  ctx->fill ();
75  }
76 
78  req->width = 1;
79  req->height = 0;
81  }
82 
83 private:
84  float _ratio;
85 };
86 
88 {
89 public:
90  ArdourHSpacer (float r = 0.75f);
91 
92 protected:
93  void render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*) {
94 
95  if (_ratio < 0) {
96  return;
97  }
98 
99  float width = get_width();
100 
101  float w = width * _ratio;
102  float t = .5f * (width - w);
103  ctx->rectangle (t, 0, w, 1);
104  uint32_t c = UIConfigurationBase::instance().color ("neutral:backgroundest");
106  ctx->fill ();
107  }
108 
110  req->width = 0;
111  req->height = 1;
113  }
114 
115 private:
116  float _ratio;
117 };
118 
120 {
121 public:
122  enum ShadowMode {
125  };
126 
127  ArdourDropShadow (ShadowMode m = DropShadowLongSideOnly, float a = 0.55f);
128 
129  void set_mode(ShadowMode m) {mode = m;}
130 
131 protected:
132  void render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*) {
133  float width = get_width();
134  float height = get_height();
135 
136  Cairo::RefPtr<Cairo::LinearGradient> _gradient;
137 
138  if ( (width>height) || mode == DropShadowBoth ) {
139  _gradient = Cairo::LinearGradient::create (0, 0, 0, 4);
140  _gradient->add_color_stop_rgba (0, 0, 0, 0, alpha);
141  _gradient->add_color_stop_rgba (1, 0, 0, 0, 0);
142  ctx->set_source (_gradient);
143  ctx->rectangle (0, 0, width, 4);
144  ctx->fill ();
145  }
146 
147  if ( (height>width) || mode == DropShadowBoth ) {
148  _gradient = Cairo::LinearGradient::create (0, 0, 4, 0);
149  _gradient->add_color_stop_rgba (0, 0, 0, 0, alpha);
150  _gradient->add_color_stop_rgba (1, 0, 0, 0, 0);
151  ctx->set_source (_gradient);
152  ctx->rectangle (0, 0, 4, height);
153  ctx->fill ();
154  }
155  }
156 
157  float alpha;
159 };
160 
161 } /* end namespace */
162 
163 #endif
void render(Cairo::RefPtr< Cairo::Context > const &ctx, cairo_rectangle_t *)
ArdourDropShadow(ShadowMode m=DropShadowLongSideOnly, float a=0.55f)
void on_size_request(Gtk::Requisition *req)
This is a default handler for the signal signal_size_request().
void render(Cairo::RefPtr< Cairo::Context > const &ctx, cairo_rectangle_t *)
Definition: ardour_spacer.h:93
void render(Cairo::RefPtr< Cairo::Context > const &ctx, cairo_rectangle_t *)
Definition: ardour_spacer.h:38
void on_size_request(Gtk::Requisition *req)
This is a default handler for the signal signal_size_request().
Definition: ardour_spacer.h:40
ArdourScalingSpacer(int natural_width=16, int natural_height=16)
void on_size_request(Gtk::Requisition *req)
This is a default handler for the signal signal_size_request().
Definition: ardour_spacer.h:77
void render(Cairo::RefPtr< Cairo::Context > const &ctx, cairo_rectangle_t *)
Definition: ardour_spacer.h:61
virtual Gtkmm2ext::Color color(const std::string &, bool *failed=0) const =0
virtual void on_size_request(Requisition *requisition)
This is a default handler for the signal signal_size_request().
void set_source_rgba(Cairo::RefPtr< Cairo::Context >, Gtkmm2ext::Color)
#define LIBWIDGETS_API
gint height
Definition: xcursors.h:1
gint width
Definition: xcursors.h:1