 |
Club Builder Foro de C++Builder en español
|
| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
victoronate Cdt

Registrado: 20 Sep 2002Mensajes: 4
|
Publicado: Vie 20 Sep, 2002 8:49 pm Asunto: graficar un arbol binario |
|
|
nece sito untutorial o informacion sobre la canvas en español  |
|
| Volver arriba |
|
 |
Trigger Lt


Registrado: 12 Ago 2002Mensajes: 88Ubicación: Barranquilla (Colombia)
|
Publicado: Jue 26 Sep, 2002 6:01 am Asunto: Claro con gusto |
|
|
Escribeme un email y te conste con un ejemplo en builder para pintar los arboles binarios  _________________
Trigger  |
|
| Volver arriba |
|
 |
Ruby Invitado
|
Publicado: Jue 01 Sep, 2005 12:32 am Asunto: Arboles |
|
|
Hola Trigger
me podrias orientar con lo de arboles, te lo agradecere mucho.
Ruby |
|
| Volver arriba |
|
 |
Lupo Ens

Registrado: 15 Ago 2005Mensajes: 30Ubicación: Prov, Buenos Aires - Argentina
|
Publicado: Jue 01 Sep, 2005 5:18 pm Asunto: |
|
|
Aca te paso uno que hice, pero es bastante precario, a ver si te sirve de ayuda...
| Código: |
const int ANCHO=60;
const int ALTO=40;
const int TAMTEXTO=12;
struct Dato
{
int indice;
int x,y;
char col;
};
struct nodo
{
struct nodo *izq;
struct Dato dato;
struct nodo *der;
};
int tempx, tempy;
int CursorY=36;
struct nodo *raiz=NULL;
struct Dato dato;
Graphics::TBitmap *Fondo;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
{
static bool PrimeraVez=true;
if(PrimeraVez)
{
Fondo = new Graphics::TBitmap;
Fondo->Width = Form1->Width;
Fondo->Height = Form1->Height;
Fondo->Canvas->Font->Color = clWhite;
Fondo->Canvas->Font->Size = TAMTEXTO;
Fondo->Canvas->Brush->Color = clBlack;
Fondo->Canvas->FillRect(ClientRect);
PrimeraVez=false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if(Key == VK_RETURN)
{
if(Edit1->Text != "")
{
if(Edit1->Text.ToInt() == 0) Application->Terminate();
dato.indice = Edit1->Text.ToInt();
raiz = creaarbol(raiz,dato);
if(raiz!=NULL)
{
Fondo->Canvas->Brush->Color = clBlack;
Fondo->Canvas->FillRect(ClientRect);
enorden(raiz);
}
}
Edit1->Text = "";
}
}
//---------------------------------------------------------------------------
struct nodo * __fastcall TForm1::nuevonodo(void)
{
struct nodo *p=NULL;
p=(struct nodo*)malloc(sizeof(struct nodo));
if(p==NULL)
{
ShowMessage("No hay memoria suficiente.");
Application->Terminate();
return NULL;
}
else
return p;
}
//---------------------------------------------------------------------------
struct nodo * __fastcall TForm1::creaarbol(struct nodo *r, struct Dato dat)
{
struct nodo *p, *q=r, *ant=NULL;
int sen;
int xant,yant;
p = nuevonodo();
p->izq = NULL;
p->der = NULL;
p->dato = dat;
if(r==NULL)
{
r = p;
r->dato.x=(Form1->Width/2)-(ANCHO/2);
r->dato.y=20;
r->dato.col=15;
}
else
{
xant = r->dato.x;
yant = r->dato.y;
while(q)
{
ant = q;
if(dat.indice > q->dato.indice)
{
q=q->der;
sen=1;
xant+=ANCHO+20;
yant+=ALTO+20;
}
else if(dat.indice < q->dato.indice)
{
q=q->izq;
sen=2;
xant-=ANCHO+20;
yant+=ALTO+20;
}
else
return r;
}
if(sen==2)
ant->izq=p;
else
ant->der=p;
p->dato.x=xant;
p->dato.y=yant;
p->dato.col=15;
}
return r;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::enorden(struct nodo *r)
{
if(r)
{
dibujar_nodo(r, tempx, tempy);
tempx = r->dato.x;
tempy = r->dato.y;
enorden(r->izq);
tempx = r->dato.x;
tempy = r->dato.y;
enorden(r->der);
tempx = r->dato.x;
tempy = r->dato.y;
}
};
//---------------------------------------------------------------------------
void __fastcall TForm1::dibujar_nodo(struct nodo *n, int X, int Y)
{
static bool primvez=true;
AnsiString tt = "";
tt = AnsiString((int)Canvas->Pixels[n->dato.x+1][n->dato.y]);
Fondo->Canvas->Brush->Color = clWhite;
Fondo->Canvas->FrameRect(Rect(n->dato.x, n->dato.y, n->dato.x+ANCHO, n->dato.y+ALTO));
if(!primvez)
{
if(X<n->dato.x)
{
Fondo->Canvas->Pen->Color = clBlue;
Fondo->Canvas->Pen->Width = 2;
Fondo->Canvas->PenPos = Point(X+ANCHO,Y+ALTO);
Fondo->Canvas->LineTo(n->dato.x, n->dato.y);
}
else if(X>n->dato.x)
{
Fondo->Canvas->Pen->Color = clRed;
Fondo->Canvas->Pen->Width = 2;
Fondo->Canvas->PenPos = Point(X, Y+ALTO);
Fondo->Canvas->LineTo(n->dato.x+ANCHO, n->dato.y);
}
}
primvez=false;
Fondo->Canvas->Brush->Color = clBlack;
TextoCentrado(Fondo->Canvas, n->dato.x+(ANCHO/2), n->dato.y+(ALTO/2)-TAMTEXTO+TAMTEXTO/4, AnsiString(n->dato.indice));
Canvas->Draw(0,0,Fondo);
Label1->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
Fondo->Width = Form1->Width;
Fondo->Height = Form1->Height;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
Canvas->Draw(0,0,Fondo);
Label1->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TextoCentrado(TCanvas *Destino, int x, int y, AnsiString texto)
{
x -= (Destino->TextWidth(texto)/2);
Destino->TextOut(x,y,texto);
}
|
_________________ Il Lupo |
|
| Volver arriba |
|
 |
Ruby Invitado
|
Publicado: Vie 02 Sep, 2005 10:33 pm Asunto: |
|
|
Gracias Lupo  |
|
| Volver arriba |
|
 |
|
|
No puedes publicar temas nuevos en este foro No puedes responder a temas en este foro No puedes editar tus mensajes en este foro No puedes borrar tus mensajes en este foro No puedes votar en las encuestas de este foro
|
© 2002–2026 Club Builder · Funciona con phpBB.
|