Skip to content

Commit

Permalink
Allow to disable shadows in Fl_Clock and derived widgets.
Browse files Browse the repository at this point in the history
As discussed on 2017-05-15 in fltk.general, thread "Fl_clock".


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12237 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Albrecht Schlosser committed May 15, 2017
1 parent 034148b commit a1d3936
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGES
Expand Up @@ -17,6 +17,9 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2017

New Features and Extensions

- (add new items here)
- New method shadow(int) allows to disable the shadows of the hands
of Fl_Clock, Fl_Clock_Output, and derived widgets.
- New method Fl_Tabs::tab_align() allows to set alignment of tab labels,
particularly to support icons on tab labels (STR #3076).
- Added '--enable-print' option to configure effective under X11 platforms
Expand Down Expand Up @@ -52,7 +55,7 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2017
- Fl_Spinner now handles Up and Down keys when the input field has
keyboard focus (STR #2989).
- Renamed test/help.cxx demo program to test/help_dialog.cxx to avoid
name conflict with CMake auto-generated target 'help'.
name conflict with CMake's auto-generated target 'help'.
- Many documentation fixes, clarifications, and enhancements.


Expand Down
24 changes: 24 additions & 0 deletions FL/Fl_Clock.H
Expand Up @@ -67,6 +67,7 @@
class FL_EXPORT Fl_Clock_Output : public Fl_Widget {
int hour_, minute_, second_;
ulong value_;
int shadow_; // draw shadows of hands
void drawhands(Fl_Color,Fl_Color); // part of draw
protected:
void draw();
Expand Down Expand Up @@ -103,6 +104,29 @@ public:
\see value(), hour(), minute()
*/
int second() const {return second_;}

/**
Returns the shadow drawing mode of the hands.
\returns shadow drawing mode of the hands
\retval 0 no shadows
\retval 1 draw shadows of hands (default)
*/
int shadow() const {return shadow_;}

/**
Sets the shadow drawing mode of the hands.
Enable (1) or disable (0) drawing the hands with shadows.
Values except 0 and 1 are reserved for future extensions and
yield undefined behavior.
The default is to draw the shadows (1).
\param[in] mode 1 = shadows (default), 0 = no shadows
*/
void shadow(int mode) { shadow_ = mode ? 1 : 0; }
};

// a Fl_Clock displays the current time always by using a timeout:
Expand Down
16 changes: 11 additions & 5 deletions src/Fl_Clock.cxx
Expand Up @@ -74,7 +74,6 @@ static void rect(double x, double y, double w, double h) {
*/
void Fl_Clock_Output::draw(int X, int Y, int W, int H) {
Fl_Color box_color = type()==FL_ROUND_CLOCK ? FL_GRAY : color();
Fl_Color shadow_color = fl_color_average(box_color, FL_BLACK, 0.5);
draw_box(box(), X, Y, W, H, box_color);
fl_push_matrix();
fl_translate(X+W/2.0-.5, Y+H/2.0-.5);
Expand All @@ -85,11 +84,16 @@ void Fl_Clock_Output::draw(int X, int Y, int W, int H) {
fl_color(active_r() ? FL_FOREGROUND_COLOR : fl_inactive(FL_FOREGROUND_COLOR));
fl_begin_loop(); fl_circle(0,0,14); fl_end_loop();
}

// draw the shadows:
fl_push_matrix();
fl_translate(0.60, 0.60);
drawhands(shadow_color, shadow_color);
fl_pop_matrix();
if (shadow_) {
Fl_Color shadow_color = fl_color_average(box_color, FL_BLACK, 0.5);
fl_push_matrix();
fl_translate(0.60, 0.60);
drawhands(shadow_color, shadow_color);
fl_pop_matrix();
}

// draw the tick marks:
fl_push_matrix();
fl_color(active_r() ? FL_FOREGROUND_COLOR : fl_inactive(FL_FOREGROUND_COLOR));
Expand All @@ -100,6 +104,7 @@ void Fl_Clock_Output::draw(int X, int Y, int W, int H) {
fl_rotate(-30);
}
fl_pop_matrix();

// draw the hands:
drawhands(selection_color(), FL_FOREGROUND_COLOR); // color was 54
fl_pop_matrix();
Expand Down Expand Up @@ -160,6 +165,7 @@ Fl_Clock_Output::Fl_Clock_Output(int X, int Y, int W, int H, const char *L)
minute_ = 0;
second_ = 0;
value_ = 0;
shadow_ = 1;
}

////////////////////////////////////////////////////////////////
Expand Down
10 changes: 8 additions & 2 deletions test/clock.cxx
Expand Up @@ -3,7 +3,7 @@
//
// Clock test program for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 by Bill Spitzak and others.
// Copyright 1998-2017 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
Expand All @@ -21,13 +21,19 @@
#include <FL/Fl_Clock.H>
#include <FL/Fl_Round_Clock.H>

const int dev_test = 0; // 1 = enable non-standard colors and no-shadow tests

int main(int argc, char **argv) {
Fl_Double_Window window(220,220,"Fl_Clock");
Fl_Clock c1(0,0,220,220); // c1.color(2,1);
window.resizable(c1);
window.end();
Fl_Double_Window window2(220,220,"Fl_Round_Clock");
Fl_Round_Clock c2(0,0,220,220); // c2.color(3,4);
Fl_Round_Clock c2(0,0,220,220);
if (dev_test) {
c2.color(FL_YELLOW,FL_RED); // set background and hands colors, resp.
c2.shadow(0); // disable shadows of the hands
}
window2.resizable(c2);
window2.end();
// my machine had a clock* Xresource set for another program, so
Expand Down

0 comments on commit a1d3936

Please sign in to comment.