Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
AnasayfaAnasayfa  PortalliPortalli  AramaArama  Latest imagesLatest images  Kayıt OlKayıt Ol  Giriş yap  

 

 C++ analog saat bileşeni

Aşağa gitmek 
YazarMesaj
YohAsakura
Seviyeli Üye
Seviyeli Üye
YohAsakura


Mesaj Sayısı : 194
Yaş : 31
Şehir : Dobbie Willage
Kayıt tarihi : 04/08/06

C++ analog saat bileşeni Empty
MesajKonu: C++ analog saat bileşeni   C++ analog saat bileşeni Icon_minitimeÇarş. 9 Ağus. - 14:52

Horloge.h


#ifndef HorlogeH
#define HorlogeH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
//---------------------------------------------------------------------------
class PACKAGE THorloge : public TGraphicControl
{
private:
TTimer *Timer1;
Graphics::TBitmap *Image1;
bool FSec;
bool __fastcall CanResize(int &NewWidth, int &NewHeight);
protected:
void __fastcall Tempo(TObject* Owner);
void __fastcall Paint();
public:
__fastcall THorloge(TComponent* Owner);
virtual __fastcall ~THorloge();
__published:
__property Anchors;
__property ParentShowHint;
__property ShowHint;
__property Visible;

__property bool Seconde = {read=FSec, write=FSec, default=true};
};
//---------------------------------------------------------------------------
#endif











Horloge.cpp

#include <vcl.h>
#include <math.h> #pragma hdrstop
#include "Horloge.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
//

static inline void ValidCtrCheck(THorloge *)
{
new THorloge(NULL);
}
//---------------------------------------------------------------------------

__fastcall THorloge::THorloge(TComponent* Owner)
: TGraphicControl(Owner)
{
ControlStyle << csOpaque;
Image1 = new Graphics::TBitmap();
Timer1 = new TTimer(NULL);
Timer1->OnTimer = Tempo;
FSec=true;
Width = 120;
Height = 120;
Image1->Width = Width;
Image1->Height = Height;
}
//---------------------------------------------------------------------------
__fastcall THorloge::~THorloge()
{
delete Image1;
delete Timer1;
}
//---------------------------------------------------------------------------
bool __fastcall THorloge::CanResize(int &NewWidth, int &NewHeight)
{
NewWidth = 120;
NewHeight = 120;
return true;
}
//---------------------------------------------------------------------------
void __fastcall THorloge::Tempo(TObject* Sender)
{
Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall THorloge::Paint()
{
float n,z,u,x0,y0,x1,y1,x2,y2,x3,y3;
TDateTime heure;
TPoint points[4];
Word wHour, wMinute, wSeconde;

heure = Now();
DecodeTime(heure, wHour, wMinute, wSeconde, NULL);

// Couleur de fond.
Image1->Canvas->Brush->Color = Color;
Image1->Canvas->Pen->Color = Color;
Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height);

// Dessin du cercle.
Image1->Canvas->Pen->Color = clBlack;
Image1->Canvas->Pen->Width = 2;
Image1->Canvas->Ellipse(2,2,118,118);

// Dessin du texte.
Image1->Canvas->Font->Name = "Arial";
Image1->Canvas->Font->Color = clBlack;
Image1->Canvas->Font->Size = 8;
Image1->Canvas->TextOut( 50,80,"CGi");

Image1->Canvas->TextOut( 55,6,"12");
Image1->Canvas->TextOut( 58,101,"6");
Image1->Canvas->TextOut( 8,53,"9");
Image1->Canvas->TextOut( 105,53,"3");

Image1->Canvas->TextOut( 81,13,"1");
Image1->Canvas->TextOut( 97,30,"2");

Image1->Canvas->TextOut( 98,76,"4");
Image1->Canvas->TextOut( 81,94,"5");

Image1->Canvas->TextOut( 33,94,"7");
Image1->Canvas->TextOut( 15,76,"8");

Image1->Canvas->TextOut( 14,30,"10");
Image1->Canvas->TextOut( 32,13,"11");

Image1->Canvas->Pen->Width = 1;

// Dessin aiguille des secondes si FSec à true.
if (FSec)
{
n = wSeconde*200/60;
z = n/100*3.14159;
u = (n+50)/100*3.14159;

x0 = sin(z)*50;
y0 = -cos(z)*50;

x1 = -sin(z)*10;
y1 = cos(z)*10;

x2 = sin(u)*2;
y2 = -cos(u)*2;

x3 = -sin(u)*2;
y3 = cos(u)*2;

points[0] = Point(x1+60,y1+60);
points[1] = Point(x2+60,y2+60);
points[2] = Point(x0+60,y0+60);
points[3] = Point(x3+60,y3+60);

Image1->Canvas->Brush->Color = clRed;
Image1->Canvas->Polygon(points, 3);
}

// Dessin aiguille des minutes.
n = wMinute*200/60 + wSeconde*200/60/60;
z = n/100*3.14159;
u = (n+50)/100*3.14159;

x0 = sin(z)*50;
y0 = -cos(z)*50;

x1 = -sin(z)*10;
y1 = cos(z)*10;

x2 = sin(u)*4;
y2 = -cos(u)*4;

x3 = -sin(u)*4;
y3 = cos(u)*4;

points[0] = Point(x1+60,y1+60);
points[1] = Point(x2+60,y2+60);
points[2] = Point(x0+60,y0+60);
points[3] = Point(x3+60,y3+60);

Image1->Canvas->Brush->Color = clAqua;
Image1->Canvas->Polygon(points, 3);

// Dessin aiguille des heures.
n = wHour*200/12 + wMinute*200/60/12;
z = n/100*3.14159;
u = (n+50)/100*3.14159;

x0 = sin(z)*35;
y0 = -cos(z)*35;

x1 = -sin(z)*10;
y1 = cos(z)*10;

x2 = sin(u)*4;
y2 = -cos(u)*4;

x3 = -sin(u)*4;
y3 = cos(u)*4;

points[0] = Point(x1+60,y1+60);
points[1] = Point(x2+60,y2+60);
points[2] = Point(x0+60,y0+60);
points[3] = Point(x3+60,y3+60);

Image1->Canvas->Brush->Color = clYellow;
Image1->Canvas->Polygon(points, 3);

Canvas->Draw(0,0,Image1);
}
//---------------------------------------------------------------------------
namespace Horloge
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(THorloge)};
RegisterComponents("Beyaz", classes, 0);
}
}
Sayfa başına dön Aşağa gitmek
http://wapistan.forumup.com
 
C++ analog saat bileşeni
Sayfa başına dön 
1 sayfadaki 1 sayfası

Bu forumun müsaadesi var:Bu forumdaki mesajlara cevap veremezsiniz
 :: Diğer :: DownloaD-
Buraya geçin: