Solution to manage an array of controls

Started by krunch, December 14, 2010, 08:18:40 AM

Previous topic - Next topic

krunch

A solution to manage multiples controls placed "in table" (same dimension + same distance) and named "A0" "B0".

Get_ControlName calculates the position index (#column #line) of the control under the pointer
The goal is to determine which control is under the pointer, without multiplying triggers. This function can be called by any trigger.


offset depends on the border of the Form :
; Form                     TitleBar=t/AllowResizing=f   TitleBar=t/AllowResizing=t   TitleBar=f/AllowResizing=f   TitleBar=f/AllowResizing=t
; Modal                       '(3 23)                        '(8 28)                               '(0 0)                             '(7 7)
; Modeless                     '(3 21)                      '(8 26)                              '(0 0)                           '(7 7)
; Palette                     '(0 0)                         '(0 0)
; ControlBar(Docked)    '(0 17)                        '(0 17)
; ControlBar(UnDocked) '(1 36)                        '(6 24)


Code (autolisp) Select
; note: put these values in Get_ControlName once prj.odcl completed
; brd (x y)    offset due to the border of the Form
; org (x y)    position of the reference-control (upper-left)
; del (x y)     size of the reference-control (upper-left)
; int (x y)    spacing between the controls

(defun c:go ()
 (dcl_Project_Load "try" T)
 (setq prj "ControlsArray"
   dia "pctArray"
   ref "pctA0"
   brd '(3 23)
   org (list (dcl_Control_GetLeft prj dia ref) (dcl_Control_GetTop prj dia ref))
   del (list (dcl_Control_GetWidth prj dia ref) (dcl_Control_GetHeight prj dia ref))
   int '(8 8)
 )
 (dcl_Project_Load prj T)
 (dcl_Form_Show prj dia)
)

; MouseEntered/MouseMovedOff (uniques triggers)
; note: *PCT is a global handler
(defun c:ControlsArray_pctArray_pct_OnMouseEntered ()  
 (setq *PCT (Get_ControlName))
 ; paint it
 (dcl_Control_SetBackColor prj dia *PCT 16711808)
)
(defun c:ControlsArray_pctArray_pct_OnMouseMovedOff ()
 (dcl_Control_SetBackColor prj dia *PCT -6)  
)

(defun Get_ControlName (/ a b c d e f pos)
 ; pos = position index
 (setq pos (mapcar '(lambda(a b c d e f) (fix (/ (- a b c d) (+ e f)))) (dcl_GetMouseCoords) (dcl_Control_GetPos prj dia) org brd del int))
 (strcat "pct" (nth (car pos) '("A" "B" "C" "D")) (nth (last pos) '("0" "1" "2" "3")))
)


version : 6.0.2.1

krunch

#1
Hi

I have corrected and updated this functioni It works fine, but is there a way to determine if a ControlBar is "docked" or not ?

Thanks

Fred Tomke

Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

krunch

Thanks! It allows to finish this feature with ControlBar (Palette can also "float" ?)

On the other hand, as it's setted by dimensions of the Form's border, I wonder if it's a good solution.. borders may be changed from a version to a new one ?