Paolo Posted September 7, 2019 Share Posted September 7, 2019 Hello, I am using the symbol display control in a dialog to show various symbols to choose from. I did not find a way to get user clicks on these controls, in the dialog handler. Is there a way or should I couple each symbol with a clickable control? Thank you for any advice, Paolo Quote Link to comment
Paolo Posted September 7, 2019 Author Share Posted September 7, 2019 (edited) I have tried also with the Image Control that responds to clicks but I did not get it to display the symbol image! I am doing this way: hImg := CreateImgFromSymbol('AM-530', 128,128, 0, 11, 9); if hImg <> nil then CreateImageControl(dialog1, 4, 200, 200, hImg); but, though the hImg is not nil, the symbol is not displayed. It is replaced by the Vectorworks icon. Below the code I am using to test. Of course, replace ''AM-530" with a symbol in your document. PROCEDURE Example; VAR dialog1 :INTEGER; int :INTEGER; hImg : handle; PROCEDURE dialog1_Handler(VAR item :LONGINT; data :LONGINT); BEGIN CASE item OF SetupDialogC: BEGIN SetItemClickable(dialog1, 4, TRUE); EnableItem(dialog1, 4, TRUE); END; 4 : BEGIN writeln('Strike!'); END; END; END; BEGIN writeln('Inizio'); dialog1 := CreateLayout('Example', TRUE, 'OK', 'Cancel'); {CreateSymbolDisplayControl(dialog1, 4, 'AM-530', 128, 128, 5, 0, 2);} hImg := CreateImgFromSymbol('AM-530', 128,128, 5, 0, 2); if hImg <> nil then CreateImageControl(dialog1, 4, 200, 200, hImg); SetFirstLayoutItem(dialog1, 4); int := RunLayoutDialog(dialog1, dialog1_Handler); END; RUN(Example); Here's the results: With the symbol control, the dialog is ok, but I cannot get clicks on the symbol… With the image control, I get clicks fired, but not the correct image 🤔 Edited September 7, 2019 by Paolo Quote Link to comment
MRoth Posted September 10, 2019 Share Posted September 10, 2019 Hi Paolo I don't now if it helps you but here is en Example, where you can choose an symbol in a dialog. 1 Quote Link to comment
Paolo Posted September 10, 2019 Author Share Posted September 10, 2019 Thank you for your reply. I have seen the attached example, but I need something different. After various tries, I have opted for the image control, though I am not 100% happy because symbols converted in images shows a "2" in the lower right side of the icon (to show that are 2D symbols). You can see (in the attached image) the difference between the big tile (obtained with CreateImgFromSymbol) and the smaller tiles (obtained with CreateImageControl). It is not what I wish to get from a "Modern Dialog", but I can live with it... For those that may be interested, since there are not plenty of examples around, here's the code to get the dialog above (kLib is the path to single files and folders whose name is, as symbols, in the vectorworks file at path symLib. PROCEDURE Example; const kLib = '/Applications/Vectorworks 2019 IT/Risorse/Elementi base/Mouldings - Models/Cornices'; symLib = '/Applications/Vectorworks 2019 IT/Risorse/Elementi base/Mouldings - Models/Cornices/MouldingsLib.vwx'; maxFolders = 1000; kTreeControlID = 4; kChosenSymbol = 5; kChosenText = 6; kBackwardBtn = 7; kForwardBtn = 8; kPages = 9; kFirstSymbol = 101; kSymbolWidth = 50; kRows = 6; kColumns = 7; TYPE menuItem = STRUCTURE voce: string; idx : integer; END; VAR dialog1 :INTEGER; result :INTEGER; widthInChars, heightInChars :INTEGER; root1, root2, child1, child2 :INTEGER; folders : array[0..maxFolders] of menuItem; buttons : array[0..maxFolders] of menuItem; c, r : integer; pagina, numeroPagine, numeroFiles: integer; function validProfileFile(name: string): boolean; begin validProfileFile := Pos('.cpf', name) > 0; end; procedure ricorsione(node: string; livello: integer; previous: integer); var i: integer; foldername: string; root: integer; begin i := 1; folderName := GetFilesInFolder(node, 1); WHILE (folderName <> '') DO BEGIN {writeln(livello, '. ', i, ' -> ', foldername);} {se è una folder, faccio un altro giro} if Pos('.', folderName) = 0 then begin {è una cartella} root := InsertTreeControlItem(dialog1, kTreeControlID, folderName, previous, livello); folders[root].voce := concat(node, '/', foldername); folders[root].idx := root; ricorsione(concat(node,'/', folderName), livello+1, root); end; i := i+1; folderName := GetFilesInFolder(node, i); END; end; procedure updateDialog; var j : integer; idx : integer; begin for j := kFirstSymbol+(pagina-1)*kColumns*kRows to kFirstSymbol+(pagina)*kColumns*kRows-1 do begin idx := j-(pagina-1)*kColumns*kRows; beginContext; IF CopySymbol(symLib, buttons[j].voce) then begin Symbol(buttons[j].voce, 0, 0, 0); SetImageControlHandle(dialog1, idx,getObject(buttons[j].voce)); SetItemClickable(dialog1, idx, TRUE); EnableItem(dialog1, idx, true); SetHelpText(dialog1, idx,buttons[j].voce); ShowItem(dialog1, idx, true); end else begin SetImageControlHandle(dialog1, idx,nil); SetHelpText(dialog1, idx,''); ShowItem(dialog1, idx, false); end; endContext(0); end; end; PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT); var result: boolean; i,j : integer; fileName : string; idItem : integer; x : integer; deltaPagina : integer; BEGIN x := item-kFirstSymbol; deltaPagina := (pagina-1)*kRows*kColumns; CASE item OF SetupDialogC: BEGIN ricorsione(klib, 1, -1); updateDialog; END; kTreeControlID : BEGIN {reinizializzo array} for i := 0 to maxFolders do begin buttons[i].voce := ''; end; result := GetTreeControlSelectedItem(dialog1, kTreeControlID, idItem); i := 1; j := 0; fileName := GetFilesInFolder(folders[idItem].voce, i); WHILE (fileName <> '') DO BEGIN {se è un file…} if validProfileFile(fileName) then begin buttons[kFirstSymbol+j].voce := fileName; end else begin j := j-1; end; j := j+1; i := i+1; fileName := GetFilesInFolder(folders[idItem].voce, i); END; numeroFiles := j; pagina := 1; numeroPagine := trunc(j / (kColumns*kRows))+1; {completo con quelli vuoti} for j := j to kRows*kColumns do begin buttons[kFirstSymbol+j].voce := ''; end; SetItemText(dialog1, kchosenText, 'choose a symbol'); SetItemText(dialog1, kPages, concat(num2str(0, pagina), '/', num2Str(0, numeroPagine))); updateDialog; END; kBackwardBtn : BEGIN pagina := pagina - 1; if pagina < 1 then pagina := numeroPagine; SetItemText(dialog1, kPages, concat(num2str(0, pagina), '/', num2Str(0, numeroPagine))); updateDialog; END; kForwardBtn :BEGIN pagina := pagina + 1; if pagina > numeroPagine then pagina := 1; SetItemText(dialog1, kPages, concat(num2str(0, pagina), '/', num2Str(0, numeroPagine))); updateDialog; END; kFirstSymbol..kFirstSymbol+kRows*kColumns: BEGIN beginContext; IF CopySymbol(symLib, buttons[kFirstSymbol+x+deltaPagina].voce) then Symbol(buttons[kFirstSymbol+x+deltaPagina].voce, 0, 0, 0); updateSymbolDisplayControl(dialog1, kChosenSymbol, buttons[kFirstSymbol+x+deltaPagina].voce, 0, 2); SetHelpText(dialog1, kChosenSymbol,buttons[kFirstSymbol+x+deltaPagina].voce); endContext(0); SetItemText(dialog1, kchosenText, buttons[kFirstSymbol+x+deltaPagina].voce); END; END; END; BEGIN dialog1 := CreateLayout('Example Dialog', TRUE, 'OK', 'Cancel'); widthInChars := 28; heightInChars := 28; CreateTreeControl(dialog1, kTreeControlID, widthInChars, heightInChars); SetFirstLayoutItem(dialog1, kTreeControlID); CreateSymbolDisplayControl(dialog1, kChosenSymbol, '', kSymbolWidth*3, kSymbolWidth*3, 5 , 0 , 2); SetRightItem(dialog1, kTreeControlID, kChosenSymbol,0,0); CreateStyledStatic(dialog1, kChosenText, 'Chosen symbol', 30,2); SetStaticTextColor(dialog1, kchosenText, 256,0,0); SetRightItem(dialog1, kChosenSymbol, kChosenText,0,0); CreatePushButton(dialog1, kBackwardBtn, '<-️︎'); CreatePushButton(dialog1, kForwardBtn, '->️'); CreateCenteredStatic(dialog1, kPages, '1/1', 6); SetBelowItem(dialog1, kTreeControlID,kBackwardBtn,0,0); SetRightItem(dialog1, kBackwardBtn, kPages,0,0); SetRightItem(dialog1, kPages, kForwardBtn,0,0); for c := 0 to kColumns-1 do for r := 0 to kRows-1 do begin {CreateSymbolDisplayControl(dialog1, kFirstSymbol+c+kColumns*r, '', kSymbolWidth, kSymbolWidth, 5, 0, 2);} CreateImageControl(dialog1, kFirstSymbol+c+kColumns*r, kSymbolWidth, kSymbolWidth, nil); if (c=0) and (r = 0) then SetBelowItem(dialog1, kChosenSymbol, kFirstSymbol +c+kColumns*r,0,0); if (c=0) and (r > 0) then SetBelowItem(dialog1, kFirstSymbol +c+kColumns*(r-1), kFirstSymbol +c+kColumns*r,0,-1); if (c>0) then SetRightItem(dialog1, kFirstSymbol +c+kColumns*r-1, kFirstSymbol +c+kColumns*r,-1,0); end; result := RunLayoutDialog(dialog1, Dialog_Handler); END; RUN(Example); Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.