Hiya
This is window with gradient background, basically I translated code from this article into asm
http://www.codeproject.com/gdi/win32_gradients.asp?target=gradient%7Csdk

Explanation of code:
I just used icezilion window example (tut3) and added handler for WM_ERASEBKGND


.elseif uMsg==WM_ERASEBKGND
OnEraseBkGnd proto :dword
invoke OnEraseBkGnd,hWnd

See OnEraseBkGnd proc in source for details

Question:
All this looks nice however there is problem, you cant use just any combination of colors you want. In my code I use C1_XXX as RGB values for starting color and C2_XXX for ending color, it works ok with example in source but try changing them into this...


C1_RED EQU 255
C1_GREEN EQU 0
C1_BLUE EQU 150

C2_RED EQU 0
C2_GREEN EQU 0
C2_BLUE EQU 100



Any idea how to solve this? Or I will just have to live with limited set of color combinations :(
Posted on 2004-03-16 16:11:25 by Mikky
To do it corectly for any set of colors you will need an "linear interpolator"
Ie it is like drawing a line but in the color space...,
actually 3 lines one for each RGB color components

so you can use:
- DDA (floating points) - that will be exact but somehow slow
- Bresenham that will be very fast but a little more complicated to implement

Depends on how many gradients you have to draw/calculate, for only one i do not know if you really need Bresenham's super speed, Also for a 3D non discreet space a floating point solution could be more accurate.

So using whatever linear interpolator you like you will have to go:
- from C1_Red to C2_Red
- from C1_Blue to C2_Blue
- from C1_Green to C2_Green
Posted on 2004-03-16 21:08:32 by BogdanOntanu
Gradient fill between two colors:
GradFill PROC USES ebx esi edi, _HWnd_:DWORD

LOCAL Color1:DWORD, Color2:DWORD
LOCAL dx1:DWORD, dx2:DWORD, dx3:DWORD
LOCAL TmpRect:RECT
LOCAL DC:DWORD, FullLength:DWORD

invoke GetClientRect, _HWnd_, ADDR TmpRect
sub TmpRect.right, 2
sub TmpRect.bottom, 2
;calc width of rectangle
mov ebx,TmpRect.right
sub ebx,TmpRect.left
mov FullLength,ebx
jz @F
;prepare tmprect
mov eax,TmpRect.left
inc eax
mov TmpRect.right,eax

invoke GetWindowLongA,_HWnd_,PWL_GRADDC
mov DC,eax
invoke GetWindowLongA,_HWnd_,PWL_BARCOLOR1
mov Color1,eax
invoke GetWindowLongA,_HWnd_,PWL_BARCOLOR2
mov Color2,eax

mov ecx, Color2
mov edi, Color1
sal ecx, 7
sal edi, 7

mov eax, ecx
mov ebx, edi
and eax, 0FF000000h / 2
and ebx, 0FF000000h / 2
sub eax, ebx
cdq
idiv FullLength
mov dx1, eax

mov eax, ecx
mov esi, edi
and eax, 0FF0000h / 2
and esi, 0FF0000h / 2
sub eax, esi
cdq
idiv FullLength
mov dx2, eax

mov eax, ecx
and eax, 0FF00h / 2
and edi, 0FF00h / 2
sub eax, edi
cdq
idiv FullLength
mov dx3, eax

mov eax, Color1
lp: ;fill tmprect
invoke CreateSolidBrush,eax
push eax
invoke FillRect,DC,ADDR TmpRect,eax ; ADDR destroys EAX!
call DeleteObject
;update tmprect
inc TmpRect.left
inc TmpRect.right

add ebx,dx1
add esi,dx2
mov edx,ebx
mov eax,esi
and edx,0FF000000h / 2
and eax,0FF0000h / 2
add edi,dx3
or edx,eax

mov eax,edi
and eax,0FF00h / 2
or eax,edx

shr eax, 7

dec FullLength
jne lp
@@: ret
GradFill ENDP
Posted on 2004-03-18 00:43:25 by bitRAKE
Hey yo Mikky, thats cute :) i love gradients, jojoj. :D
Posted on 2004-03-18 06:51:46 by JaiKMw