1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| //---------------------------------------------------------------------------
#pragma hdrstop
#include "jListBox.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
__fastcall jListBox::jListBox(TComponent *Owner, TImage *BG)
: TCustomControl(Owner)
{
if(Owner->InheritsFrom(__classid(TWinControl)))
{
Parent = (TWinControl*)Owner;
BringToFront();
}
//Lien vers l'image d'arrière plan
BackGround = BG;
//Création d'un scrollbar pour le défilement des items
ScrollBar = new TScrollBar(this);
ScrollBar->Kind = sbVertical;
ScrollBar->Align = alLeft;
ScrollBar->Max = 0;
ScrollBar->OnChange = WhenScroll;
ScrollBar->Parent = this;
FItemIndex = -1;
Items = new TStringList;
OnMouseDown = WhenMouseDown;
}
//--
__fastcall jListBox::~jListBox()
{
Items->Clear();
delete Items;
}
//--
void __fastcall jListBox::Paint()
{
Canvas->Brush->Style = bsClear;
//Quelques variables
int we = Width;
int he = Height;
TRect Dest = Rect(0,0,we,he);
TRect Srce;
//Calcul des coordonnées de la portion d'image en arrière plan
Srce.Left = Left - BackGround->Left;
Srce.Top = Top - BackGround->Top;
Srce.Right = Srce.Left + we;
Srce.Bottom = Srce.Top + he;
//Copie du fond
Canvas->CopyRect(Dest, BackGround->Picture->Bitmap->Canvas, Srce);
Canvas->Font->Color = clBlack; //<<< Ici ça dépend !
//Ecriture des items
MaxItems = he / hauteur_image;
int item;
for(int j = 0; j < MaxItems; j++)
{
item = j + FTopIndex;
if(item < Items->Count)
{
Canvas->Draw(0, j * hauteur_image, (Graphics::TBitmap*)Items->Objects[ item] );
/*
if(item == FItemIndex)Canvas->Font->Style = Canvas->Font->Style << fsBold;
else Canvas->Font->Style = Canvas->Font->Style >> fsBold;
Canvas->TextOut(4, j * 16, Items->Strings[item]);*/
}
}
//Contour 3D
/*Canvas->Pen->Color = clWhite;
Canvas->MoveTo(0,he); Canvas->LineTo(0,0); Canvas->LineTo(we,0);
Canvas->Pen->Color = clBlack;
we--; he--;
Canvas->MoveTo(0,he); Canvas->LineTo(we,he); Canvas->LineTo(we,0);*/
}
void __fastcall jListBox::AddObject(AnsiString N, Graphics::TBitmap *Image)
{
Items->AddObject(N, Image);
ScrollBar->Max = Items->Count-1;
Repaint();
}
void __fastcall jListBox::WhenScroll(TObject *Sender)
{
FTopIndex = ScrollBar->Position;
Repaint();
}
void __fastcall jListBox::WhenMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
int n = Y / hauteur_image;
if(n < MaxItems)
{
n = n + FTopIndex;
if(n < Items->Count)
{
ItemIndex = n;
}
}
}
void __fastcall jListBox::SetItemIndex(int Value)
{
FItemIndex = Value;
Repaint();
}
void __fastcall jListBox::SetTopIndex(int Value)
{
if((Value >= 0) && Value < (Items->Count-1))
{
ScrollBar->Position = Value;
FTopIndex = Value;
Repaint();
}
} |
Partager