Comments

wxBinaryClock.exw
wxEuphoria

BinaryClock.exw
win32lib

Header -- wxBinaryClock.exw
--   version 1.0
--
--   translated by c.k.lester and matthew lewis
-- from Greg Habarek's win32lib version of BinaryClock.exw
--
-- Confusing yet functional... and cross-platform compatible. :)
-- BinaryClock.exw
--
-- Confusing yet functional.
--
Includes
wxBinaryClock has inline images, whereas BinaryClock gets them from an include file.
without warning

include wxEuphoria.e
include wxMenu.e
include wxGraphics.e
include wxTimer.e

object void
include Win32Lib.ew
without warning

include images\LED0.e
include images\LED1.e
include images\LED2.e
include images\LED3.e
Create Window constant
   Main = create( wxFrame, {0, -1, "Binary Clock", -1, -1, 132, 114, wxDEFAULT_FRAME_STYLE - ( wxSYSTEM_MENU + wxRESIZE_BORDER ) }),
   MainPanel = create( wxPanel, {Main}),
constant
   Main = create( Window, "Binary Clock", 0, {w32AltEdge,-132}, w32Edge, 132, 114, {WS_DLGFRAME} ),
Create Popup Menu    -- The Popup Menu
   wxID_AMBER = new_id(),
   wxID_BLUE = new_id(),
   wxID_RED = new_id(),
   
      Popup1 = create( wxMenu, {0,"Popup"} ),
       --MenuNew = create( wxMenuItem,{ FileMenu, wxID_NEW,"&New"}),
       Amber = create( wxMenuItem, { Popup1, wxID_AMBER, "&Amber","",1 } ),
       Blue = create( wxMenuItem, { Popup1, wxID_BLUE, "&Blue","",1 } ),
       Red = create( wxMenuItem, { Popup1, wxID_RED, "&Red","",1 } ),
       Sep1 = create( wxMenuItem,{ Popup1, wxID_SEPARATOR, "-"}),
       --AlwaysOnTop = create( wxMenuItem, { Popup1, "Always On Top", Popup1, 0, 0, 0, 0, 0 ),
       --Sep3 = create( wxMenuItem,{ Popup1, wxID_SEPARATOR, "-"}),
       Exit = create( wxMenuItem,{ Popup1, wxID_EXIT, "&Exit"}),
   Popup1 = create( Popup, "", Main, 0, 0, 0, 0, 0 ),
   Amber = create( MenuItem, "&Amber", Popup1, 0, 0, 0, 0, 0 ),
   Blue = create( MenuItem, "&Blue", Popup1, 0, 0, 0, 0, 0 ),
   Red = create( MenuItem, "&Red", Popup1, 0, 0, 0, 0, 0 ),
   Sep1 = create( MenuItem, "-", Popup1, 0, 0, 0, 0, 0 ),
   AlwaysOnTop = create( MenuItem, "Always On Top", Popup1, 0, 0, 0, 0, 0 ),
   Sep2 = create( MenuItem, "-", Popup1, 0, 0, 0, 0, 0 ),
   Exit = create( MenuItem, "E&xit", Popup1, 0, 0, 0, 0, w32AUTOCLOSE )
The Graphics -- Some color widgets
   wxRED = create(wxColour, {255,0,0}),
   wxBLUE = create( wxColour, {0,0,255}),
   wxAMBER = create( wxColour, {224,128,64}),
   wxGREY = create(wxColour,{100,100,100}),
   wxPINK = create( wxColour, {255,30,156}),

   -- The Graphics
   GreyDot = create( wxBitmap,{ BM_XPM, {
            "18 18 4 1",
            " c #FF1E9C",
            ". c #000000",
            "+ c #C0C0C0",
            "@ c #FFFFFF",
            " ",
            " ...... ",
            " ..++++++.. ",
            " .++++++++++. ",
            " .++@@++++++++. ",
            " .+@@+++++++++. ",
            " .++@+++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++. ",
            " .++++++++++++. ",
            " .++++++++++. ",
            " ..++++++.. ",
            " ...... ",
            " "}}),
   
   AmberDot = create( wxBitmap,{ BM_XPM, {
            "18 18 4 1",
            ". c #000000",
            "+ c #E08040",
            " c #FF1E9C",
            "@ c #FFFFFF",
            " ",
            " ...... ",
            " ..++++++.. ",
            " .++++++++++. ",
            " .++@@++++++++. ",
            " .+@@+++++++++. ",
            " .++@+++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++. ",
            " .++++++++++++. ",
            " .++++++++++. ",
            " ..++++++.. ",
            " ...... ",
            " "}}),
            
   BlueDot = create( wxBitmap,{ BM_XPM, {
            "18 18 4 1",
            ". c #000000",
            "+ c #0000FF",
            " c #FF1E9C",
            "@ c #FFFFFF",
            " ",
            " ...... ",
            " ..++++++.. ",
            " .++++++++++. ",
            " .++@@++++++++. ",
            " .+@@+++++++++. ",
            " .++@+++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++. ",
            " .++++++++++++. ",
            " .++++++++++. ",
            " ..++++++.. ",
            " ...... ",
            " "}}),
            
   RedDot = create( wxBitmap,{ BM_XPM, {
            "18 18 4 1",
            ". c #000000",
            "+ c #FF0000",
            " c #FF1E9C",
            "@ c #FFFFFF",
            " ",
            " ...... ",
            " ..++++++.. ",
            " .++++++++++. ",
            " .++@@++++++++. ",
            " .+@@+++++++++. ",
            " .++@+++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++++. ",
            " .++++++++++++. ",
            " .++++++++++++. ",
            " .++++++++++. ",
            " ..++++++.. ",
            " ...... ",
            " "}}),

   -- The Masks (for transparency drawing)
   GreyMask = create( wxMask, { GreyDot, wxPINK } ),
   AmberMask = create( wxMask, { AmberDot, wxPINK } ),
   BlueMask = create( wxMask, { BlueDot, wxPINK } ),
   RedMask = create( wxMask, { RedDot, wxPINK } ),
   
kStates = {AmberDot, BlueDot, RedDot}

   -- set the masks
   void = call_member( wxBitmap_SetMask, GreyDot, {GreyMask})
   void = call_member( wxBitmap_SetMask, RedDot, {RedMask})
   void = call_member( wxBitmap_SetMask, BlueDot, {BlueMask})
   void = call_member( wxBitmap_SetMask, AmberDot, {AmberMask})
   
constant
LED0 = createDIB( LED0_bmp ), -- Grey (OFF)
LED1 = createDIB( LED1_bmp ), -- Amber
LED2 = createDIB( LED2_bmp ), -- Blue
LED3 = createDIB( LED3_bmp ) -- Red

constant
kStates = {LED1, LED2, LED3}
Timer Widget constant
   -- The Timer
   MyTimer = create( wxTimer, {Main, -1})
   
 
Init Vars integer vColor
   vColor = 1
integer vColor
vColor = 1
LED Blit Procedure procedure ledBlt( atom pDst, integer pDstX, integer pDstY, integer pState )
atom lSrc
if pState then
lSrc = kStates[pState]
else
lSrc = GreyDot
end if
draw_bitmap( pDst, lSrc, pDstX, pDstY, 1 ) -- the '1' means draw with transparency (use the mask)
end procedure
procedure ledBlt( atom pDst, integer pDstX, integer pDstY, integer pState )
atom lSrc
if pState then
lSrc = kStates[pState]
else
lSrc = LED0
end if
transBlt( pDst, pDstX, pDstY, lSrc )
end procedure
Drawing Binary Time Procedure
This is exactly the same for each program.
procedure drawBinaryTime( integer pCtrl, integer HH, integer MM, integer SS )
-- draws binary time in 24-hour format

object h1, h2, m1, m2, s1, s2
sequence rect, xPos, yPos, t
integer center, bottom

-- separate each digit
h1 = floor( HH / 10 )
h2 = HH - (h1 * 10)
m1 = floor( MM / 10 )
m2 = MM - (m1 * 10)
s1 = floor( SS / 10 )
s2 = SS - (s1 * 10)

-- convert digits to bits
-- (some only need 2 or 3 bits)
h1 = int_to_bits( h1, 2 )
h2 = int_to_bits( h2, 4 )
m1 = int_to_bits( m1, 3 )
m2 = int_to_bits( m2, 4 )
s1 = int_to_bits( s1, 3 )
s2 = int_to_bits( s2, 4 )

rect = get_rect( MainPanel )
center = floor( (rect[3]-rect[1]) / 2 )
bottom = rect[4]-rect[2]
   
-- referenced from {center, bottom}
xPos = {-60, -40, -20, 0, 20, 40}
yPos = {-20, -40, -60, -80}

t = {h1, h2, m1, m2, s1, s2}

for x = 1 to length( t ) do

for y = 1 to length( t[x] ) do

if t[x][y] then
t[x][y] = vColor
end if

ledBlt( pCtrl, center+xPos[x], bottom+yPos[y], t[x][y] )

end for

end for

end procedure
         
procedure drawBinaryTime( integer pCtrl, integer HH, integer MM, integer SS )
-- draws binary time in 24-hour format

object h1, h2, m1, m2, s1, s2
sequence rect, xPos, yPos, t
integer center, bottom

-- separate each digit
h1 = floor( HH / 10 )
h2 = HH - (h1 * 10)
m1 = floor( MM / 10 )
m2 = MM - (m1 * 10)
s1 = floor( SS / 10 )
s2 = SS - (s1 * 10)

-- convert digits to bits
-- (some only need 2 or 3 bits)
h1 = int_to_bits( h1, 2 )
h2 = int_to_bits( h2, 4 )
m1 = int_to_bits( m1, 3 )
m2 = int_to_bits( m2, 4 )
s1 = int_to_bits( s1, 3 )
s2 = int_to_bits( s2, 4 )

rect = getClientRect( pCtrl )
center = floor( (rect[3]-rect[1]) / 2 )
bottom = rect[4]-rect[2]

-- referenced from {center, bottom}
xPos = {-60, -40, -20, 0, 20, 40}
yPos = {-20, -40, -60, -80}

t = {h1, h2, m1, m2, s1, s2}

for x = 1 to length( t ) do

for y = 1 to length( t[x] ) do

if t[x][y] then
t[x][y] = vColor
end if

ledBlt( pCtrl, center+xPos[x], bottom+yPos[y], t[x][y] )

end for

end for

end procedure
Call Popup Menu on Right Click Procedure procedure on_rclick( atom this, atom event_type, atom id, atom event )
sequence pos
   pos = mouse_event_position( event )
   void = call_member( wxWindow_DoPopupMenu, this, Popup1 & pos )
end procedure
set_event_handler(MainPanel, -1, wxEVT_RIGHT_DOWN, routine_id( "on_rclick" ))
procedure Main_Mouse( integer pSelf, integer pEvent, sequence pParams )
integer event, x, y, shift
event = pParams[1]
x = pParams[2]
y = pParams[3]
shift = pParams[4]
if event = RightDown then
popup( Popup1, x, y )
end if
end procedure
setHandler( Main, w32HMouse, routine_id("Main_Mouse") )
Change Color Procedure (Menu Selection Event) procedure AmberBlueRed_Click( atom this, atom event_type, atom id, atom event )
-- alter LED colors
   check_menuitem( Amber, 0 )
   check_menuitem( Blue, 0 )
   check_menuitem( Red, 0 )
   if id=wxID_AMBER then
      check_menuitem( Amber, 1 )
      vColor = 1
   elsif id=wxID_BLUE then
      check_menuitem( Blue, 1 )
      vColor = 2
   elsif id=wxID_RED then
      check_menuitem( Red, 1 )
      vColor = 3
   end if
refresh_window( {MainPanel,1} )
end procedure
set_event_handler( {Main,Amber}, wxID_AMBER, wxEVT_COMMAND_MENU_SELECTED,
routine_id( "AmberBlueRed_Click" ))
set_event_handler( {Main,Blue}, wxID_BLUE, wxEVT_COMMAND_MENU_SELECTED,
routine_id( "AmberBlueRed_Click" ))
set_event_handler( {Main,Red}, wxID_RED, wxEVT_COMMAND_MENU_SELECTED,
routine_id( "AmberBlueRed_Click" ))
procedure AmberBlueRed_Click( integer pSelf, integer pEvent, sequence pParams )
setCheck( Amber, w32False )
setCheck( Blue, w32False )
setCheck( Red, w32False )
if pSelf = Amber then
vColor = 1
elsif pSelf = Blue then
vColor = 2
elsif pSelf = Red then
vColor = 3
end if
setCheck( pSelf, w32True )
end procedure
setHandler( {Amber,Blue,Red}, w32HClick, routine_id("AmberBlueRed_Click") )
Other Menu Events procedure onMenu_MenuExit(atom this, atom event_type, atom id, atom event)
exit_main()
end procedure
set_event_handler( {Main,Popup1}, wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
routine_id( "onMenu_MenuExit" ))
procedure AlwaysOnTop_Click( integer pSelf, integer pEvent, sequence pParams )
-- toggle Always On Top option

setCheck( AlwaysOnTop, not isChecked(AlwaysOnTop) )

if isChecked( AlwaysOnTop ) then
moveZOrder( Main, HWND_TOPMOST )
else
moveZOrder( Main, HWND_NOTOPMOST )
end if

end procedure
setHandler( AlwaysOnTop, w32HClick, routine_id("AlwaysOnTop_Click") )
Timer, Paint, and Open/Close Event Procedures procedure onTimer_Main( atom this, atom id, atom event_type, atom event )
   refresh_window( {MainPanel,1} )
end procedure
set_event_handler( Main, -1, wxEVT_TIMER, routine_id( "onTimer_Main" ))

procedure onPaint_Main( atom this, atom id, atom event_type, atom event )
object t
atom dc
   dc = create(wxPaintDC, {MainPanel})
   t = date()
   drawBinaryTime( dc, t[4], t[5], t[6] )
   delete_instance( dc )
end procedure
set_event_handler( MainPanel, get_id(MainPanel), wxEVT_PAINT, routine_id( "onPaint_Main" ))
procedure Main_Timer( integer pSelf, integer pEvent, sequence pParams )
sequence dt
if pEvent = w32HPaint or (pEvent = w32HTimer and pParams[1] = 1) then
-- get the date/time
dt = date()
-- draw HH:MM:SS
drawBinaryTime( Main, dt[4], dt[5], dt[6] )
end if
end procedure
setHandler( Main, {w32HTimer, w32HPaint}, routine_id("Main_Timer") )

procedure Main_Open( integer pSelf, integer pEvent, sequence pParams )
setTimer( Main, 1, 1000 )
end procedure
setHandler( Main, w32HOpen, routine_id("Main_Open") )

procedure Main_Close( integer pSelf, integer pEvent, sequence pParams )
killTimer( Main, 1 )
end procedure
setHandler( Main, w32HClose, routine_id("Main_Close") )
Init and Main() check_menuitem( Amber, 1 )
start_timer( MyTimer, 1000, 0 )

wxMain( Main )
setCheck( Amber, w32True )
setIcon( Main, "binaryclock.ico" )

WinMain( Main, Normal )