Colors/es: what changed
Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | # Descripción | |
| 2 | 2 | ||
| 3 | 3 | En el LCL TColor es el tipo estandar para color. Es compatible con TColor de Delphi. TColor puede representar cualquiera de los dos *either', tanto' un valor RGB (3x8bit), o*or'' un color de sistema **system** tal como **clDefault**. El LCL puede trabajar además con el fpImage system que utiliza el tipo TFPColor (el cual es RGBA (4x16bit), no RGB (3x8bit) como TColor). | |
| 4 | 4 | ||
| 5 | 5 | En referencia a este tema de los colores nos puede resultar de utilidad este pequeño programa [Lazarus Color Picker (lcolorpicker)](http://lcolorpicker.sourceforge.net/) | |
| 6 | 6 | ||
| 7 | 7 | RGB = Red (rojo) Green (verde) Blue (azul). | |
| 8 | 8 | ||
| 9 | 9 | ## Conversiones entre valores TColor y RGB | |
| 10 | 10 | ||
| 11 | 11 | La unit **Graphics** aporta las siguientes funciones: | |
| 12 | 12 | ||
| 13 | 13 | ``` pascal | |
| 14 | 14 | function Blue(rgb: TColor): BYTE; // does not work on system color | |
| 15 | 15 | function Green(rgb: TColor): BYTE; // does not work on system color | |
| 16 | 16 | function Red(rgb: TColor): BYTE; // does not work on system color | |
| 17 | 17 | function RGBToColor(R, G, B: Byte): TColor; | |
| 18 | 18 | procedure RedGreenBlue(rgb: TColor; out Red, Green, Blue: Byte); // does not work on system color | |
| 19 | 19 | function FPColorToTColor(const FPColor: TFPColor): TColor; | |
| 20 | 20 | function TColorToFPColor(const c: TColor): TFPColor; // does not work on system color | |
| 21 | 21 | function IsSysColor(AColor: TColorRef): Boolean; | |
| 22 | 22 | ``` | |
| 23 | 23 | ||
| 24 | 24 | ## Convertir TColor hacia/desde una cadena | |
| 25 | 25 | ||
| 26 | 26 | Funciones para convertir cadenas tales como "25500" o "\$AA0088" o "clNavy" a TColor: | |
| 27 | 27 | ||
| 28 | 28 | - StringToColor | |
| 29 | 29 | - StringToColorDef | |
| 30 | 30 | ||
| 31 | 31 | Para convertir TColor a una cadena agradable: | |
| 32 | 32 | ||
| 33 | 33 | - ColorToString | |
| 34 | 34 | ||
| 35 | 35 | # Tabla de colores estandar | |
| 36 | 36 | ||
| 37 | 37 | Se proveen 20 constantes de colores predefinidos, los cuales son compatibles con Delphi: | |
| 38 | 38 | ||
| 39 | 39 | | Constante de Color | Significado | Valor hexadecimal para usar con TColor | Ejemplo | | |
| 40 | 40 | |----|----|----|----| | |
| 41 | 41 | | clBlack | Black | TColor(\$000000); | | | |
| 42 | 42 | | clMaroon | Maroon | TColor(\$000080); | | | |
| 43 | 43 | | clGreen | Green | TColor(\$008000); | | | |
| 44 | 44 | | clOlive | Olive Green | TColor(\$008080); | | | |
| 45 | 45 | | clNavy | Navy Blue | TColor(\$800000); | | | |
| 46 | 46 | | clPurple | Purple | TColor(\$800080); | | | |
| 47 | 47 | | clTeal | Teal | TColor(\$808000); | | | |
| 48 | 48 | | clGray | Grey | TColor(\$808080); | | | |
| 49 | 49 | | clSilver | Silver | TColor(\$C0C0C0); | | | |
| 50 | 50 | | clRed | Red | TColor(\$0000FF); | | | |
| 51 | 51 | | clLime | Lime Green | TColor(\$00FF00); | | | |
| 52 | 52 | | clYellow | Yellow | TColor(\$00FFFF); | | | |
| 53 | 53 | | clBlue | Blue | TColor(\$FF0000); | | | |
| 54 | 54 | | clFuchsia | Fuchsia | TColor(\$FF00FF); | | | |
| 55 | 55 | | clAqua | Aqua | TColor(\$FFFF00); | | | |
| 56 | 56 | | clLtGray | Light Grey | TColor(\$C0C0C0); | clSilver alias | | |
| 57 | 57 | | clDkGray | Dark Grey | TColor(\$808080); | clGray alias | | |
| 58 | 58 | | clWhite | White | TColor(\$FFFFFF); | | | |
| 59 | 59 | | clCream | Cream | TColor(\$F0FBFF); | Lazarus 1.2 and newer | | |
| 60 | 60 | | clMedGray | Medium Grey | TColor(\$A4A0A0); | Lazarus 1.2 and newer | | |
| 61 | 61 | | clMoneyGreen | Mint Green | TColor(\$C0DCC0); | Lazarus 1.2 and newer | | |
| 62 | 62 | | clSkyBlue | Sky Blue | TColor(\$F0CAA6); | Lazarus 1.2 and newer | | |
| 63 | 63 | ||
| 64 | 64 | # System colors | |
| 65 | 65 | ||
| 66 | 66 | ## Ejemplo: clInfoBk, clInfoText | |
| 67 | 67 | ||
| 68 | 68 | Los colores de sistema son colores constantes con un significado especial. Su valor real depende del contexto y tema. No son colores simples. | |
| 69 | 69 | ||
| 70 | 70 | Por ejemplo **clInfoBk**: | |
| 71 | 71 | ||
| 72 | 72 | ``` pascal | |
| 73 | 73 | Form1.Canvas.Brush.Color:=clInfoBk; // Utiliza la brocha por defecto del fondo de una ventana de sugerencia. | |
| 74 | 74 | Form1.Canvas.FillRect(10,10,50,50); | |
| 75 | 75 | ``` | |
| 76 | 76 | ||
| 77 | 77 | Una ventana de sugerencia en MS Windows debería tener un fondo blanco por lo que lo siguiente se dibujará en blanco. En Linux/GTK2 puede que tenga una textura metálica, por lo que lo siguiente dibujará la textura. Si necesitas poner algo de texto dentro entonces necesitas un color adecuado como **clInfoText**, de otra forma el texto puede resultar ilegible por parte del ususario. Por ejemplo: | |
| 78 | 78 | ||
| 79 | 79 | ``` pascal | |
| 80 | 80 | Form1.Canvas.Brush.Color:=clInfoBk; // Utiliza el color de brocha para fondo de una ventana de sugerencia. | |
| 81 | 81 | Form1.Canvas.FillRect(10,10,50,50); | |
| 82 | 82 | Form1.Canvas.Font.Color:=clInfoText; // Utiliza el color de texto por defecto de una ventana de sugerencia. | |
| 83 | 83 | Form1.Canvas.TextOut(10,10,'Hint'); | |
| 84 | 84 | ``` | |
| 85 | 85 | ||
| 86 | 86 | El color de sistema **clInfoBk** no se puede utilizar para **Pen.Color** ni para Font.Color. Si lo utilizas el resultado no está definido y depende tanto del widgetset como del tema del usuario. Lo mismo para **clInfoText**: Solamente puede utilizarse como Font.Color. Utilizarlo para **Brush.Color** puede que no funcione. Hasta el momento, todos los widgetsets permiten utilizarlo con **Pen.Color** también. | |
| 87 | 87 | ||
| 88 | 88 | Por ejemplo un listado de colores y su aspecto visible utilizado en fuentes: | |
| 89 | 89 | ||
| 90 | - | ||
| 90 | + |  | |
| 91 | 91 | ||
| 92 | 92 | ## Cambios de Tema | |
| 93 | 93 | ||
| 94 | 94 | Cuando el usuario cambia el tema, los colores de sistema también cambian. Un **clInfoBk** puede cambiar de blanco a azul de un color a una textura. Este cambio tendrá lugar cuando habilites un nuevo manejador de brocha (brush). Ten en cuenta que una simple asignación como Brush.Color:=clInfoBk no habilita un manejador de brocha. El manejador de brocha se habilita en uso. Por ejemplo: | |
| 95 | 95 | ||
| 96 | 96 | ``` pascal | |
| 97 | 97 | Form1.Canvas.Brush.Color:=clInfoBk; // Esto no creará un nuevo manejador de brocha. | |
| 98 | 98 | Form1.Canvas.FillRect(10,10,50,50); // Esto creará el manejador de brocha con la actual brocha del tema activo para ventanas de sugerencia. | |
| 99 | 99 | ... | |
| 100 | 100 | // Si el tema cambia en este momento el Brush.Handle está todavía establecido con los valores antiguos. | |
| 101 | 101 | ... | |
| 102 | 102 | Form1.Canvas.FillRect(10,10,50,50); // Esto pintará con la brocha del tema anterior. | |
| 103 | 103 | Form1.Canvas.Brush.Color:=clInfoBk; // Asignando el valor antiguo no creará un nuevo manejador de brocha. | |
| 104 | 104 | Form1.Canvas.FillRect(10,10,50,50); // Esto pintará con la brocha del tema anterior. | |
| 105 | 105 | Form1.Canvas.Brush.Color:=clRed; // Asignando un color nuevo, invalida manejador (handle) anterior. | |
| 106 | 106 | Form1.Canvas.Brush.Color:=clInfoBk; // Asignando un color nuevo, invalida manejador (handle) anterior. | |
| 107 | 107 | Form1.Canvas.FillRect(10,10,50,50); // Esto creará un nuevo manejador y pintará con el nuevo tema. | |
| 108 | 108 | ``` | |
| 109 | 109 | ||
| 110 | 110 | ## Tabla de colores del sistema | |
| 111 | 111 | ||
| 112 | 112 | La siguente tabla lista los colores del sistema y su significado. Utilizarlos fuera de lo especificado en la definición no estaría definido y el resultado obtenido depende del widgetset y del tema. Por ejemplo **clDefault** es el color de fondo para la brocha (brush) en el contexto de dispositivo utilizado. Si lo que necesitas es pintar elementos tipo button en tus propios controles personalizados entonces utiliza las funciones de la unidad **Themes**. | |
| 113 | 113 | ||
| 114 | 114 | **Constant** | |
| 115 | 115 | ||
| 116 | 116 | **Definición LCL** | |
| 117 | 117 | ||
| 118 | 118 | **Notas Delphi** | |
| 119 | 119 | ||
| 120 | 120 | **Widgetsets Soportados** | |
| 121 | 121 | ||
| 122 | 122 | clNone | |
| 123 | 123 | ||
| 124 | 124 | Indicates "do not paint". Utilizarlos como color de Control no esta definido. El control no será transparente. | |
| 125 | 125 | ||
| 126 | 126 | \- | |
| 127 | 127 | ||
| 128 | 128 | todos | |
| 129 | 129 | ||
| 130 | 130 | clDefault | |
| 131 | 131 | ||
| 132 | 132 | Using it for Brush will use the normal background brush of the target DC (device context). | |
| 133 | 133 | ||
| 134 | 134 | - On a Form's canvas a *FillRect* will paint a rectangular area filled with the normal background of a standard window. This is whatever the widgetset and theme defines. This might be the color gray or a gradient or a picture. | |
| 135 | 135 | - Using clDefault on the Canvas of a TListBox will paint with the normal background, which is normally white on Windows. So in a TListBox clDefault is the same as clWindow. | |
| 136 | 136 | - Using it as Pen color will use the default line color for the device context. | |
| 137 | 137 | - Using it as Font color will use the normal text color of the device context. | |
| 138 | 138 | ||
| 139 | 139 | \| - | |
| 140 | 140 | ||
| 141 | 141 | all | |
| 142 | 142 | ||
| 143 | 143 | clScrollBar | |
| 144 | 144 | ||
| 145 | 145 | Scrollbar body | |
| 146 | 146 | ||
| 147 | 147 | \- | |
| 148 | 148 | ||
| 149 | 149 | all | |
| 150 | 150 | ||
| 151 | 151 | clBackground | |
| 152 | 152 | ||
| 153 | 153 | ? | |
| 154 | 154 | ||
| 155 | 155 | \- | |
| 156 | 156 | ||
| 157 | 157 | all | |
| 158 | 158 | ||
| 159 | 159 | clActiveCaption | |
| 160 | 160 | ||
| 161 | 161 | Active window titlebar | |
| 162 | 162 | ||
| 163 | 163 | \- | |
| 164 | 164 | ||
| 165 | 165 | none | |
| 166 | 166 | ||
| 167 | 167 | clInactiveCaption | |
| 168 | 168 | ||
| 169 | 169 | Inactive window titlebar | |
| 170 | 170 | ||
| 171 | 171 | \- | |
| 172 | 172 | ||
| 173 | 173 | none | |
| 174 | 174 | ||
| 175 | 175 | clMenu | |
| 176 | 176 | ||
| 177 | 177 | Regular menu item background color | |
| 178 | 178 | ||
| 179 | 179 | \- | |
| 180 | 180 | ||
| 181 | 181 | none | |
| 182 | 182 | ||
| 183 | 183 | clWindow | |
| 184 | 184 | ||
| 185 | 185 | The normal background brush of unselected text. Defined for controls like TEdit, TComboBox, TMemo, TListBox, TTreeView. | |
| 186 | 186 | ||
| 187 | 187 | \- | |
| 188 | 188 | ||
| 189 | 189 | none | |
| 190 | 190 | ||
| 191 | 191 | clWindowFrame | |
| 192 | 192 | ||
| 193 | 193 | Color of frame around the window | |
| 194 | 194 | ||
| 195 | 195 | \- | |
| 196 | 196 | ||
| 197 | 197 | none | |
| 198 | 198 | ||
| 199 | 199 | clMenuText | |
| 200 | 200 | ||
| 201 | 201 | The font color to use together with clMenu | |
| 202 | 202 | ||
| 203 | 203 | \- | |
| 204 | 204 | ||
| 205 | 205 | none | |
| 206 | 206 | ||
| 207 | 207 | clWindowText | |
| 208 | 208 | ||
| 209 | 209 | Font color to use together with clWindow | |
| 210 | 210 | ||
| 211 | 211 | \- | |
| 212 | 212 | ||
| 213 | 213 | none | |
| 214 | 214 | ||
| 215 | 215 | clCaptionText | |
| 216 | 216 | ||
| 217 | 217 | Active window titlebar text color | |
| 218 | 218 | ||
| 219 | 219 | \- | |
| 220 | 220 | ||
| 221 | 221 | none | |
| 222 | 222 | ||
| 223 | 223 | clActiveBorder | |
| 224 | 224 | ||
| 225 | 225 | ? | |
| 226 | 226 | ||
| 227 | 227 | \- | |
| 228 | 228 | ||
| 229 | 229 | none | |
| 230 | 230 | ||
| 231 | 231 | clInactiveBorder | |
| 232 | 232 | ||
| 233 | 233 | ? | |
| 234 | 234 | ||
| 235 | 235 | \- | |
| 236 | 236 | ||
| 237 | 237 | none | |
| 238 | 238 | ||
| 239 | 239 | clAppWorkspace | |
| 240 | 240 | ||
| 241 | 241 | MDIMain form background | |
| 242 | 242 | ||
| 243 | 243 | \- | |
| 244 | 244 | ||
| 245 | 245 | none | |
| 246 | 246 | ||
| 247 | 247 | clHighlight | |
| 248 | 248 | ||
| 249 | 249 | The brush color of selected element | |
| 250 | 250 | ||
| 251 | 251 | \- | |
| 252 | 252 | ||
| 253 | 253 | none | |
| 254 | 254 | ||
| 255 | 255 | clHighlightText | |
| 256 | 256 | ||
| 257 | 257 | Font color of selected text (to use together with clHighligh). | |
| 258 | 258 | ||
| 259 | 259 | \- | |
| 260 | 260 | ||
| 261 | 261 | none | |
| 262 | 262 | ||
| 263 | 263 | clBtnFace | |
| 264 | 264 | ||
| 265 | 265 | Button background | |
| 266 | 266 | ||
| 267 | 267 | \- | |
| 268 | 268 | ||
| 269 | 269 | none | |
| 270 | 270 | ||
| 271 | 271 | clBtnShadow | |
| 272 | 272 | ||
| 273 | 273 | Button shadow color (bottom right) used to achieve 3D effect | |
| 274 | 274 | ||
| 275 | 275 | \- | |
| 276 | 276 | ||
| 277 | 277 | none | |
| 278 | 278 | ||
| 279 | 279 | clGrayText | |
| 280 | 280 | ||
| 281 | 281 | The font color of disabled element | |
| 282 | 282 | ||
| 283 | 283 | \- | |
| 284 | 284 | ||
| 285 | 285 | none | |
| 286 | 286 | ||
| 287 | 287 | clBtnText | |
| 288 | 288 | ||
| 289 | 289 | Button font color to use together with clBtnFace | |
| 290 | 290 | ||
| 291 | 291 | \- | |
| 292 | 292 | ||
| 293 | 293 | none | |
| 294 | 294 | ||
| 295 | 295 | clInactiveCaptionText | |
| 296 | 296 | ||
| 297 | 297 | Inactive window titlebar text color | |
| 298 | 298 | ||
| 299 | 299 | \- | |
| 300 | 300 | ||
| 301 | 301 | none | |
| 302 | 302 | ||
| 303 | 303 | clBtnHighlight | |
| 304 | 304 | ||
| 305 | 305 | Button highlight color (top left) used to achieve 3D effect | |
| 306 | 306 | ||
| 307 | 307 | \- | |
| 308 | 308 | ||
| 309 | 309 | none | |
| 310 | 310 | ||
| 311 | 311 | cl3DDkShadow | |
| 312 | 312 | ||
| 313 | 313 | ? | |
| 314 | 314 | ||
| 315 | 315 | \- | |
| 316 | 316 | ||
| 317 | 317 | none | |
| 318 | 318 | ||
| 319 | 319 | cl3DLight | |
| 320 | 320 | ||
| 321 | 321 | ? | |
| 322 | 322 | ||
| 323 | 323 | \- | |
| 324 | 324 | ||
| 325 | 325 | none | |
| 326 | 326 | ||
| 327 | 327 | clInfoText | |
| 328 | 328 | ||
| 329 | 329 | Font color for hints. Use together with clInfoBk | |
| 330 | 330 | ||
| 331 | 331 | \- | |
| 332 | 332 | ||
| 333 | 333 | all | |
| 334 | 334 | ||
| 335 | 335 | clInfoBk | |
| 336 | 336 | ||
| 337 | 337 | Brush color for hints. Use together with clInfoText | |
| 338 | 338 | ||
| 339 | 339 | \- | |
| 340 | 340 | ||
| 341 | 341 | all | |
| 342 | 342 | ||
| 343 | 343 | clHotLight | |
| 344 | 344 | ||
| 345 | 345 | ? | |
| 346 | 346 | ||
| 347 | 347 | \- | |
| 348 | 348 | ||
| 349 | 349 | none | |
| 350 | 350 | ||
| 351 | 351 | clGradientActiveCaption | |
| 352 | 352 | ||
| 353 | 353 | The second color used to make gradient of active window titlebar | |
| 354 | 354 | ||
| 355 | 355 | \- | |
| 356 | 356 | ||
| 357 | 357 | none | |
| 358 | 358 | ||
| 359 | 359 | clGradientInactiveCaption | |
| 360 | 360 | ||
| 361 | 361 | The second color used to make gradient for inactive window titlebar | |
| 362 | 362 | ||
| 363 | 363 | \- | |
| 364 | 364 | ||
| 365 | 365 | none | |
| 366 | 366 | ||
| 367 | 367 | clMenuHighlight | |
| 368 | 368 | ||
| 369 | 369 | The background color of selected menu item | |
| 370 | 370 | ||
| 371 | 371 | \- | |
| 372 | 372 | ||
| 373 | 373 | none | |
| 374 | 374 | ||
| 375 | 375 | clMenuBar | |
| 376 | 376 | ||
| 377 | 377 | The Backround color of menu bar | |
| 378 | 378 | ||
| 379 | 379 | \- | |
| 380 | 380 | ||
| 381 | 381 | none | |
| 382 | 382 | ||
| 383 | 383 | clForm | |
| 384 | 384 | ||
| 385 | 385 | ? | |
| 386 | 386 | ||
| 387 | 387 | \- | |
| 388 | 388 | ||
| 389 | 389 | none | |
| 390 | 390 | ||
| 391 | 391 | clColorDesktop | |
| 392 | 392 | ||
| 393 | 393 | ? | |
| 394 | 394 | ||
| 395 | 395 | \- | |
| 396 | 396 | ||
| 397 | 397 | none | |
| 398 | 398 | ||
| 399 | 399 | cl3DFace | |
| 400 | 400 | ||
| 401 | 401 | ? | |
| 402 | 402 | ||
| 403 | 403 | \- | |
| 404 | 404 | ||
| 405 | 405 | none | |
| 406 | 406 | ||
| 407 | 407 | cl3DShadow | |
| 408 | 408 | ||
| 409 | 409 | ? | |
| 410 | 410 | ||
| 411 | 411 | \- | |
| 412 | 412 | ||
| 413 | 413 | none | |
| 414 | 414 | ||
| 415 | 415 | cl3DHiLight | |
| 416 | 416 | ||
| 417 | 417 | ? | |
| 418 | 418 | ||
| 419 | 419 | \- | |
| 420 | 420 | ||
| 421 | 421 | none | |
| 422 | 422 | ||
| 423 | 423 | clBtnHiLight | |
| 424 | 424 | ||
| 425 | 425 | Same as clBtnHighlight | |
| 426 | 426 | ||
| 427 | 427 | \- | |
| 428 | 428 | ||
| 429 | 429 | none | |
| 430 | 430 | ||
| 431 | 431 | # Dibujando theme elements en tus controles personalizados | |
| 432 | 432 | ||
| 433 | 433 | La unidad **Themes** aporta funciones para dibujar elementos individuales de controles estandar. Por ejemplo, para dibujar un signo de expansión como un TTreeView utiliza el siguiente código: | |
| 434 | 434 | ||
| 435 | 435 | ``` pascal | |
| 436 | 436 | uses Themes; | |
| 437 | 437 | ||
| 438 | 438 | ... | |
| 439 | 439 | ||
| 440 | 440 | procedure TYourCustomControl.Paint; | |
| 441 | 441 | const | |
| 442 | 442 | PlusMinusDetail: array[Boolean {Hot}, Boolean {Expanded}] of TThemedTreeview = | |
| 443 | 443 | ( | |
| 444 | 444 | (ttGlyphClosed, ttGlyphOpened), | |
| 445 | 445 | (ttHotGlyphClosed, ttHotGlyphOpened) | |
| 446 | 446 | ); | |
| 447 | 447 | var | |
| 448 | 448 | Details: TThemedElementDetails; | |
| 449 | 449 | R: TRect; | |
| 450 | 450 | Collapse: boolean; | |
| 451 | 451 | begin | |
| 452 | 452 | ... | |
| 453 | 453 | //draw a themed expand sign. | |
| 454 | 454 | Details := ThemeServices.GetElementDetails(PlusMinusDetail[False, Collapse]); | |
| 455 | 455 | R := Rect(ALeft, ATop, ARight + 1, ABottom + 1); | |
| 456 | 456 | ThemeServices.DrawElement(Canvas.Handle, Details, R, nil); | |
| 457 | 457 | ... | |
| 458 | 458 | end; | |
| 459 | 459 | ``` | |
| 460 | 460 | ||
| 461 | 461 | # Conversiones de color hacia/desde html | |
| 462 | 462 | ||
| 463 | 463 | - [Convertir color desde/hacia HTML](http://wiki.lazarus.freepascal.org/Convert_color_to/from_HTML/es) | |
| 464 | 464 | ||
| 465 | 465 | - [Discusión sobre convertir color *desde/hacia HTML](http://wiki.lazarus.freepascal.org/Talk:Convert_color_to/from_HTML) | |
| 466 | 466 | ||
| 467 | 467 | --- | |
| 468 | 468 | *From the Free Pascal wiki, page "Colors/es", as it stood on 2020-02-11 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
