My own crappy attempt - moveable and resizable but not brilliant and not set up for DPI awareness.
Can be moved by 'dragging' the title bar and resized by 'dragging' the bottom right hand corner.
Code: Select all
Global GVAR_version.s = " v201"
; -----------------------------------------------------------------------------
; P R E F I X D E F I N I T I O N S
; -----------------------------------------------------------------------------
; LVAR_ -> Local variable
; PVAR_ -> Passed variable
; GVAR_ -> Global variable
; DVAR_ -> Database variable
;
; PROC_ -> Procedure
; STRU_ -> Structure
; LIST_ -> List
; MCRO_ -> Macro
; CNST_ -> Constant
; WNDW_ -> Window ID
;
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#CNST_margin = 10
#CNST_spacing = 10
; WINDOW Types
#CNST_wndw_std = 0
#CNST_wndw_warn = 1
; GADGET Types
#CNST_label = 0
#CNST_string = 1
#CNST_button = 2
#CNST_checkbox = 3
; WARNING WINDOW Types
#CNST_warn_y = 0
#CNST_warn_yn = 1
#CNST_warn_ync = 2
; WARNING WINDOW results
#CNST_yes = 0
#CNST_no = 1
#CNST_cancel = 2
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;{ default window gadgets structure
Structure STRU_wndw
WNDW_id.i
WNDW_m_w.i
WNDW_m_h.i
EndStructure
;}
Global NewList LIST_wndw.STRU_wndw()
;{ window gadget stack
Structure STRU_gdgt_stack
gid.i
btn_text.s
default_data.s
add_data_1.s
add_data_2.s
EndStructure
;}
Global NewList LIST_gdgt_stack.STRU_gdgt_stack()
;{ default colours structure
Structure STRU_wndw_colours
; window structure
wndw_border.i
wndw_background.i
; window title bar
wndw_titlebar_paper.i
wndw_titlebar_paper_a.i
wndw_titlebar_ink.i
; window about button
wndw_about_btn.i
; window minimise button
wndw_min_btn.i
; window close button
wndw_close_btn.i
; resize gadget
wndw_resize_background.i
wndw_resize_border_1.i
wndw_resize_border_2.i
EndStructure
;}
Global GVAR_wndw_colours.STRU_wndw_colours
;define and set global font
Global f_12.i = LoadFont(#PB_Any,"Calibri", 12, #PB_Font_HighQuality)
SetGadgetFont(#PB_Default, FontID(f_12))
; this PC's available screen settings
Global GVAR_screen_qty.i, GVAR_screen_width.i, GVAR_screen_height.i
Global GVAR_screen_dpi_x.d, GVAR_screen_dpi_y.d
Declare.i PROC_tint_rgb(PVAR_rgb.i, PVAR_percentage.i)
Declare.i PROC_tint_rgba(PVAR_rgba.i, PVAR_percentage.i)
Declare.i PROC_setup_colours()
Declare.i PROC_screen_dims()
Declare.i PROC_wndw_ctrl_btn_display(PVAR_gid.i, PVAR_ink.i, PVAR_paper.i)
Declare.i PROC_wndw_check_position(PVAR_wndw_id.i)
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; G E N E R A L P R O C S
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Procedure.i PROC_tint_rgb(PVAR_rgb.i, PVAR_percentage.i)
; /--------------------------------------------------------------------------\
; | P U R P O S E |
; |--------------------------------------------------------------------------|
; | Lightens or darkens the RGB value passed by the percentage value passed |
; \--------------------------------------------------------------------------/
LVAR_text_line.s ; Used for storing lines read from file
LVAR_r.i ; the red value of the passed rgb colour
LVAR_g.i ; the green value of the passed rgb colour
LVAR_b.i ; the blue value of the passed rgb colour
LVAR_p.d ; the percentage to change the rgb colour by
LVAR_r = Red(PVAR_rgb)
LVAR_g = Green(PVAR_rgb)
LVAR_b = Blue(PVAR_rgb)
LVAR_p = PVAR_percentage / 100
LVAR_r = LVAR_r + (255 - LVAR_r) * LVAR_p
LVAR_g = LVAR_g + (255 - LVAR_g) * LVAR_p
LVAR_b = LVAR_b + (255 - LVAR_b) * LVAR_p
ProcedureReturn RGB(LVAR_r, LVAR_g, LVAR_b)
EndProcedure
Procedure.i PROC_tint_rgba(PVAR_rgba.i, PVAR_percentage.i)
; ---------------------------------------------------------------------------
; P U R P O S E
; ---------------------------------------------------------------------------
; Lightens or darkens the RGBA value passed by the percentage value passed
; ---------------------------------------------------------------------------
; I N P U T S
; ---------------------------------------------------------------------------
; PVAR_rgb.i -> A colour in RGBA format
; PVAR_percentage.i -> The percentage to lighten or darken the original
; colour ( 0 To 100 )
; ---------------------------------------------------------------------------
; D E C L A R E L O C A L V A R I A B L E S
; ---------------------------------------------------------------------------
LVAR_text_line.s ; Used for storing lines read from file
LVAR_r.i ; the red value of the passed rgba colour
LVAR_g.i ; the green value of the passed rgba colour
LVAR_b.i ; the blue value of the passed rgba colour
LVAR_a.i ; the aplha value of the passed rgba colour
LVAR_p.d ; the percentage to change the rgba colour by
; ---------------------------------------------------------------------------
LVAR_r = Red(PVAR_rgba)
LVAR_g = Green(PVAR_rgba)
LVAR_b = Blue(PVAR_rgba)
LVAR_a = Alpha(PVAR_rgba)
LVAR_p = PVAR_percentage / 100
LVAR_r.i = LVAR_r + (255 - LVAR_r) * LVAR_p
LVAR_g.i = LVAR_g + (255 - LVAR_g) * LVAR_p
LVAR_b.i = LVAR_b + (255 - LVAR_b) * LVAR_p
ProcedureReturn RGBA(LVAR_r, LVAR_g, LVAR_b, 255)
EndProcedure
Procedure.i PROC_setup_colours()
; /--------------------------------------------------------------------------\
; | P U R P O S E |
; |--------------------------------------------------------------------------|
; | sets up the default system colours to be used by the program |
; \--------------------------------------------------------------------------/
GVAR_wndw_colours\wndw_border = PROC_tint_rgb(RGB(198, 218, 0), 50)
GVAR_wndw_colours\wndw_background = RGB(059, 059, 060)
GVAR_wndw_colours\wndw_titlebar_ink = RGB(059, 059, 060)
GVAR_wndw_colours\wndw_titlebar_paper = RGB(198, 218, 000)
GVAR_wndw_colours\wndw_titlebar_paper_a = RGBA(198, 218, 000, 255)
GVAR_wndw_colours\wndw_about_btn = RGBA(000, 200, 000, 255)
GVAR_wndw_colours\wndw_min_btn = RGBA(255, 153, 000, 255)
GVAR_wndw_colours\wndw_close_btn = RGBA(255, 000, 000, 255)
GVAR_wndw_colours\wndw_resize_background = RGBA(198, 218, 000, 255)
GVAR_wndw_colours\wndw_resize_border_1 = RGBA(198, 218, 000, 255)
GVAR_wndw_colours\wndw_resize_border_2 = RGBA(059, 059, 060, 255)
EndProcedure
Procedure.i PROC_screen_dims()
; /--------------------------------------------------------------------------\
; | P U R P O S E |
; |--------------------------------------------------------------------------|
; | Gets available screens width and height (in pixels) and stores them in |
; | global variables |
; \--------------------------------------------------------------------------/
LVAR_no_of_screens.i = ExamineDesktops()
GVAR_screen_qty = LVAR_no_of_screens
Debug "Number of desktops : " + Str(LVAR_no_of_screens)
For LVAR_loop_count.i = 0 To (LVAR_no_of_screens-1)
GVAR_screen_width + DesktopWidth(LVAR_loop_count)
GVAR_screen_height = DesktopHeight(LVAR_loop_count)
Debug "Screen No. : " + Str(LVAR_loop_count) + #TAB$ + "Resolution : " + Str(GVAR_screen_width) + " x " + Str(GVAR_screen_height)
Next
GVAR_screen_dpi_x = DesktopResolutionX()
GVAR_screen_dpi_y = DesktopResolutionY()
EndProcedure
Procedure.i PROC_wndw_ctrl_btn_display(PVAR_gid.i, PVAR_ink.i, PVAR_paper.i)
If StartVectorDrawing(CanvasVectorOutput(PVAR_gid))
AddPathBox(0, 0, Round(30 * GVAR_screen_dpi_x, #PB_Round_Up), Round(30 * GVAR_screen_dpi_y, #PB_Round_Up))
VectorSourceColor(PVAR_paper)
FillPath()
AddPathCircle(15* GVAR_screen_dpi_x, 15* GVAR_screen_dpi_y, 13* GVAR_screen_dpi_x, 0, 360)
VectorSourceColor(GVAR_wndw_colours\wndw_background)
FillPath()
AddPathCircle(15* GVAR_screen_dpi_x, 15* GVAR_screen_dpi_y, 12* GVAR_screen_dpi_x, 0, 360)
VectorSourceColor(PVAR_ink)
FillPath()
StopVectorDrawing()
EndIf
EndProcedure
Procedure.i PROC_wndw_check_position(PVAR_wndw_id.i)
; /--------------------------------------------------------------------------\
; | P U R P O S E |
; |--------------------------------------------------------------------------|
; | checks to see if the user has moved the specified window outside that |
; | available space |
; \--------------------------------------------------------------------------/
LVAR_wndw_width.i = WindowWidth(PVAR_wndw_id)
LVAR_wndw_height.i = WindowHeight(PVAR_wndw_id)
If WindowX(PVAR_wndw_id) + LVAR_wndw_width > GVAR_screen_width
ResizeWindow(PVAR_wndw_id, GVAR_screen_width - (LVAR_wndw_width + 5), #PB_Ignore, #PB_Ignore, #PB_Ignore)
ElseIf WindowX(PVAR_wndw_id) < 0
ResizeWindow(PVAR_wndw_id, 5, #PB_Ignore, #PB_Ignore, #PB_Ignore)
EndIf
If WindowY(PVAR_wndw_id) + LVAR_wndw_height > GVAR_screen_height
ResizeWindow(PVAR_wndw_id, #PB_Ignore, GVAR_screen_height - (LVAR_wndw_height + 5), #PB_Ignore, #PB_Ignore)
ElseIf WindowY(PVAR_wndw_id) < 0
ResizeWindow(PVAR_wndw_id, #PB_Ignore, 5, #PB_Ignore, #PB_Ignore)
EndIf
EndProcedure
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
; W I N D O W S
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Global WNDW_main.i
Global WNDW_main_background.i, WNDW_main_titlebar.i, WNDW_main_btn_min.i, WNDW_main_btn_close.i, WNDW_main_btn_resize.i
Procedure.i PROC_wndw_main()
WNDW_main = OpenWindow(#PB_Any, 0, 0, 800, 600, "Title" + GVAR_version, #PB_Window_ScreenCentered | #PB_Window_BorderLess)
If WNDW_main
AddKeyboardShortcut(WNDW_main, #PB_Shortcut_F12, 100)
Debug WindowWidth(WNDW_main)
Debug WindowHeight(WNDW_main)
LVAR_w.i = WindowWidth(WNDW_main): LVAR_h.i = WindowHeight(WNDW_main)
SetWindowColor(WNDW_main, GVAR_wndw_colours\wndw_border)
WNDW_main_background = ContainerGadget(#PB_Any, 2, 2, LVAR_w-4, LVAR_h-4)
CloseGadgetList()
SetGadgetColor(WNDW_main_background, #PB_Gadget_BackColor, GVAR_wndw_colours\wndw_background )
DisableGadget(WNDW_main_background, #True)
WNDW_main_titlebar = TextGadget(#PB_Any, 1, 1, LVAR_w-1, 30, " " + GetWindowTitle(WNDW_main), #SS_CENTERIMAGE)
SetGadgetColor(WNDW_main_titlebar, #PB_Gadget_BackColor, GVAR_wndw_colours\wndw_titlebar_paper )
SetGadgetColor(WNDW_main_titlebar, #PB_Gadget_FrontColor, GVAR_wndw_colours\wndw_titlebar_ink )
WNDW_main_btn_about = CanvasGadget(#PB_Any, LVAR_w-105, 1, 30, 30)
PROC_wndw_ctrl_btn_display(WNDW_main_btn_about, GVAR_wndw_colours\wndw_about_btn, GVAR_wndw_colours\wndw_titlebar_paper_a)
WNDW_main_btn_min = CanvasGadget(#PB_Any, LVAR_w-70, 1, 30, 30)
PROC_wndw_ctrl_btn_display(WNDW_main_btn_min, GVAR_wndw_colours\wndw_min_btn, GVAR_wndw_colours\wndw_titlebar_paper_a)
WNDW_main_btn_close = CanvasGadget(#PB_Any, LVAR_w-35, 1, 30, 30)
PROC_wndw_ctrl_btn_display(WNDW_main_btn_close, GVAR_wndw_colours\wndw_close_btn, GVAR_wndw_colours\wndw_titlebar_paper_a)
WNDW_main_btn_resize = CanvasGadget(#PB_Any, LVAR_w-10, LVAR_h-10, 10, 10)
LVAR_cgw.i = GadgetWidth(WNDW_main_btn_resize) * GVAR_screen_dpi_x
LVAR_cgh.i = GadgetHeight(WNDW_main_btn_resize) * GVAR_screen_dpi_y
If StartVectorDrawing(CanvasVectorOutput(WNDW_main_btn_resize))
AddPathBox(0, 0, LVAR_cgw, LVAR_cgh)
VectorSourceColor(GVAR_wndw_colours\wndw_resize_border_1)
FillPath()
AddPathBox(0, 0, LVAR_cgw-(2 * GVAR_screen_dpi_x), LVAR_cgh-(2 * GVAR_screen_dpi_y))
VectorSourceColor(GVAR_wndw_colours\wndw_resize_border_2)
FillPath()
StopVectorDrawing()
EndIf
Else
LVAR_message.s = "Failed to open WNDW_main"
Debug LVAR_message
EndIf
; update LIST_wndw()
AddElement(LIST_wndw())
LIST_wndw()\WNDW_id = WNDW_main
LIST_wndw()\WNDW_m_w = WindowWidth(WNDW_main)
LIST_wndw()\WNDW_m_h = WindowHeight(WNDW_main)
WNDW_main_quit.i
LVAR_drag_flag.i = #False
LVAR_resize_flag.i = #False
Repeat
WNDW_event.i = WindowEvent()
Select WNDW_event
Case #WM_LBUTTONDOWN
Debug "DOWN"
LVAR_old_wxo.i = WindowMouseX(WNDW_main)
LVAR_old_wyo.i = WindowMouseY(WNDW_main)
If LVAR_old_wyo < 30
LVAR_drag_flag = #True
EndIf
Case #WM_LBUTTONUP
Debug "UP"
LVAR_drag_flag = #False
Case #WM_MOUSEMOVE
If LVAR_drag_flag = #True
Debug "move"
ResizeWindow(WNDW_main, DesktopMouseX()-LVAR_old_wxo, DesktopMouseY()-LVAR_old_wyo, #PB_Ignore, #PB_Ignore)
EndIf
If LVAR_resize_flag = #True
Debug "resize"
LVAR_w_w.i = 10 + WindowWidth(WNDW_main) + ( DesktopMouseX() - (WindowX(WNDW_main)+WindowWidth(WNDW_main)) )
LVAR_w_h.i = 10 + WindowHeight(WNDW_main) + ( DesktopMouseY() - (WindowY(WNDW_main)+WindowHeight(WNDW_main)) )
If LVAR_w_w < LVAR_m_w
Debug "smaller"
LVAR_w_w = LVAR_m_w
EndIf
If LVAR_w_h < LVAR_m_h
LVAR_w_h = LVAR_m_h
EndIf
ResizeWindow(WNDW_main, #PB_Ignore, #PB_Ignore, LVAR_w_w, LVAR_w_h)
ResizeGadget(WNDW_main_background, #PB_Ignore, #PB_Ignore, LVAR_w_w-4, LVAR_w_h-4)
ResizeGadget(WNDW_main_titlebar, #PB_Ignore, #PB_Ignore, LVAR_w_w, #PB_Ignore)
ResizeGadget(WNDW_main_btn_about, LVAR_w_w - 105, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(WNDW_main_btn_min, LVAR_w_w - 70, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(WNDW_main_btn_close, LVAR_w_w - 35, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(WNDW_main_btn_resize, WindowWidth(WNDW_main)-10, WindowHeight(WNDW_main)-10, #PB_Ignore, #PB_Ignore)
EndIf
EndSelect
Select EventGadget()
Case WNDW_main_btn_about
;{ events
Select EventType()
Case #PB_EventType_MouseEnter
PROC_wndw_ctrl_btn_display(WNDW_main_btn_about, PROC_tint_rgba(GVAR_wndw_colours\wndw_about_btn, 35), GVAR_wndw_colours\wndw_titlebar_paper_a)
Case #PB_EventType_MouseLeave
PROC_wndw_ctrl_btn_display(WNDW_main_btn_about, GVAR_wndw_colours\wndw_about_btn, GVAR_wndw_colours\wndw_titlebar_paper_a)
Case #PB_EventType_LeftButtonUp
Debug "About"
EndSelect
;}
Case WNDW_main_btn_min
;{ events
Select EventType()
Case #PB_EventType_MouseEnter
PROC_wndw_ctrl_btn_display(WNDW_main_btn_min, PROC_tint_rgba(GVAR_wndw_colours\wndw_min_btn, 35), GVAR_wndw_colours\wndw_titlebar_paper_a)
Case #PB_EventType_MouseLeave
PROC_wndw_ctrl_btn_display(WNDW_main_btn_min, GVAR_wndw_colours\wndw_min_btn, GVAR_wndw_colours\wndw_titlebar_paper_a)
Case #PB_EventType_LeftButtonUp
SetWindowState(WNDW_main, #PB_Window_Minimize)
EndSelect
;}
Case WNDW_main_btn_close
;{ events
Select EventType()
Case #PB_EventType_MouseEnter
PROC_wndw_ctrl_btn_display(WNDW_main_btn_close, PROC_tint_rgba(GVAR_wndw_colours\wndw_close_btn, 35), GVAR_wndw_colours\wndw_titlebar_paper_a)
Case #PB_EventType_MouseLeave
PROC_wndw_ctrl_btn_display(WNDW_main_btn_close, GVAR_wndw_colours\wndw_close_btn, GVAR_wndw_colours\wndw_titlebar_paper_a)
Case #PB_EventType_LeftButtonUp
WNDW_main_quit = #True
EndSelect
;}
Case WNDW_main_btn_resize
;{ events
Select EventType()
Case #PB_EventType_MouseEnter
SetGadgetAttribute(WNDW_main_btn_resize, #PB_Canvas_Cursor, #PB_Cursor_LeftUpRightDown)
Case #PB_EventType_MouseLeave
SetGadgetAttribute(WNDW_main_btn_resize, #PB_Canvas_Cursor, #PB_Cursor_Default)
Case #PB_EventType_LeftButtonDown
LVAR_resize_flag = #True
; get window minimum dimensions
FirstElement(LIST_wndw())
ForEach LIST_wndw()
If LIST_wndw()\WNDW_id = WNDW_main
LVAR_m_w.i = LIST_wndw()\WNDW_m_w
LVAR_m_h.i = LIST_wndw()\WNDW_m_h
Break
EndIf
Next
Case #PB_EventType_LeftButtonUp
LVAR_resize_flag = #False
RedrawWindow_(WindowID(WNDW_main),#NUL,#NUL,#RDW_ALLCHILDREN|#RDW_INVALIDATE)
EndSelect
;}
EndSelect
Until WNDW_main_quit = #True
CloseWindow(WNDW_main)
EndProcedure
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PROC_screen_dims()
PROC_setup_colours()
PROC_wndw_main()
End
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -