Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-14 Thread Виталий Фадеев via Digitalmars-d-learn
On Tuesday, 15 December 2020 at 05:10:27 UTC, Виталий Фадеев 
wrote:
On Tuesday, 15 December 2020 at 05:04:46 UTC, Виталий Фадеев 
wrote:
On Monday, 14 December 2020 at 16:19:18 UTC, Adam D. Ruppe 
wrote:
On Monday, 14 December 2020 at 16:11:16 UTC, Jacob Carlborg 
wrote:
Or you can call it `rgba`. It seems to be what Wikipedia 
prefers [1].


The ordering here tends to reflect the bytes. So argb puts 
the alpha byte first in the array whereas rgba puts red first.


But there's other ways here including just saying argb(...) 
or foo.as!"argb" or whatever well.


I think about .rgba.

Yes. The ordering! The logic.

ARGB = .argb

Thanks!


0x00AABBCC.argb

0x00AABBCC - is ARGB value
.argb  - is unit

...in my logic.

120.px
120   - is Pixel value
.px   - is unit

...in my logic.

100.percent
100   - is Percent value
.percent  - is unit

...in my logic.
)

Thanks!


This concept:
class X
{
this()
{
props.fontFace   = "Ubuntu Mono";
props.fontSize   = 24.px;
props.lineHeight = 15.px;
props.color  = 0xFF;
props.backColor  = 0x22;
// or
props.color  = 0xFF.rgb;
props.backColor  = 0x22.rgb;
// or
props.color  = 0x88FF.argb;
props.backColor  = 0x8822.argb;
}
}

Thanks!
)


Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-14 Thread Виталий Фадеев via Digitalmars-d-learn
On Tuesday, 15 December 2020 at 05:04:46 UTC, Виталий Фадеев 
wrote:
On Monday, 14 December 2020 at 16:19:18 UTC, Adam D. Ruppe 
wrote:
On Monday, 14 December 2020 at 16:11:16 UTC, Jacob Carlborg 
wrote:
Or you can call it `rgba`. It seems to be what Wikipedia 
prefers [1].


The ordering here tends to reflect the bytes. So argb puts the 
alpha byte first in the array whereas rgba puts red first.


But there's other ways here including just saying argb(...) or 
foo.as!"argb" or whatever well.


I think about .rgba.

Yes. The ordering! The logic.

ARGB = .argb

Thanks!


0x00AABBCC.argb

0x00AABBCC - is ARGB value
.argb  - is unit

...in my logic.

120.px
120   - is Pixel value
.px   - is unit

...in my logic.

100.percent
100   - is Percent value
.percent  - is unit

...in my logic.
)

Thanks!



Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-14 Thread Виталий Фадеев via Digitalmars-d-learn

On Monday, 14 December 2020 at 16:19:18 UTC, Adam D. Ruppe wrote:
On Monday, 14 December 2020 at 16:11:16 UTC, Jacob Carlborg 
wrote:
Or you can call it `rgba`. It seems to be what Wikipedia 
prefers [1].


The ordering here tends to reflect the bytes. So argb puts the 
alpha byte first in the array whereas rgba puts red first.


But there's other ways here including just saying argb(...) or 
foo.as!"argb" or whatever well.


I think about .rgba.

Yes. The ordering! The logic.

ARGB = .argb

Thanks!



Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-14 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 14 December 2020 at 16:11:16 UTC, Jacob Carlborg wrote:
Or you can call it `rgba`. It seems to be what Wikipedia 
prefers [1].


The ordering here tends to reflect the bytes. So argb puts the 
alpha byte first in the array whereas rgba puts red first.


But there's other ways here including just saying argb(...) or 
foo.as!"argb" or whatever well.


Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-14 Thread Jacob Carlborg via Digitalmars-d-learn

On Monday, 14 December 2020 at 05:51:28 UTC, Виталий Фадеев wrote:


It's parsing the `.a` in `.argb` as part of the number:

auto color = 0x00AABBCC.a rgb; // what the compiler sees

You can fix it with parentheses:

auto color = (0x00AABBCC).argb;


Thanks!

It is not perfect, but also beauty!


Or you can call it `rgba`. It seems to be what Wikipedia prefers 
[1].


[1] https://en.wikipedia.org/wiki/RGBA_color_model

--
/Jacob Carlborg


Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-13 Thread Виталий Фадеев via Digitalmars-d-learn

On Monday, 14 December 2020 at 05:37:21 UTC, Paul Backus wrote:
On Monday, 14 December 2020 at 05:27:40 UTC, Виталий Фадеев 
wrote:

".rgb"  Compiled fine.
".argb" Compilation error.


Source:
https://run.dlang.io/is/ULQ4kh


It's parsing the `.a` in `.argb` as part of the number:

auto color = 0x00AABBCC.a rgb; // what the compiler sees

You can fix it with parentheses:

auto color = (0x00AABBCC).argb;


Thanks!

It is not perfect, but also beauty!



Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-13 Thread Paul Backus via Digitalmars-d-learn

On Monday, 14 December 2020 at 05:27:40 UTC, Виталий Фадеев wrote:

".rgb"  Compiled fine.
".argb" Compilation error.


Source:
https://run.dlang.io/is/ULQ4kh


It's parsing the `.a` in `.argb` as part of the number:

auto color = 0x00AABBCC.a rgb; // what the compiler sees

You can fix it with parentheses:

auto color = (0x00AABBCC).argb;


Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-13 Thread Виталий Фадеев via Digitalmars-d-learn

On Monday, 14 December 2020 at 05:24:39 UTC, Виталий Фадеев wrote:


... msg ...



But...:
Color rgb( uint color )
{
return
Color( cast( uint ) (
( ( color & 0x00FF ) << 16 )  |
( ( color & 0xFF00 ) )  |
( ( color & 0x00FF ) >> 16 )
) );
}

unittest
{
auto color2 = 0x00AABBCC.rgb;
}

".rgb"  Compiled fine.
".argb" Compilation error.


Source:
https://run.dlang.io/is/ULQ4kh




Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-13 Thread Виталий Фадеев via Digitalmars-d-learn

We have:

static import winapi=core.sys.windows.windows;

struct Color
{
union
{
 winapi.COLORREF native;
 struct
{
ubyte r;
ubyte g;
ubyte b;
}
}
ubyte a = 0xFF;
}


Color argb( uint color )
{
Color c;

c.native =
cast( uint ) (
( ( color & 0x00FF ) << 16 )  |
( ( color & 0xFF00 ) )  |
( ( color & 0x00FF ) >> 16 )
);

c.a = ( color & 0xFF00 ) >> 24;

return c;
}


Goal:
auto color = 0x00AABBCC.argb;

Has error:
Error: exponent required for hex float
( at 0x00AABBCC.argb )

What is it ?
How to implement beauty code like the: #CC.rgb ?