Ooops
January 15, 2021, 06:37:25 PM

Author Topic: [bb] Xp/Normal Group Box by Helios [ 1+ years ago ]  (Read 640 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Xp/Normal Group Box by Helios [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : Xp/Normal Group Box
Author : Helios
Posted : 1+ years ago

Description : Well this creates a basic group box, the style parameters specifys wether its a Xp styled one or a normal one, all the colors come from the systemColors so they should look right on all themes. When using it make sure to put the update code in your main loop as this resizes the image and deletes the type if you resize or delete its parent!

You need this in a decals file;

Code: [Select]
.lib "user32.dll"
api_GetSysColor% (nIndex%) : "GetSysColor"


Code :
Code: BlitzBasic
  1. ;--------------------------------------------------------------------
  2. ;               THe type!!
  3. ;               (C) 2500 TIM lEOANRD
  4. ; -------------------------------------------------------------------
  5. Type groupbox
  6.         Field panel
  7.         Field parent
  8.         Field name$
  9.         Field style
  10. End Type
  11.  
  12.  
  13. ;--------------------------------------------------------------------
  14. ;               The Update Code
  15. ;               (C) 2500 TIM lEOANRD
  16. ;               NOTE: This is used when resizeing and freeing windows
  17. ;                     asccociated with it!
  18. ; -------------------------------------------------------------------
  19. Function updategadgets()
  20. id=PeekEvent()
  21. ev=EventSource()
  22.  
  23. ;Update Group Boxes
  24. For g.groupbox=Each groupbox
  25.         If id=$802
  26.                 resizeGroupbox(Handle(g.groupbox))
  27.         EndIf
  28.         If id=$803 And EventSource()=gparent Then FreeGroupBox(gpanel)
  29. Next
  30.  
  31. End Function
  32.  
  33.  
  34. ;--------------------------------------------------------------------
  35. ;               GROUP BOX CODE
  36. ;               (C) 2500 TIM lEOANRD
  37. ;               NOTE: The buffer parameter is used to set the
  38. ;             current buffer back To the one you were using!
  39. ; -------------------------------------------------------------------
  40. Function CreateGroupBox(name$, x, y, w, h, p , style=0, buffer=0)
  41.         g.groupbox=New groupbox
  42.        
  43.         ;Create the panel to make the gadget out of
  44.                 gpanel=CreatePanel(x,y,w,h,p)
  45.                 gparent=p
  46.                 g
  47. ame=name
  48.                 gstyle=style
  49.        
  50.         ;Create the image
  51.         image=CreateImage(w,h) : SetBuffer ImageBuffer(image)
  52.        
  53.         ;Draw gadgets with system colors
  54.         ClsColor GetSysColorR(15),GetSysColorG(15),GetSysColorB(15) : Cls
  55.        
  56.         If style=0
  57.         Color GetSysColorR(11),GetSysColorG(11),GetSysColorB(11) : rRect 0,4,w-1,h-5,6
  58.         ;Not used anymore, not needed just slows down...
  59.         ;Color GetSysColorR(5),GetSysColorG(5),GetSysColorB(5) : rRect 1,5,w-3,h-7,5
  60.         EndIf
  61.        
  62.         If style=1
  63.         Color GetSysColorR(16),GetSysColorG(16),GetSysColorB(16) : Rect 0,4,w,h-5,0
  64.         EndIf
  65.        
  66.         font=LoadFont("MS Sans Serif",8) : SetFont(font)
  67.         Viewport 13,0,StringWidth(name)+6,FontHeight()
  68.         Cls
  69.         If style=0 Then Color 0,70,213
  70.         If style=1 Then Color GetSysColorR(8),GetSysColorG(8),GetSysColorB(8)
  71.         Text(16,0,name)
  72.        
  73.         ; Save image and set it as panel image
  74.         SaveImage(image,"tempGB.bmp")
  75.         SetPanelImage(gpanel,"tempGB.bmp")
  76.         DeleteFile("tempGB.bmp")
  77.        
  78.         ;Reset the buffer
  79.         If buffer<>0 Then SetBuffer buffer
  80.        
  81. Return gpanel
  82. End Function
  83.  
  84.  
  85.  
  86. Function FreeGroupBox(pan)
  87. For g.groupbox=Each groupbox
  88.         If gpanel=pan Then FreeGadget gpanel : Delete g.groupbox
  89. Next
  90. End Function
  91.  
  92.  
  93.  
  94. Function ResizeGroupBox(han)
  95. g.groupbox=Object.groupbox(han)
  96. w=GadgetWidth(gpanel)
  97. h=GadgetHeight(gpanel)
  98.  
  99.         ;Create the image
  100.         image=CreateImage(w,h) : SetBuffer ImageBuffer(image)
  101.        
  102.         ;Draw gadgets with system colors
  103.         ClsColor GetSysColorR(15),GetSysColorG(15),GetSysColorB(15) : Cls
  104.        
  105.         If gstyle=0
  106.         Color GetSysColorR(11),GetSysColorG(11),GetSysColorB(11) : rRect 0,4,w-1,h-5,6
  107.         ;Not used anymore, not needed just slows down...
  108.         ;Color GetSysColorR(5),GetSysColorG(5),GetSysColorB(5) : rRect 1,5,w-3,h-7,5
  109.         EndIf
  110.        
  111.         If gstyle=1
  112.         Color GetSysColorR(16),GetSysColorG(16),GetSysColorB(16) : Rect 0,4,w,h-5,0
  113.         EndIf
  114.        
  115.         font=LoadFont("MS Sans Serif",8) : SetFont(font)
  116.         Viewport 13,0,StringWidth(g
  117. ame)+6,FontHeight()
  118.         Cls
  119.         If gstyle=0 Then Color 0,70,213
  120.         If gstyle=1 Then Color GetSysColorR(8),GetSysColorG(8),GetSysColorB(8)
  121.         Text(16,0,g
  122. ame)
  123.        
  124.         ; Save image and set it as panel image
  125.         SaveImage(image,"tempGB.bmp")
  126.         SetPanelImage(gpanel,"tempGB.bmp")
  127.         DeleteFile("tempGB.bmp")
  128.        
  129. End Function
  130.  
  131.  
  132. ;--------------------------------------------------------------------
  133. ;               Rounded Rectangle CODE
  134. ;         Thanks to Stephen C. Demuth for this!
  135. ; -------------------------------------------------------------------
  136. Function RRect(x,y,width,height,radius=5)
  137.  
  138.         If radius > width/2 Then radius = width/2
  139.         If radius > height/2 Then radius = height/2
  140.  
  141.         ;---DRAW BORDERS
  142.         Line x+radius,y,x+width-radius,y                           ;Top
  143.         Line x+radius,y+height,x+width-radius,y+height ;Bottom 
  144.         Line x,y+radius,x,y+height-radius                          ;Left
  145.         Line x+width,y+radius,x+width,y+height-radius  ;Right  
  146.  
  147.  
  148.         ;---DRAW CORNERS
  149.  
  150.         ;Upper Left
  151.         For deg = 90 To 180
  152.                 yp = Sin(deg) * radius * -1 + y + radius
  153.                 xp = Cos(deg) * radius + x + radius            
  154.                 Plot xp,yp
  155.         Next
  156.  
  157.         ;Lower Left
  158.         For deg = 180 To 270
  159.                 yp = Sin(deg) * radius * -1 + y + height - radius
  160.                 xp = Cos(deg) * radius + x + radius            
  161.                 Plot xp,yp
  162.         Next
  163.  
  164.         ;Upper Right
  165.         For deg = 0 To 90
  166.                 yp = Sin(deg) * radius * -1 + y + radius
  167.                 xp = Cos(deg) * radius + x + width - radius            
  168.                 Plot xp,yp
  169.         Next
  170.  
  171.         ;Lower Right
  172.         For deg = 270 To 359
  173.                 yp = Sin(deg) * radius * -1 + y + height - radius
  174.                 xp = Cos(deg) * radius + x + width - radius            
  175.                 Plot xp,yp
  176.         Next
  177.  
  178. End Function
  179.  
  180.  
  181. ;--------------------------------------------------------------------
  182. ;               System Colour code
  183. ;         I cant remember who made it but credit to him anyway!
  184. ; -------------------------------------------------------------------
  185. Function GetSysColorR(SystemColor)
  186.         Return (api_GetSysColor(SystemColor) And $000000FF)
  187. End Function
  188.  
  189.  
  190. Function GetSysColorG(SystemColor)
  191.         Return (api_GetSysColor(SystemColor) And $0000FF00) Shr 8
  192. End Function
  193.  
  194.  
  195. Function GetSysColorB(SystemColor)
  196.         Return (api_GetSysColor(SystemColor) And $00FF0000) Shr 16
  197. End Function


Comments :


Helios(Posted 1+ years ago)

 heres an example....
Code: [Select]
win=CreateWindow("Group Box test",50,50,400,300,0,2+8+1)
GB1=createGroupBox("Xp Style",5,5,380,120,win)
GB2=createGroupBox("Normal Style",5,140,380,100,win,1)
SetGadgetLayout(gb1,1,2,1,2)
SetGadgetLayout(gb2,1,2,2,2)

Repeat
id=WaitEvent()
UpdateGadgets()
Until id=$803

;--------------------------------------------------------------------
; THe type!!
; (C) 2500 TIM lEOANRD
; -------------------------------------------------------------------
Type groupbox
Field panel
Field parent
Field name$
Field style
End Type


;--------------------------------------------------------------------
; The Update Code
; (C) 2500 TIM lEOANRD
; NOTE: This is used when resizeing and freeing windows
;      asccociated with it!
; -------------------------------------------------------------------
Function updategadgets()
id=PeekEvent()
ev=EventSource()

;Update Group Boxes
For g.groupbox=Each groupbox
If id=$802
resizeGroupbox(Handle(g.groupbox))
EndIf
If id=$803 And EventSource()=gparent Then FreeGroupBox(gpanel)
Next

End Function


;--------------------------------------------------------------------
; GROUP BOX CODE
; (C) 2500 TIM lEOANRD
; NOTE: The buffer parameter is used to set the
;             current buffer back To the one you were using!
; -------------------------------------------------------------------
Function CreateGroupBox(name$, x, y, w, h, p , style=0, buffer=0)
g.groupbox=New groupbox

;Create the panel to make the gadget out of
gpanel=CreatePanel(x,y,w,h,p)
gparent=p
g
ame=name
gstyle=style

;Create the image
image=CreateImage(w,h) : SetBuffer ImageBuffer(image)

;Draw gadgets with system colors
ClsColor GetSysColorR(15),GetSysColorG(15),GetSysColorB(15) : Cls

If style=0
Color GetSysColorR(11),GetSysColorG(11),GetSysColorB(11) : rRect 0,4,w-1,h-5,6
;Not used anymore, not needed just slows down...
;Color GetSysColorR(5),GetSysColorG(5),GetSysColorB(5) : rRect 1,5,w-3,h-7,5
EndIf

If style=1
Color GetSysColorR(16),GetSysColorG(16),GetSysColorB(16) : Rect 0,4,w,h-5,0
EndIf

font=LoadFont("MS Sans Serif",8) : SetFont(font)
Viewport 13,0,StringWidth(name)+6,FontHeight()
Cls
If style=0 Then Color 0,70,213
If style=1 Then Color GetSysColorR(8),GetSysColorG(8),GetSysColorB(8)
Text(16,0,name)

; Save image and set it as panel image
SaveImage(image,"tempGB.bmp")
SetPanelImage(gpanel,"tempGB.bmp")
DeleteFile("tempGB.bmp")

;Reset the buffer
If buffer<>0 Then SetBuffer buffer

Return gpanel
End Function



Function FreeGroupBox(pan)
For g.groupbox=Each groupbox
If gpanel=pan Then FreeGadget gpanel : Delete g.groupbox
Next
End Function



Function ResizeGroupBox(han)
g.groupbox=Object.groupbox(han)
w=GadgetWidth(gpanel)
h=GadgetHeight(gpanel)

;Create the image
image=CreateImage(w,h) : SetBuffer ImageBuffer(image)

;Draw gadgets with system colors
ClsColor GetSysColorR(15),GetSysColorG(15),GetSysColorB(15) : Cls

If gstyle=0
Color GetSysColorR(11),GetSysColorG(11),GetSysColorB(11) : rRect 0,4,w-1,h-5,6
;Not used anymore, not needed just slows down...
;Color GetSysColorR(5),GetSysColorG(5),GetSysColorB(5) : rRect 1,5,w-3,h-7,5
EndIf

If gstyle=1
Color GetSysColorR(16),GetSysColorG(16),GetSysColorB(16) : Rect 0,4,w,h-5,0
EndIf

font=LoadFont("MS Sans Serif",8) : SetFont(font)
Viewport 13,0,StringWidth(g
ame)+6,FontHeight()
Cls
If gstyle=0 Then Color 0,70,213
If gstyle=1 Then Color GetSysColorR(8),GetSysColorG(8),GetSysColorB(8)
Text(16,0,g
ame)

; Save image and set it as panel image
SaveImage(image,"tempGB.bmp")
SetPanelImage(gpanel,"tempGB.bmp")
DeleteFile("tempGB.bmp")

End Function


;--------------------------------------------------------------------
; Rounded Rectangle CODE
;  Thanks to Stephen C. Demuth for this!
; -------------------------------------------------------------------
Function RRect(x,y,width,height,radius=5)

If radius > width/2 Then radius = width/2
If radius > height/2 Then radius = height/2

;---DRAW BORDERS
Line x+radius,y,x+width-radius,y   ;Top
Line x+radius,y+height,x+width-radius,y+height ;Bottom
Line x,y+radius,x,y+height-radius   ;Left
Line x+width,y+radius,x+width,y+height-radius  ;Right


;---DRAW CORNERS

;Upper Left
For deg = 90 To 180
yp = Sin(deg) * radius * -1 + y + radius
xp = Cos(deg) * radius + x + radius
Plot xp,yp
Next

;Lower Left
For deg = 180 To 270
yp = Sin(deg) * radius * -1 + y + height - radius
xp = Cos(deg) * radius + x + radius
Plot xp,yp
Next

;Upper Right
For deg = 0 To 90
yp = Sin(deg) * radius * -1 + y + radius
xp = Cos(deg) * radius + x + width - radius
Plot xp,yp
Next

;Lower Right
For deg = 270 To 359
yp = Sin(deg) * radius * -1 + y + height - radius
xp = Cos(deg) * radius + x + width - radius
Plot xp,yp
Next

End Function


;--------------------------------------------------------------------
; System Colour code
;  I cant remember who made it but credit to him anyway!
; -------------------------------------------------------------------
Function GetSysColorR(SystemColor)
        Return (api_GetSysColor(SystemColor) And $000000FF)
End Function


Function GetSysColorG(SystemColor)
Return (api_GetSysColor(SystemColor) And $0000FF00) Shr 8
End Function


Function GetSysColorB(SystemColor)
Return (api_GetSysColor(SystemColor) And $00FF0000) Shr 16
End Function



Phoenix(Posted 1+ years ago)

 It's veeeery slow, though it looks good. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal