Fl_Clock.H 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // "$Id: Fl_Clock.H 12238 2017-05-15 15:35:30Z AlbrechtS $"
  3. //
  4. // Clock header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2017 by Bill Spitzak and others.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. /* \file
  19. Fl_Clock, Fl_Clock_Output widgets . */
  20. #ifndef Fl_Clock_H
  21. #define Fl_Clock_H
  22. #ifndef Fl_Widget_H
  23. #include "Fl_Widget.H"
  24. #endif
  25. // Values for type():
  26. // Please change doxygen documentation below (class Fl_Clock_Output)
  27. // accordingly as well when changing the following type values:
  28. #define FL_SQUARE_CLOCK 0 /**< type() of Square Clock variant */
  29. #define FL_ROUND_CLOCK 1 /**< type() of Round Clock variant */
  30. #define FL_ANALOG_CLOCK FL_SQUARE_CLOCK /**< An analog clock is square */
  31. #define FL_DIGITAL_CLOCK FL_SQUARE_CLOCK /**< Not yet implemented */
  32. // fabien: Please keep the horizontal formatting of both images in class desc,
  33. // don't lose vertical space for nothing!
  34. /**
  35. \class Fl_Clock_Output
  36. \brief This widget can be used to display a program-supplied time.
  37. The time shown on the clock is not updated. To display the current time,
  38. use Fl_Clock instead.
  39. \htmlonly <BR> <table align=CENTER border=1 cellpadding=5 >
  40. <caption align=bottom>type() FL_SQUARE_CLOCK and FL_ROUND_CLOCK </caption> <TR><TD> \endhtmlonly
  41. \image html clock.png
  42. \htmlonly </TD> <TD> \endhtmlonly
  43. \image html round_clock.png
  44. \htmlonly </TD> </TR> </table> \endhtmlonly
  45. \image latex clock.png "FL_SQUARE_CLOCK type" width=4cm
  46. \image latex round_clock.png "FL_ROUND_CLOCK type" width=4cm
  47. Values for clock type() (\#include \<FL/Clock.H\>):
  48. \code
  49. #define FL_SQUARE_CLOCK 0 // Square Clock variant
  50. #define FL_ROUND_CLOCK 1 // Round Clock variant
  51. #define FL_ANALOG_CLOCK FL_SQUARE_CLOCK // An analog clock is square
  52. #define FL_DIGITAL_CLOCK FL_SQUARE_CLOCK // Not yet implemented
  53. \endcode
  54. */
  55. class FL_EXPORT Fl_Clock_Output : public Fl_Widget {
  56. int hour_, minute_, second_;
  57. ulong value_;
  58. int shadow_; // draw shadows of hands
  59. void drawhands(Fl_Color,Fl_Color); // part of draw
  60. protected:
  61. void draw();
  62. void draw(int X, int Y, int W, int H);
  63. public:
  64. Fl_Clock_Output(int X, int Y, int W, int H, const char *L = 0);
  65. void value(ulong v); // set to this Unix time
  66. void value(int H, int m, int s);
  67. /**
  68. Returns the displayed time.
  69. Returns the time in seconds since the UNIX epoch (January 1, 1970).
  70. \see value(ulong)
  71. */
  72. ulong value() const {return value_;}
  73. /**
  74. Returns the displayed hour (0 to 23).
  75. \see value(), minute(), second()
  76. */
  77. int hour() const {return hour_;}
  78. /**
  79. Returns the displayed minute (0 to 59).
  80. \see value(), hour(), second()
  81. */
  82. int minute() const {return minute_;}
  83. /**
  84. Returns the displayed second (0 to 60, 60=leap second).
  85. \see value(), hour(), minute()
  86. */
  87. int second() const {return second_;}
  88. /**
  89. Returns the shadow drawing mode of the hands.
  90. \returns shadow drawing mode of the hands
  91. \retval 0 no shadows
  92. \retval 1 draw shadows of hands (default)
  93. */
  94. int shadow() const {return shadow_;}
  95. /**
  96. Sets the shadow drawing mode of the hands.
  97. Enables (1) or disables (0) drawing the hands with shadows.
  98. Values except 0 and 1 are reserved for future extensions and
  99. yield undefined behavior.
  100. The default is to draw the shadows (1).
  101. \param[in] mode 1 = shadows (default), 0 = no shadows
  102. */
  103. void shadow(int mode) { shadow_ = mode ? 1 : 0; }
  104. };
  105. // a Fl_Clock displays the current time always by using a timeout:
  106. /**
  107. \class Fl_Clock
  108. \brief This widget provides a round analog clock display.
  109. Fl_Clock is provided for Forms compatibility.
  110. It installs a 1-second timeout callback using Fl::add_timeout().
  111. You can choose the rounded or square type of the clock with type().
  112. Please see Fl_Clock_Output widget for applicable values.
  113. \htmlonly <BR> <table align=CENTER border=1 cellpadding=5 >
  114. <caption align=bottom>type() FL_SQUARE_CLOCK and FL_ROUND_CLOCK </caption> <TR><TD> \endhtmlonly
  115. \image html clock.png
  116. \htmlonly </TD> <TD> \endhtmlonly
  117. \image html round_clock.png
  118. \htmlonly </TD> </TR> </table> \endhtmlonly
  119. \image latex clock.png "FL_SQUARE_CLOCK type" width=4cm
  120. \image latex round_clock.png "FL_ROUND_CLOCK type" width=4cm
  121. \see class Fl_Clock_Output
  122. */
  123. class FL_EXPORT Fl_Clock : public Fl_Clock_Output {
  124. public:
  125. int handle(int);
  126. Fl_Clock(int X, int Y, int W, int H, const char *L = 0);
  127. Fl_Clock(uchar t, int X, int Y, int W, int H, const char *L);
  128. ~Fl_Clock();
  129. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Clock, Fl_Clock_Output)
  130. };
  131. #endif
  132. //
  133. // End of "$Id: Fl_Clock.H 12238 2017-05-15 15:35:30Z AlbrechtS $".
  134. //