make arrow button's arrow size scalable by the user
This commit is contained in:
parent
13bf2a7fdd
commit
346a6598a6
7 changed files with 51 additions and 14 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,8 +1,16 @@
|
|||
(Format: Year/Month/Day)
|
||||
Changes for 0.9.10:
|
||||
*04/08/26:
|
||||
* Fixed 2 possible Memleaks (Mathias)
|
||||
Ewmh.cc
|
||||
* Make arrow in toolbar buttons scalable size (Simon)
|
||||
- new theme item: toolbar.button.scale: <number>
|
||||
The number is a scale factor, which is divided into 100 to give
|
||||
the size relative to the button. 100 gives a arrow the same size
|
||||
as button, 200 gives half the size, 300 a third, etc.
|
||||
- default is now 300, not 200
|
||||
- also fix size balance with left/right arrows
|
||||
ArrowButton.hh/cc ButtonTheme.hh/cc ButtonTool.cc FbTk/Button.hh
|
||||
* Fixed 2 possible Memleaks (Mathias)
|
||||
Ewmh.cc
|
||||
* Re-implement bevels in toolbar, plus numerous toolbar-related theme
|
||||
fixes => old styles now look like they used to! (Simon)
|
||||
Toolbar.cc ToolbarItem.h ToolTheme.cc ToolbarTheme.cc ToolFactory.cc
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// $Id: ArrowButton.cc,v 1.7 2004/08/25 17:16:40 rathnor Exp $
|
||||
// $Id: ArrowButton.cc,v 1.8 2004/08/26 15:09:33 rathnor Exp $
|
||||
|
||||
#include "ArrowButton.hh"
|
||||
#include "ButtonTheme.hh"
|
||||
|
||||
ArrowButton::ArrowButton(ArrowButton::Type arrow_type,
|
||||
const FbTk::FbWindow &parent,
|
||||
|
@ -29,7 +30,8 @@ ArrowButton::ArrowButton(ArrowButton::Type arrow_type,
|
|||
unsigned int width, unsigned int height):
|
||||
FbTk::Button(parent, x, y, width, height),
|
||||
m_arrow_type(arrow_type),
|
||||
m_mouse_handler(0) {
|
||||
m_mouse_handler(0),
|
||||
m_arrowscale(300) {
|
||||
|
||||
setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask |
|
||||
EnterWindowMask | LeaveWindowMask);
|
||||
|
@ -41,7 +43,8 @@ ArrowButton::ArrowButton(ArrowButton::Type arrow_type,
|
|||
unsigned int width, unsigned int height):
|
||||
FbTk::Button(screen_num, x, y, width, height),
|
||||
m_arrow_type(arrow_type),
|
||||
m_mouse_handler(0) {
|
||||
m_mouse_handler(0),
|
||||
m_arrowscale(300) {
|
||||
|
||||
setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask |
|
||||
EnterWindowMask | LeaveWindowMask);
|
||||
|
@ -84,15 +87,20 @@ void ArrowButton::drawArrow() {
|
|||
XPoint pts[3];
|
||||
unsigned int w = width();
|
||||
unsigned int h = height();
|
||||
// arrow size: half of the button
|
||||
unsigned int ax = w / 2;
|
||||
unsigned int ay = h / 2;
|
||||
|
||||
int arrowscale_n = m_arrowscale;
|
||||
int arrowscale_d = 100;
|
||||
unsigned int ax = arrowscale_d * w / arrowscale_n;
|
||||
unsigned int ay = arrowscale_d * h / arrowscale_n;
|
||||
// if these aren't an even number, left and right arrows end up different
|
||||
if (( ax % 2 ) == 1) ax++;
|
||||
if (( ay % 2 ) == 1) ay++;
|
||||
switch (m_arrow_type) {
|
||||
case LEFT:
|
||||
// start at the tip
|
||||
pts[0].x = (w / 2) - (ax / 2); pts[0].y = h / 2;
|
||||
pts[1].x = ax; pts[1].y = ay / 2;
|
||||
pts[2].x = 0; pts[2].y = - ay;
|
||||
pts[1].x = ax; pts[1].y = -ay / 2;
|
||||
pts[2].x = 0; pts[2].y = ay;
|
||||
break;
|
||||
case RIGHT:
|
||||
pts[0].x = (w / 2) + (ax / 2); pts[0].y = h / 2;
|
||||
|
@ -118,3 +126,12 @@ void ArrowButton::drawArrow() {
|
|||
}
|
||||
}
|
||||
|
||||
void ArrowButton::updateTheme(const FbTk::Theme &theme) {
|
||||
// it must be a button theme
|
||||
const ButtonTheme &btheme = static_cast<const ButtonTheme &>(theme);
|
||||
|
||||
m_arrowscale = btheme.scale();
|
||||
if (m_arrowscale == 0) m_arrowscale = 300; // default is 0 => 300
|
||||
else if (m_arrowscale < 100) m_arrowscale = 100; // otherwise clamp
|
||||
else if (m_arrowscale > 100000) m_arrowscale = 100000; // clamp below overflow when *100
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// $Id: ArrowButton.hh,v 1.4 2003/10/13 23:51:04 fluxgen Exp $
|
||||
// $Id: ArrowButton.hh,v 1.5 2004/08/26 15:09:33 rathnor Exp $
|
||||
|
||||
#ifndef ARROWBUTTON_HH
|
||||
#define ARROWBUTTON_HH
|
||||
|
@ -45,10 +45,13 @@ public:
|
|||
void leaveNotifyEvent(XCrossingEvent &ce);
|
||||
|
||||
void setMouseMotionHandler(FbTk::EventHandler *eh) { m_mouse_handler = eh; }
|
||||
|
||||
void updateTheme(const FbTk::Theme &theme);
|
||||
private:
|
||||
void drawArrow();
|
||||
Type m_arrow_type;
|
||||
FbTk::EventHandler *m_mouse_handler;
|
||||
int m_arrowscale;
|
||||
};
|
||||
|
||||
#endif // ARROWBUTTON_HH
|
||||
|
|
|
@ -8,7 +8,8 @@ ButtonTheme::ButtonTheme(int screen_num,
|
|||
ToolTheme(screen_num, name, alt_name),
|
||||
m_pic_color(*this, name + ".picColor", alt_name + ".PicColor"),
|
||||
m_pressed_texture(*this, name + ".pressed", alt_name + ".Pressed"),
|
||||
m_gc(RootWindow(FbTk::App::instance()->display(), screen_num)) {
|
||||
m_gc(RootWindow(FbTk::App::instance()->display(), screen_num)),
|
||||
m_scale(*this, name + ".scale", alt_name + ".Scale") {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -16,10 +16,12 @@ public:
|
|||
|
||||
inline const FbTk::Texture &pressed() const { return *m_pressed_texture; }
|
||||
inline GC gc() const { return m_gc.gc(); }
|
||||
inline int scale() const { return *m_scale; } // scale factor for inside objects
|
||||
private:
|
||||
FbTk::ThemeItem<FbTk::Color> m_pic_color;
|
||||
FbTk::ThemeItem<FbTk::Texture> m_pressed_texture;
|
||||
FbTk::GContext m_gc;
|
||||
FbTk::ThemeItem<int> m_scale;
|
||||
};
|
||||
|
||||
#endif // BUTTONTHEME_HH
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// $Id: ButtonTool.cc,v 1.3 2004/01/13 14:41:32 rathnor Exp $
|
||||
// $Id: ButtonTool.cc,v 1.4 2004/08/26 15:09:33 rathnor Exp $
|
||||
|
||||
#include "ButtonTool.hh"
|
||||
|
||||
|
@ -55,6 +55,7 @@ void ButtonTool::renderTheme() {
|
|||
btn.setBorderColor(theme().border().color());
|
||||
btn.setBorderWidth(theme().border().width());
|
||||
btn.setAlpha(theme().alpha());
|
||||
btn.updateTheme(static_cast<const FbTk::Theme &>(theme()));
|
||||
|
||||
Pixmap old_pm = m_cache_pm;
|
||||
if (!theme().texture().usePixmap()) {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// $Id: Button.hh,v 1.8 2003/12/16 17:06:49 fluxgen Exp $
|
||||
// $Id: Button.hh,v 1.9 2004/08/26 15:09:33 rathnor Exp $
|
||||
|
||||
#ifndef FBTK_BUTTON_HH
|
||||
#define FBTK_BUTTON_HH
|
||||
|
@ -36,6 +36,8 @@
|
|||
|
||||
namespace FbTk {
|
||||
|
||||
class Theme;
|
||||
|
||||
class Button:public FbTk::FbWindow, public EventHandler,
|
||||
private NotCopyable {
|
||||
public:
|
||||
|
@ -67,6 +69,9 @@ public:
|
|||
virtual void exposeEvent(XExposeEvent &event);
|
||||
//@}
|
||||
|
||||
// in case it cares about a theme
|
||||
virtual void updateTheme(const FbTk::Theme &theme) {}
|
||||
|
||||
/// @return true if the button is pressed, else false
|
||||
bool pressed() const { return m_pressed; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue