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


Registrado: 09 Nov 2002Mensajes: 663
|
Publicado: Mie 16 Ene, 2019 12:37 am Asunto: Enviar parámetro |
|
|
Hola, tengo la siguiente función:
| Código: |
void __fastcall TCustomPanel::Paint(void)
{
TRect rect = GetClientRect();
PintarDegradadoH(Canvas, rect, clBlue, clBlack, 64);
}
|
Mi pregunta es cómo le puedo enviar los valores clBlue y clBlack o cualquier otro color a través de código.
Gracias por anticipado. _________________ ¡ADELANTE CON ESTE SUPER FORO! |
|
| Volver arriba |
|
 |
Alpinador Lt Cmdr

Registrado: 21 Abr 2014Mensajes: 123
|
Publicado: Mie 16 Ene, 2019 12:35 pm Asunto: |
|
|
no entiendo muy bien que cosa quieres hacer pero para obtener un color dado tienes RGB(0, 255, 0);
donde esos 3 valores del 0 al 255 indican la combinacion del color que quieres conseguir
clLime, clBlack, clBlue etc son como unas macros-nombre definidas por Rad Studio ya con unos colores concretos y por defecto conocidos
las propiedades color almacenan los colores con este formato $000080FF (color naranja) con el simbolo del dolar delante y luego un valor hexadecimal
si lo que quieres en enviarlo a una funcion tienes que definir los argumentos de la funcion o el tipo de dato con la clase TColor
por ejemplo
| Código: | TColor devuelve_color(void)
{
return(clLime);
}
por ponerlo en plan sencillo |
TColor is used to specify the color of an object.
Unit
Graphics
enum TColor {clMin=-0x7fffffff-1, clMax=0x7fffffff};
Description
TColor is used to specify the color of an object. It is used by the Color property of many components and by a number of other properties that specify color values.
The Graphics unit contains definitions of useful constants for TColor. These constants map either directly to the closest matching color in the system palette (for example, clBlue maps to blue) or to the corresponding system screen element color defined in the Color section of the Windows Control panel (for example, clBtnFace maps to the system color for button faces).
If you specify TColor as a specific 4-byte hexadecimal number instead of using the constants defined in the Graphics unit, the low three bytes represent RGB color intensities for blue, green, and red, respectively. The value $00FF0000 represents full-intensity, pure blue, $0000FF00 is pure green, and $000000FF is pure red. $00000000 is black and $00FFFFFF is white.
If the highest-order byte is zero ($00), the color obtained is the closest matching color in the system palette. If the highest-order byte is one ($01), the color obtained is the closest matching color in the currently realized palette. If the highest-order byte is two ($02), the value is matched with the nearest color in the logical palette of the current device context.
The following tables lists the color constants from the Graphics unit. The first two columns list the colors that map to the closest matching color in the system palette, while the last two columns list the colors that are defined in the Windows Control panel.
Ultima edición por Alpinador el Mie 16 Ene, 2019 5:38 pm, editado 2 veces |
|
| Volver arriba |
|
 |
Alpinador Lt Cmdr

Registrado: 21 Abr 2014Mensajes: 123
|
Publicado: Mie 16 Ene, 2019 5:16 pm Asunto: |
|
|
te dejo este codigo que cambia el color del form con un TTimer
por si te aclara un poco el tema quisquilloso del TColor
Seguramente Escafandra o Leo sabran hacerlo de forma mas optimizada y elegante......jejejej
| Código: | //---------------------------------------------------------------------------
#include <vcl.h>
#include <stdlib.h>
#include <stdio.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
int color = 0;
AnsiString color_final = "$00";
AnsiString color2;
color = RGB(rand()%254, rand()%254, rand()%254);
color2 = IntToStr(color);
color_final = color_final + color2;
Form1->Color = StringToColor(color_final);
}
//--------------------------------------------------------------------------- |
|
|
| Volver arriba |
|
 |
Tugui Master


Registrado: 09 Nov 2002Mensajes: 663
|
Publicado: Mie 16 Ene, 2019 8:06 pm Asunto: |
|
|
Gracias Alpinador pero no es eso exactamente, estoy utilizando dos funciones que trabajan juntas para pintar un degradado en un panel y quiero que el usuario pueda cambiar esos colores desde otro formulario, las funciones son las siguientes:
| Código: |
void PintarDegradadoH(TCanvas *canvas, TRect& rect, TColor c1, TColor c2,
int nTonos)
{
c1 = static_cast<TColor>( ColorToRGB(c1) );
c2 = static_cast<TColor>( ColorToRGB(c2) );
int Rf = GetRValue(c1), Gf=GetGValue(c1), Bf=GetBValue(c1);
int Rd = GetRValue(c2)-Rf, Gd=GetGValue(c2)-Gf, Bd=GetBValue(c2)-Bf;
int R, G, B;
float incremento = (float)nTonos / rect.Height();
for (int i=0; i<rect>Pen->Color = (TColor) RGB(R, G, B);
canvas->MoveTo(rect.left, rect.top+i);
canvas->LineTo(rect.right, rect.top+i);
}
}
|
y la que llama a la anterior para pintar el degradado es esta:
| Código: |
void __fastcall TCustomPanel::Paint(void)
{
TRect rect = GetClientRect();
PintarDegradadoH(Canvas, rect, clBlue, clBlack, 64);
}
|
Entonces quisiera saber, si hay alguna forma de pasar los valores de color a ésta última función, estoy probando con un archivo .ini pero no logro acceder a la función. Gracias de nuevo. _________________ ¡ADELANTE CON ESTE SUPER FORO! |
|
| Volver arriba |
|
 |
Tugui Master


Registrado: 09 Nov 2002Mensajes: 663
|
Publicado: Mie 16 Ene, 2019 10:41 pm Asunto: |
|
|
Ya está ya lo he conseguido, he guardado los colores en un archivo .ini y al abrir la aplicación leo el archivo ini y cargo los colores uno y dos en los valores TColor de la función PintarDegradado, así de sencillo. Muchas gracias . _________________ ¡ADELANTE CON ESTE SUPER FORO! |
|
| 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.
|