soccer jersey forums.silverfrost.com :: View topic - DRAW_LINE@ and color transparency
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DRAW_LINE@ and color transparency

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
DanRRight



Joined: 10 Mar 2008
Posts: 2876
Location: South Pole, Antarctica

PostPosted: Fri Oct 04, 2013 1:24 pm    Post subject: DRAW_LINE@ and color transparency Reply with quote

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?

Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8036
Location: Salford, UK

PostPosted: Fri Oct 04, 2013 4:20 pm    Post subject: Reply with quote

Thanks. I already have this on the wish list.
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2393
Location: Yateley, Hants, UK

PostPosted: Fri Oct 04, 2013 7:22 pm    Post subject: Reply with quote

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:

Code:
      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
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2876
Location: South Pole, Antarctica

PostPosted: Sat Oct 05, 2013 3:10 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
jalih



Joined: 30 Jul 2012
Posts: 196

PostPosted: Mon Oct 07, 2013 8:02 pm    Post subject: Re: Reply with quote

PaulLaidler wrote:
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.
Code:

##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
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2393
Location: Yateley, Hants, UK

PostPosted: Mon Oct 07, 2013 9:00 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8036
Location: Salford, UK

PostPosted: Tue Oct 08, 2013 7:42 am    Post subject: Reply with quote

Thanks Jalih. That's very helpful.
Back to top
View user's profile Send private message AIM Address
DanRRight



Joined: 10 Mar 2008
Posts: 2876
Location: South Pole, Antarctica

PostPosted: Wed Oct 09, 2013 7:09 pm    Post subject: Reply with quote

Great, thanks all, Eddie, Jalih, Paul, hopefully we will see soon the new addition to the library!
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2876
Location: South Pole, Antarctica

PostPosted: Sun Nov 03, 2013 4:33 pm    Post subject: Reply with quote

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

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
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2393
Location: Yateley, Hants, UK

PostPosted: Mon Nov 04, 2013 1:14 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group