Author: matt
Date: 2012-05-02 14:40:56 -0700 (Wed, 02 May 2012)
New Revision: 9437
Log:
Fixed Clock and Circle for OS X
Modified:
branches/branch-3.0/include/fltk3/Clock.h
branches/branch-3.0/src/fltk3/Clock.cxx
branches/branch-3.0/src/fltk3/vertex.cxx
branches/branch-3.0/test/clock.cxx
Modified: branches/branch-3.0/include/fltk3/Clock.h
===================================================================
--- branches/branch-3.0/include/fltk3/Clock.h 2012-05-02 21:24:21 UTC (rev
9436)
+++ branches/branch-3.0/include/fltk3/Clock.h 2012-05-02 21:40:56 UTC (rev
9437)
@@ -63,13 +63,16 @@
\image latex round_clock.png "fltk3::ROUND_CLOCK type" width=4cm
*/
class FLTK3_EXPORT ClockOutput : public Widget {
-
+
+ private:
int hour_, minute_, second_;
ulong value_;
void drawhands(fltk3::Color,fltk3::Color); // part of draw
+
protected:
void draw();
void draw(int X, int Y, int W, int H);
+
public:
ClockOutput(int X, int Y, int W, int H, const char *L = 0);
@@ -123,7 +126,7 @@
\image latex round_clock.png "fltk3::ROUND_CLOCK type" width=4cm
*/
class FLTK3_EXPORT Clock : public ClockOutput {
-
+
public:
int handle(int);
Modified: branches/branch-3.0/src/fltk3/Clock.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Clock.cxx 2012-05-02 21:24:21 UTC (rev
9436)
+++ branches/branch-3.0/src/fltk3/Clock.cxx 2012-05-02 21:40:56 UTC (rev
9437)
@@ -31,17 +31,20 @@
#include <math.h>
#include <time.h>
#ifndef WIN32
-# include <sys/time.h>
+# include <sys/time.h>
#endif /* !WIN32 */
+
// Original clock display written by Paul Haeberli at SGI.
// Modifications by Mark Overmars for Forms
// Further changes by Bill Spitzak for fltk
+
const float hourhand[4][2] = {{-0.5f, 0}, {0, 1.5f}, {0.5f, 0}, {0, -7.0f}};
const float minhand[4][2] = {{-0.5f, 0}, {0, 1.5f}, {0.5f, 0}, {0, -11.5f}};
const float sechand[4][2] = {{-0.1f, 0}, {0, 2.0f}, {0.1f, 0}, {0, -11.5f}};
+
static void drawhand(double ang,const float v[][2],fltk3::Color
fill,fltk3::Color line)
{
fltk3::push_matrix();
@@ -53,7 +56,9 @@
fltk3::pop_matrix();
}
-void fltk3::ClockOutput::drawhands(fltk3::Color fill, fltk3::Color line) {
+
+void fltk3::ClockOutput::drawhands(fltk3::Color fill, fltk3::Color line)
+{
if (!active_r()) {
fill = fltk3::inactive(fill);
line = fltk3::inactive(line);
@@ -63,7 +68,9 @@
drawhand(-360*(second()/60.0), sechand, fill, line);
}
-static void rect(double x, double y, double w, double h) {
+
+static void rect(double x, double y, double w, double h)
+{
double r = x+w;
double t = y+h;
fltk3::begin_polygon();
@@ -74,11 +81,13 @@
fltk3::end_polygon();
}
+
/**
- Draw clock with the given position and size.
- \param[in] X, Y, W, H position and size
-*/
-void fltk3::ClockOutput::draw(int X, int Y, int W, int H) {
+ Draw clock with the given position and size.
+ \param[in] X, Y, W, H position and size
+ */
+void fltk3::ClockOutput::draw(int X, int Y, int W, int H)
+{
fltk3::Color box_color = type()==fltk3::ROUND_CLOCK ? fltk3::GRAY : color();
fltk3::Color shadow_color = fltk3::color_average(box_color, fltk3::BLACK,
0.5);
draw_box(box(), X, Y, W, H, box_color);
@@ -111,21 +120,29 @@
fltk3::pop_matrix();
}
+
/**
- Draw clock with current position and size.
-*/
-void fltk3::ClockOutput::draw() {
- draw(x(), y(), w(), h());
+ Draw clock with current position and size.
+ */
+void fltk3::ClockOutput::draw()
+{
+ if (is_group_relative()) {
+ draw(0, 0, w(), h());
+ } else {
+ draw(x(), y(), w(), h());
+ }
draw_label();
}
+
/**
- Set the displayed time.
- Set the time in hours, minutes, and seconds.
- \param[in] H, m, s displayed time
- \see hour(), minute(), second()
+ Set the displayed time.
+ Set the time in hours, minutes, and seconds.
+ \param[in] H, m, s displayed time
+ \see hour(), minute(), second()
*/
-void fltk3::ClockOutput::value(int H, int m, int s) {
+void fltk3::ClockOutput::value(int H, int m, int s)
+{
if (H!=hour_ || m!=minute_ || s!=second_) {
hour_ = H; minute_ = m; second_ = s;
value_ = (H * 60 + m) * 60 + s;
@@ -133,13 +150,15 @@
}
}
+
/**
- Set the displayed time.
- Set the time in seconds since the UNIX epoch (January 1, 1970).
- \param[in] v seconds since epoch
- \see value()
+ Set the displayed time.
+ Set the time in seconds since the UNIX epoch (January 1, 1970).
+ \param[in] v seconds since epoch
+ \see value()
*/
-void fltk3::ClockOutput::value(ulong v) {
+void fltk3::ClockOutput::value(ulong v)
+{
value_ = v;
struct tm *timeofday;
// Some platforms, notably Windows, now use a 64-bit time_t value...
@@ -148,14 +167,17 @@
value(timeofday->tm_hour, timeofday->tm_min, timeofday->tm_sec);
}
+
/**
- Create a new fltk3::ClockOutput widget with the given position, size and
label.
- The default boxtype is \c fltk3::NO_BOX.
- \param[in] X, Y, W, H position and size of the widget
- \param[in] L widget label, default is no label
+ Create a new fltk3::ClockOutput widget with the given position, size and
label.
+ The default boxtype is \c fltk3::NO_BOX.
+ \param[in] X, Y, W, H position and size of the widget
+ \param[in] L widget label, default is no label
*/
fltk3::ClockOutput::ClockOutput(int X, int Y, int W, int H, const char *L)
-: fltk3::Widget(X, Y, W, H, L) {
+: fltk3::Widget(X, Y, W, H, L)
+{
+ set_group_relative();
box(fltk3::UP_BOX);
selection_color(fltk3::gray_ramp(5));
align(fltk3::ALIGN_BOTTOM);
@@ -165,54 +187,69 @@
value_ = 0;
}
+
////////////////////////////////////////////////////////////////
+
/**
- Create an fltk3::Clock widget using the given position, size, and label
string.
- The default boxtype is \c fltk3::NO_BOX.
- \param[in] X, Y, W, H position and size of the widget
- \param[in] L widget label, default is no label
+ Create an fltk3::Clock widget using the given position, size, and label
string.
+ The default boxtype is \c fltk3::NO_BOX.
+ \param[in] X, Y, W, H position and size of the widget
+ \param[in] L widget label, default is no label
*/
fltk3::Clock::Clock(int X, int Y, int W, int H, const char *L)
- : fltk3::ClockOutput(X, Y, W, H, L) {}
+: fltk3::ClockOutput(X, Y, W, H, L)
+{
+ set_group_relative();
+}
+
/**
- Create an fltk3::Clock widget using the given boxtype, position, size, and
- label string.
- \param[in] t boxtype
- \param[in] X, Y, W, H position and size of the widget
- \param[in] L widget label, default is no label
+ Create an fltk3::Clock widget using the given boxtype, position, size, and
+ label string.
+ \param[in] t boxtype
+ \param[in] X, Y, W, H position and size of the widget
+ \param[in] L widget label, default is no label
*/
fltk3::Clock::Clock(uchar t, int X, int Y, int W, int H, const char *L)
- : fltk3::ClockOutput(X, Y, W, H, L) {
+: fltk3::ClockOutput(X, Y, W, H, L)
+{
+ set_group_relative();
type(t);
box(t==fltk3::ROUND_CLOCK ? fltk3::NO_BOX : fltk3::UP_BOX);
}
-static void tick(void *v) {
+
+static void tick(void *v)
+{
((fltk3::Clock*)v)->value( (ulong)time(0) );
fltk3::add_timeout(1.0, tick, v);
}
-int fltk3::Clock::handle(int event) {
+
+int fltk3::Clock::handle(int event)
+{
switch (event) {
- case fltk3::SHOW:
- tick(this);
- break;
- case fltk3::HIDE:
- fltk3::remove_timeout(tick, this);
- break;
+ case fltk3::SHOW:
+ tick(this);
+ break;
+ case fltk3::HIDE:
+ fltk3::remove_timeout(tick, this);
+ break;
}
return ClockOutput::handle(event);
}
-
+
+
/**
- The destructor removes the clock.
+ The destructor removes the clock.
*/
-fltk3::Clock::~Clock() {
+fltk3::Clock::~Clock()
+{
fltk3::remove_timeout(tick, this);
}
+
//
// End of "$Id$".
//
Modified: branches/branch-3.0/src/fltk3/vertex.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/vertex.cxx 2012-05-02 21:24:21 UTC (rev
9436)
+++ branches/branch-3.0/src/fltk3/vertex.cxx 2012-05-02 21:40:56 UTC (rev
9437)
@@ -350,7 +350,7 @@
// Quartz warning: circle won't scale to current matrix!
// Last argument must be 0 (counter-clockwise) or it draws nothing under
__LP64__ !!!!
CGContextSetShouldAntialias(fl_gc, true);
- CGContextAddArc(fl_gc, xt, yt, (w+h)*0.25f, 0, 2.0f*M_PI, 0);
+ CGContextAddArc(fl_gc, xt+origin_x(), yt+origin_y(), (w+h)*0.25f, 0,
2.0f*M_PI, 0);
(vertex_kind() == POLYGON ? CGContextFillPath : CGContextStrokePath)(fl_gc);
CGContextSetShouldAntialias(fl_gc, false);
}
Modified: branches/branch-3.0/test/clock.cxx
===================================================================
--- branches/branch-3.0/test/clock.cxx 2012-05-02 21:24:21 UTC (rev 9436)
+++ branches/branch-3.0/test/clock.cxx 2012-05-02 21:40:56 UTC (rev 9437)
@@ -36,7 +36,7 @@
window.resizable(c1);
window.end();
fltk3::DoubleWindow window2(220,220,"fltk3::Round_Clock");
- fltk3::RoundClock c2(0,0,220,220); // c2.color(3,4);
+ fltk3::RoundClock c2(10,10,200,200); // c2.color(3,4);
window2.resizable(c2);
window2.end();
// my machine had a clock* Xresource set for another program, so
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit