Silverfrost Forums

Welcome to our forums

DRAW_LINE@ and color transparency

4 Oct 2013 12:24 #13085

Paul, OpenGL has it as a fourth parameter besides three for RGB but would be nice to have an option for variable 0 to 1 drawing transparency for Salflibc graphics library to plot the graphs like this. Possible?

http://img819.imageshack.us/img819/5706/0hti.jpg

4 Oct 2013 3:20 #13086

Thanks. I already have this on the wish list.

4 Oct 2013 6:22 #13087

Dan,

Some years ago there was a post on transparency - I looked, but can't find it now. The original poster (my apologies to them for reposting their code) produced a routine:

      logical function SetWindowOpacity(hWnd, alpha) 
C     ----------------------------------------------
!     Set opacity level for a window (call after window creation) - 
!     automatically sets appropriate extended style and sets opacity  
!     from 0 (transparent) to 255 (no transparency). 
      use mswin 
      integer, parameter:: WS_EX_LAYERED = Z'00080000' 
      integer, parameter:: LWA_COLORKEY  = Z'00000001' 
      integer, parameter:: LWA_ALPHA     = Z'00000002' 
      STDCALL SetLayeredWindowAttributes 'SetLayeredWindowAttributes' 
     &         (VAL, VAL, VAL, VAL) : LOGICAL*4 
      integer, intent(in):: hWnd 
      integer, intent(in):: alpha 
      integer:: attrib, i 
  ! Get current window attributes to ensure WS_EX_LAYERED extended style is set 
      attrib = GetWindowLong(hWnd, GWL_EXSTYLE) 
      if (IAND(attrib,WS_EX_LAYERED) /= WS_EX_LAYERED) then 
         i = SetWindowLong(hWnd, GWL_EXSTYLE, IOR(attrib,WS_EX_LAYERED)) 
         end if 
  ! Set layered window alpha value 
      SetWindowOpacity = SetLayeredWindowAttributes
     &           (hWnd, 0, CORE1(LOC(alpha)), LWA_ALPHA) 
      end function SetWindowOpacity

I have been using this to make a borderless, no-caption initial splash screen gradually fade away (by changing the alpha value progressively in a %dl callback). It may be worth having a go to see if you can feed it to a %gr area, but whether it works only on a whole window or a single control, you would have to experiment.

Eddie

5 Oct 2013 2:10 #13088

Thanks, Eddie, Well, making DRAW_LINE@ transparency based on this idea is beyond of my capabilities... As to the window transparency - that's definitely cool thing. In order for this trick has not been forgotten and more, have been used by the people spreading further greatness and Wow factor of CWP would be nice if we always end up with working flashy example placing everything into User Examples collection. If i had some time i'd do that

7 Oct 2013 7:02 #13096

Quoted from PaulLaidler Thanks. I already have this on the wish list.

This one is quite easy to do. You just need a device context for the %gr graphics surface, to be able to create a GDI+ Graphics object.

Below is a example for the FTN95 callable ARGB color line drawing routine. For performance reasons calls to GdiplusStartup() and GdiplusShutdown() should probably be moved outside of the line drawing function.

##NOCONSOLE 
##MAKEDLL 
##USES 'gdiplus.lib' 

type GdiplusStartupInput 
	int GdiplusVersion 
	int DebugEventCallback 
	int SuppressBackgroundThread 
	int SuppressExternalCodecs 
endtype


@API GdiplusStartup(pointer pToken, pointer GdiplusStartupInput, int GdiplusStartupOutput),int 
@API GdiplusShutdown(uint token) 
@API GdipCreateFromHDC(uint hDC, pointer pGraphics),int 
@API GdipDeleteGraphics(uint Graphics),int 
@API GdipCreatePen1(uint argb,float w,int GpUnit, pointer pPen),int
@API GdipDeletePen(uint Pen),int
@API GdipDrawLineI(pointer pGraphics, pointer pPen, int x1, int y1, int x2, int y2),int


export ARGB
func ARGB(char a, char r, char g, char b),uint
	union col
		uint ARGB
		char bytes[4]
	endunion

  col c
	c.bytes[3] = a
	c.bytes[2] = r
	c.bytes[1] = g
	c.bytes[0] = b

	return c.ARGB
