Make custom window edge smooth?

Just starting out? Need help? Post your questions and find answers here.
fluent
User
User
Posts: 68
Joined: Sun Jan 24, 2021 10:57 am

Make custom window edge smooth?

Post by fluent »

Playing with a custom window shape but no so happy with the somewhat jagged edge of the curved part...
Any cool API tricks to add anti-aliasing?

Code: Select all

CreateImage(0, 400, 300)
StartDrawing(ImageOutput(0))
Box(0,0,400,300,#Blue)
Ellipse(30,30,300,200,#White)
StopDrawing()

w = ImageWidth(0)
h = ImageHeight(0)

OpenWindow(0, 0, 0, w,h, "", #PB_Window_BorderLess|#PB_Window_ScreenCentered) 

SetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE,GetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED) 
SetLayeredWindowAttributes_(WindowID(0),#White,0,#LWA_COLORKEY)

ImageGadget(1,0,0,w,h,ImageID(0)) 
DisableGadget(1,1)
ButtonGadget(2,250,230,100,30,"Quit") 

Repeat 
  Select WaitWindowEvent() 
    Case #WM_LBUTTONDOWN
      SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0) 
      
    Case #PB_Event_Gadget 
      Select EventGadget() 
        Case 2
          Quit = 1
      EndSelect 
      
    Case #PB_Event_CloseWindow 
      quit = 1
      
  EndSelect 
  
Until Quit = 1

User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Make custom window edge smooth?

Post by Demivec »

fluent wrote: Fri Apr 16, 2021 9:21 pm Playing with a custom window shape but no so happy with the somewhat jagged edge of the curved part...
Any cool API tricks to add anti-aliasing?

Code: Select all

CreateImage(0, 400, 300)
; StartDrawing(ImageOutput(0))
; Box(0,0,400,300,#Blue)
; Ellipse(30,30,300,200,#White)
; StopDrawing()
StartVectorDrawing(ImageVectorOutput(0))
  AddPathBox(0,0,400,300)
  VectorSourceColor(RGBA(0, 0, $FF, $FF));#Blue)
  FillPath()
  AddPathEllipse(30,30,300,200)
  VectorSourceColor(RGBA($FF, $FF, $FF, $FF)) ;#White)
  FillPath()
StopVectorDrawing()

w = ImageWidth(0)
h = ImageHeight(0)

OpenWindow(0, 0, 0, w,h, "", #PB_Window_BorderLess|#PB_Window_ScreenCentered) 

SetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE,GetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED) 
SetLayeredWindowAttributes_(WindowID(0),#White,0,#LWA_COLORKEY)

ImageGadget(1,0,0,w,h,ImageID(0)) 
DisableGadget(1,1)
ButtonGadget(2,250,230,100,30,"Quit") 

Repeat 
  Select WaitWindowEvent() 
    Case #WM_LBUTTONDOWN
      SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0) 
      
    Case #PB_Event_Gadget 
      Select EventGadget() 
        Case 2
          Quit = 1
      EndSelect 
      
    Case #PB_Event_CloseWindow 
      quit = 1
      
  EndSelect 
  
Until Quit = 1
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Make custom window edge smooth?

Post by Saki »

@Demivec
Move your example over a dark background and you will see the problem.
The color edges interpolate with each other.
This is only possible via the Alpha channel.
地球上の平和
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Make custom window edge smooth?

Post by Demivec »

Saki wrote: Sat Apr 17, 2021 9:36 am @Demivec
Move your example over a dark background and you will see the problem.
The color edges interpolate with each other.
@Saki: Thank you for your feedback on my suggestion. I agree that the effectiveness of the antialiasing depends on the background it is shown over. In my defense I showed an antialiasied example and an improvement over the OP's original example.

In hindsight I should have used a Grey color to blend with to make it more pleasing (or equally offensive) when viewed over both light or dark backgrounds.

I don't know of any API solutions to help things any. There may be some but I don't know of any.
fluent
User
User
Posts: 68
Joined: Sun Jan 24, 2021 10:57 am

Re: Make custom window edge smooth?

Post by fluent »

Good enough for me, thanks!
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Make custom window edge smooth?

Post by Demivec »

fluent wrote: Sat Apr 17, 2021 1:06 pm Good enough for me, thanks!
Your welcome.
Post Reply