April 15, 2024, 10:13:05 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


IW Binary Clock

Started by GWS, January 10, 2012, 01:34:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

January 10, 2012, 01:34:43 PM Last Edit: January 11, 2012, 10:09:27 AM by GWS
Hi folks,

I've hit the buffers with this one ..  ::)

I'm trying to implement the CB version of my binary clock, but it's misbehaving badly.

I get flashes and flickers, no lit block sprites showing, resizing is abysmal, and awful things happen if I run WordPad over the top of the window.

Something is obviously very wrong, but I can't see what ..  ???

Any ideas appreciated ..

regards, :)

Graham

[Edit: thanks to Larry's suggestion I've modified the program in the attachment].
Tomorrow may be too late ..

LarryMc

This works but the alignment is off on my screen.

' Designed for re-sizeable 800x600 screen resolution ...
' GWS - January 2012 - IWB Binary Clock

window w
int spos[14,3],img1,i,b[10,5],run,style
int cmu,cmt,chu,cht,tmu,tmt,thu,tht
string a$,c[14]
pointer sp[14]
pointer spbg

autodefine "OFF"

style = @minbox|@maxbox|@size|@noautodraw
openwindow w,0,0,800,600,style,0,"IonicWind Binary Clock",&handler
if attachscreen(w,800,600) < 0 :' Direct X screen
messagebox w, "Error creating DirectX screen","Error"
closewindow w
end
endif

fillscreen 0x0
centerwindow w

' load background image ...
spbg = LoadSprite(GETSTARTPATH()+"back.jpg")
if (spbg = 0)
messagebox w, "Could not load the background image","Error"
closewindow w
end
endif

' load sprites ..
c[1] = "org1","org2","grn1","grn2","grn3","grn4"
c[7] = "blu1","blu2","blu3","red1","red2","red3","red4"

' set binary state flags ..
b[0,1] = 0: b[0,2] = 0: b[0,3] = 0: b[0,4] = 0
b[1,1] = 1: b[1,2] = 0: b[1,3] = 0: b[1,4] = 0
b[2,1] = 0: b[2,2] = 1: b[2,3] = 0: b[2,4] = 0
b[3,1] = 1: b[3,2] = 1: b[3,3] = 0: b[3,4] = 0
b[4,1] = 0: b[4,2] = 0: b[4,3] = 1: b[4,4] = 0
b[5,1] = 1: b[5,2] = 0: b[5,3] = 1: b[5,4] = 0
b[6,1] = 0: b[6,2] = 1: b[6,3] = 1: b[6,4] = 0
b[7,1] = 1: b[7,2] = 1: b[7,3] = 1: b[7,4] = 0
b[8,1] = 0: b[8,2] = 0: b[8,3] = 0: b[8,4] = 1
b[9,1] = 1: b[9,2] = 0: b[9,3] = 0: b[9,4] = 1


for i = 1 to 13
a$ = c[i] + ".bmp"
sp[i] = loadsprite(getstartpath + a$)
SpriteMaskColor sp[i], 0x0
SpriteDrawMode sp[i], @TRANS
next i

' set sprite positions ..
spos[1,1] = 57: spos[1,2] = 342
spos[2,1] = 92: spos[2,2] = 252
spos[3,1] = 210: spos[3,2] = 347
spos[4,1] = 224: spos[4,2] = 255
spos[5,1] = 239: spos[5,2] = 172
spos[6,1] = 248: spos[6,2] = 89
spos[7,1] = 443: spos[7,2] = 348
spos[8,1] = 425: spos[8,2] = 257
spos[9,1] = 407: spos[9,2] = 170
spos[10,1] = 598: spos[10,2] = 343
spos[11,1] = 559: spos[11,2] = 248
spos[12,1] = 527: spos[12,2] = 165
spos[13,1] = 497: spos[13,2] = 89

' set currently displayed hours and minutes ..
cmu = 0 : cmt = 0
chu = 0 : cht = 0

run = 1

do
update()
until run = 0

