Author Topic: Static Buttons  (Read 2172 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Static Buttons
« on: February 11, 2011, 03:30:05 PM »
Deleted
« Last Edit: April 11, 2015, 08:59:58 AM by Peter »

Charles Pegge

  • Guest
Re: Static Buttons
« Reply #1 on: February 12, 2011, 04:28:40 AM »
Thanks Peter.

Just for fun I OOPified your program. If you have many buttons and other objects it helps to keep them in good order. (as the theory goes :) )

Code: [Select]
include "Func.inc"

Dim hdc, clk, mx, px, py, wy as long
Dim a as single
Dim msg as string 

SetWindow "Button Static",640,480,ws_dlgframe
hdc=BufferDC
SetFont hdc,8,14,fw_bold,"times"
px=320 : py=240


Function DrawRectangle(byval hdc as long, byval x0 as long, byval y0 as long, byval x1 as long, byval y1 as long ,byval color as long)
Long x, y
For y=0 To y1
For x=0 To x1
SetPixel hdc,x0+x,y0+y,color
Next
Next
End Function

Sub Delay(byval time as long)
Long Tick, cTime 
cTime = timeGetTime
Tick = cTime + time
While  Tick > cTime
cTime = timeGetTime
Wend
End Sub

Sub Quader(byval x1 as long, byval y1 as long, byval hx as long, byval hy as long)
DrawCircle hdc, x1, y1, 3, &hFF0000
DrawCircle hdc, x1,y1+hy,3,&hFF0000
DrawCircle hdc, x1+hx,y1+hy,3,&hFF0000
DrawCircle hdc, x1+hx, y1,3,&hFF0000
DrawBox hdc, x1, y1, hx, hy,&h00FF00
End Sub

'-----------
class button
'===========

long x0,y0,w0,h0
string txt

method constructor(byval px as long, byval py as long, byval pw as long, byval ph as long, byval tx as string)
  txt=tx : x0=px : y0=py : w0=pw : h0=ph 
  iF Len(txt) > w0/10 Then txt ="!"
  draw()
end method

method destructor()
end method

method msg(t as string)
  txt=t
end method

method draw()
  DrawRectangle hdc,x0,y0,w0,h0,255
  DrawLine hdc,x0,y0,x0+w0,y0,&hFAFAFA
  DrawLine hdc,x0,y0,x0,y0+h0,&hFAFAFA
  DrawLine hdc,x0+w0,y0,x0+w0,y0+h0,&h404040
  DrawLine hdc,x0,y0+h0,x0+w0,y0+h0,&h404040
  DrawText hdc,txt,x0+5+(w0-Len(txt)*10)\2,y0+((h0-16)\2),&hFF0000
end method

method pressed() as long
  iF MouseClick() =1 And MouseX >=x0 And MouseX <=x0+w0 And MouseY >=y0 And MouseY <=y0+h0
  DrawLine hdc, x0,y0,x0+w0,y0,&h404040
  DrawLine hdc, x0,y0,x0,y0+h0,&h404040
  DrawLine hdc, x0+w0,y0,x0+w0,y0+h0,&hFAFAFA
  DrawLine hdc, x0,y0+h0,x0+w0,y0+h0,&hFAFAFA
  Function =1
End iF
end method

end class

 
new button ButtonA 32, 72, 68, 16,"Quader"
new button ButtonB 32, 90, 68, 16,"Stop!"
new button ButtonC 280,400,128,32,"Home"
new Button ButtonD 280,68, 256,38,""


While WinExit =0
ClearBuffer &h669ddb
buttonA.draw : buttonB.draw : buttonC.draw : buttonD.draw
if buttonC.pressed then WinExit=1
if buttonD.pressed then buttonD.msg "THANK YOU!" else buttonD.msg "BUTTON FOR YOU!"
iF ButtonB.pressed Then clk=0 
Quader mx,200,80,64
DrawCircle hdc, px,py,  a,&hFFFF00
DrawCircle hdc, px,py+2,a,&hFFA000
DrawCircle hdc, px,py-2,a,&hFF6400
iF ButtonA.pressed Then clk=1
iF clk=1
iF a <=120 Then a += 1.0
mx = mx +6
iF mx >=640-8 Then mx=0
End iF
DoEvents
FlipBuffer
Delay (10)
Wend

del buttonA : del buttonB : del buttonC : del buttonD

WinEnd