endf


export draw_line
func draw_line(uint hDC, int x1, int y1, int x2, int y2, float w, uint c) 
	int result 
	pointer pToken
	pointer pGraphics
	pointer pPen
	GdiplusStartupInput gsi(1,NULL,FALSE,FALSE)

	GdiplusStartup(&pToken,gsi,NULL)
	result = GdipCreateFromHDC(hDC,&pGraphics) 
	result = GdipCreatePen1(c,w,2,&pPen)
	result = GdipDrawLineI(pGraphics,pPen,x1,y1,x2,y2)

	GdipDeletePen(pPen)
	GdipDeleteGraphics(pGraphics) 
	GdiplusShutdown(pToken) 
endf

Blue line drawn with different alpha values in a CW+ program

7 Oct 2013 8:00 #13097

Jalih - as always - has the answer.

My suggestion was (a) that you draw your whole image in a window with a big %gr, find the handle of the window, and then apply transparency to the whole window. I know this works.

The second thing (which couldn't try because the hard drive on my laptop went bad while I was away from home) is to see if you can make a %gr area transparent with the routine - you get the handle of the %gr using %lc (maybe, as the handle you supply to %gr is a clearwin handle, not a windows one!)

Eddie

8 Oct 2013 6:42 #13101

Thanks Jalih. That's very helpful.

9 Oct 2013 6:09 #13119

Great, thanks all, Eddie, Jalih, Paul, hopefully we will see soon the new addition to the library!

3 Nov 2013 3:33 #13266

Eddie,

The 'fade away' was a nice trick, thanks. I use it for numerous warnings now.

What the purpose was for declaring the transparency function as logical function? That is hell of uncommon, and even scary even just to try it, so I changed that to integer and here is the whole demo code

   winapp
   use clrwin
   integer  SetWindowOpacity
   external SetWindowOpacity

   ii=123456
   i=winio@('%ww%sv%ca[Fade Away Example]&') 
!..%sv is to close window by hovering mouse over window - earlier then the window will fade away by itself
   i=winio@('%si# Some Parameter%rd&',ii)
   i=winio@('%hw%lw',ihw, ilw)

   do ialpha=255,0,-10
     call temporary_yield@
       iii = SetWindowOpacity(ihw, ialpha) 
     call sleep1@(0.2)
   enddo

!.. This closes window at the end
   ilw = 0
   call window_update@(ilw)
   end

!====================================================

      integer function SetWindowOpacity(hWnd, alpha) 
 !     ---------------------------------------------- 
 !     Set opacity level for a window (call after window creation) - 
 !     automatically sets appropriate extended style and sets opacity  
 !     from 0 (transparent) to 255 (no transparency). 
       use mswin 
       integer, parameter:: WS_EX_LAYERED = Z'00080000' 
       integer, parameter:: LWA_COLORKEY  = Z'00000001' 
       integer, parameter:: LWA_ALPHA     = Z'00000002' 
       STDCALL SetLayeredWindowAttributes 'SetLayeredWindowAttributes' &
     &         (VAL, VAL, VAL, VAL) : LOGICAL*4 
       integer, intent(in):: hWnd 
       integer, intent(in):: alpha 
       integer:: attrib, i 
       logical aaaaaa
   ! Get current window attributes to ensure WS_EX_LAYERED extended style is set 
       attrib = GetWindowLong(hWnd, GWL_EXSTYLE) 
       if (IAND(attrib,WS_EX_LAYERED) /= WS_EX_LAYERED) then 
          i = SetWindowLong(hWnd, GWL_EXSTYLE, IOR(attrib,WS_EX_LAYERED)) 
          end if 
   ! Set layered window alpha value 
       aaaaaa = SetLayeredWindowAttributes &
     &           (hWnd, 0, CORE1(LOC(alpha)), LWA_ALPHA) 
       SetWindowOpacity = 1
       end function SetWindowOpacity
4 Nov 2013 12:14 #13268

Dan,

I posted the code as I took it from the forum, so Logical is not my doing.

I also use [volatile] for some windows, then if you click anywhere else they go away.

Eddie

Please login to reply.