for i = 1 to 13
freesprite sp[i]
next i
freesprite spbg
closewindow w
end

sub handler(),int
select @CLASS
case @IDCLOSEWINDOW
    run = 0
endselect
return
endsub


sub update()
a$ = left$(time$,5)
tmu = val(mid$(a$,5,1)) : tmt = val(mid$(a$,4,1))
thu = val(mid$(a$,2,1)) : tht = val(left$(a$,1))

' set the display for the current time ..
drawsprite spbg

' update 'tmu' (minutes unit value)..
for i = 1 to 4
if (b[tmu,i] = 1)
movesprite sp[i+9], spos[i+9,1], spos[i+9,2]
drawsprite sp[i+9]
endif
next i

' update 'tmt' (minutes tens value)..
for i = 1 to 3
if (b[tmt,i] = 1)
movesprite sp[i+6], spos[i+6,1], spos[i+6,2]
drawsprite sp[i+6]
endif
next i

' update 'thu' (hours unit value)..
for i = 1 to 4
if (b[thu,i] = 1)
movesprite sp[i+2], spos[i+2,1], spos[i+2,2]
drawsprite sp[i+2]
endif
next i

' update 'tht' (hours tens value)..
for i = 1 to 2
if (b[tht,i] = 1)
movesprite sp[i], spos[i,1], spos[i,2]
drawsprite sp[i]
endif
next i

flip

return
endsub


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

Thanks Larry ..  ;D

I don't know what you did yet, but that's much better - I'll check it out when the Sun comes up -  but I think I can probably take it from there, it will be just a matter of positioning.

IWB is quite different from CB - I'm just trying to get used to it.

best wishes, :)

Graham
Tomorrow may be too late ..

LarryMc

Quote from: GWS on January 10, 2012, 06:56:40 PM
IWB is quite different from CB - I'm just trying to get used to it.

I have the same problem when trying to look at CB code. ;)

All I did was the things necessary to turn the background image into a sprite.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

I'm back ..  ;D

Thanks for looking at it Larry.  I've more or less got it working now, so I've uploaded it again in the first post.

I'm puzzled what's going on though. 

My idea of a sprite, is an image which moves about on top of other images.  It takes some graphics work to create one, and make it's background color suitable for selection as 'transparent'.  Otherwise, you'd see rectangles moving about as well as your carefully drawn 'aliens'.

Sprites usually float over a background picture - and this I've previously treated as a static image - at least in CB.  It's always worked OK before.

So although specifying the background image as a sprite does seem to solve the breakup problems that occur if it's loaded just as an image in IWB, I don't understand why.

The 'tearing' effects when another window (like Calculator for instance) is moved in front of the clock window, I've more or less solved by putting a WAIT statement in the update loop.

I also found a compile problem I wouldn't have expected.

In my event handler subroutine .. SUB handler() .. if I don't place a ,INT after the closing bracket, I get warnings that 'handler does not match the declaration of IWBWINPROC' .. 'different return type: none, should be int.'

So to keep it quiet, I have to use SUB handler(),int.

Then I get another warning about the RETURN statement .. 'WARNING: return value expected'.
So I have to put a '0' after RETURN to get rid of that.

This seems to be a bit of arm twisting, since I hadn't intended the handler subroutine to return anything.
If a subroutine is not returning anything, I would have thought the empty brackets .. SUB x() should have been enough.

Lastly, the clock window in CB is easily resized from fullscreen to small, maintaining the relative position and size of all sprites.  It takes no special coding on my part to achieve this - it just works.

The IWB version will resize the containing window, but leaves the background and sprite sizes unchanged - so you get large white areas at fullscreen for instance. This is not very satisfactory, so I've had to change the latest version to a fixed size window.

I imagine if I did a chunk more code to handle window resizing it would probably be able to emulate the CB version, but I don't see why this happens.  Some technical difference between the two systems I guess - but CB wins on that score.  ;)

So the project is a qualified success.

best wishes, :)

Graham









Tomorrow may be too late ..