Window and Gadget BackColor & FrontColor use RGBA()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Window and Gadget BackColor & FrontColor use RGBA()

Post by gurj »

Window and Gadget BackColor & FrontColor use RGBA()
for through Window and suspend Gadget
my pb for chinese:
http://ataorj.ys168.com
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Window and Gadget BackColor & FrontColor use RGBA()

Post by netmaestro »

for through Window and suspend Gadget
I'm not sure what you mean by "suspend gadget" but the application of a 32bit color to the background of a window would not give it any level of transparency. For that you need to use layered windows on MS and I've no idea for the other OS's. Layered windows don't require a 32bit color for background to achieve transparency. MS achieves transparency on these special windows without the use of an alpha layer. It is done mathematically as in this example which also uses no RGBA colors:

Code: Select all

; Alpha transparency via arithmetic
; Lloyd Gallant (netmaestro) January 2017

Procedure ColorProc(x, y, sourcecolor, targetcolor)
  alpha.d = (y/480)*255
  redout.f = Red(sourcecolor)*(alpha/255) + Red(targetcolor)*((255-alpha)/255)
  greenout.f = Green(sourcecolor)*(alpha/255) + Green(targetcolor)*((255-alpha)/255)
  blueout.f = Blue(sourcecolor)*(alpha/255) + Blue(targetcolor)*((255-alpha)/255)
  ProcedureReturn RGB(Int(redout),Int(greenout),Int(blueout))
EndProcedure

CreateImage(0, 640, 480, 24, RGB(255,255,223))
LoadFont(0, "verdana", 10)
StartDrawing(ImageOutput(0))
  a$ = "This is a line numbered from one to twenty displayed at this vertical position" 
  For i=1 To 20
    DrawText(20, i*20, a$, #Black, RGB(255,255,223))
  Next
StopDrawing()

CreateImage(1, 640, 480, 24, RGB(255,255,223))

StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_CustomFilter)
  CustomFilterCallback(@colorproc())
  DrawImage(ImageID(0),0,0)
StopDrawing()

OpenWindow(0,0,0,640,480,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,0,0,ImageID(1))
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow
BERESHEIT
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: Window and Gadget BackColor & FrontColor use RGBA()

Post by gurj »

Thanks netmaestro ! i bad english,sorry ! suspend -> float ?...
ok ! from TI-994A's code
http://www.purebasic.fr/english/viewtop ... 13&t=67460
i use :

Code: Select all

; from TI-994A
; ;InitNetwork()
; UsePNGImageDecoder()
; ; bgFile.s = GetTemporaryDirectory() + "donald.png"
; ; If FileSize(bgFile) < 1
; ;   ReceiveHTTPFile("https://www.dropbox.com/s/" + 
; ;                   "yt0gc8de39hmupo/donaldMove.png?dl=1", bgFile)
; ;  EndIf
; bgFile.s = "D:\exe1\PureB\PureBasic\Examples\Sources\Data\CdPlayer.png"
; ;i make CdPlayer.png is transparent
; donald = LoadImage(#PB_Any, bgFile)

;*****************************************************************

Procedure WndProc(win, msg, wParam, lParam)
  Shared mainWindow
  Protected result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_LBUTTONDOWN 
      SendMessage_(WindowID(mainWindow),#WM_NCLBUTTONDOWN,#HTCAPTION,0) 
  EndSelect 
  ProcedureReturn result
EndProcedure

Procedure makeInvisible(id, gadget = 0)
  If gadget
    SetGadgetColor(id, #PB_Gadget_BackColor, $6f6f6f) 
    id = GadgetID(id)
  Else
    SetWindowColor(id, $6f6f6f) 
    id = WindowID(id)
  EndIf
  SetWindowLongPtr_(id, #GWL_EXSTYLE, 
                    GetWindowLongPtr_(id, #GWL_EXSTYLE) | #WS_EX_LAYERED) 
  SetLayeredWindowAttributes_(id, $6f6f6f, 0, #LWA_COLORKEY) 
EndProcedure

;If donald
  wFlags = #PB_Window_ScreenCentered | #PB_Window_BorderLess
  mainWindow = OpenWindow(#PB_Any, 0, 0, 550, 550, "", wFlags)
  makeInvisible(mainWindow)
  
  ;bgImage = ImageGadget(#PB_Any, 0, 0, 0, 0, ImageID(donald)) 
  closeBtn = ButtonGadget(#PB_Any, 520, 0, 30, 30, "X") 
  txtInput = StringGadget(#PB_Any, 350, 480, 200, 30, "")
  submitBtn = ButtonGadget(#PB_Any, 350, 520, 200, 30, "SUBMIT") 
  ;DisableGadget(bgImage, #True)
  SetWindowCallback(@WndProc())
  
  container = ContainerGadget(#PB_Any, 30, 30, 200, 100)
  containerTxt = StringGadget(#PB_Any, 0, 0, 200, 30, "")
  containerBtn = ButtonGadget(#PB_Any, 0, 40, 200, 30, 
                              "I'm in the container!")
  makeInvisible(container, 1)
  CloseGadgetList()
  
  scrollGadget = ScrollAreaGadget(#PB_Any, 350, 180, 200, 280, 400, 600)
  scrollTxt = StringGadget(#PB_Any, 10, 20, 160, 30, "")
  scrollBtn = ButtonGadget(#PB_Any, 10, 60, 160, 30, 
                              "I'm in the scroll area!")  
  makeInvisible(scrollGadget, 1)
  CloseGadgetList()
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case closeBtn
            appQuit = 1
          Case submitBtn
            MessageRequester("Invisible Window", 
                             "You entered, " + #DQUOTE$ + 
                             GetGadgetText(txtInput) + #DQUOTE$)            
          Case containerBtn
            MessageRequester("Invisible Window", 
                             "You entered, " + #DQUOTE$ + 
                             GetGadgetText(containerTxt) + #DQUOTE$)
          Case scrollBtn
            MessageRequester("Invisible Window", 
                             "You entered, " + #DQUOTE$ + 
                             GetGadgetText(scrollTxt) + #DQUOTE$)            
        EndSelect
    EndSelect
  Until appQuit = 1 
; Else
;   MessageRequester("Invisible Window", "Background image not found.")
; EndIf
my pb for chinese:
http://ataorj.ys168.com
Post Reply