View Full Version : DotNet controls Picture Box
MerlinEl 08-10-2009, 11:05 AM Hi
I’m trying to remake my old Asset Browser and use dotNet forms.
But when I’m searched in the internet to learn more about this stuff..
I realize what most of people create their own dll files.
And using dotnet.loadAssembly … to load them in to max.
This is very good! But not for me ,because I don’t know any of C++ or VB , Pascal …. languages
Is there any way to avoid this and create a simple browser with already existing functions in DotNet?
so.... I started to create an array of images
imgPaths = getFiles "C:\\Temp\\Images\\*.jpg"
and after, load them in to picture boxes and add in form
(
local imgPaths = getFiles "C:\\Temp\\Images\\*.jpg"
local colors = dotNetClass "System.Drawing.Color"
local dockStyle = dotNetClass "System.Windows.Forms.DockStyle"
--collect images
local imgArray = #()
for i=1 to imgPaths.count do
(
local pic = dotNetObject "System.Windows.Forms.PictureBox"
pic.width = 160
pic.height = 120
pic.Padding = dotNetObject "System.Windows.Forms.Padding" 4
--pic.Cursor = dotNetObject "System.Windows.Forms.Cursor" "C:\\temp\\images\\hnwse.cur"
pic.AllowDrop = true
imgArray[i] = pic
imgArray[i].image = (dotNetclass "System.Drawing.Image").fromfile imgPaths[i]
)
--add images to form
local dotForm = (dotNetObject "System.Windows.Forms.Form")
for i=1 to imgPaths.count do dotForm.Controls.add imgArray[i]
dotForm.Text = " Picture Box Test 1"
dotForm.topmost = true
dotForm.show()
)
Something is not right here , all the pictures is on same place.
I can’t find a command to put them right.
I’m tried also dotNetObject "System.Windows.Forms.ImageList" , but there I’m lost completely ...
I dont know why this is not working???
-- LargeIconEach item appears as a full-sized icon with a label below it.
lv.View = (dotNetClass "System.Windows.Forms.View"). LargeIcon
http://msdn.microsoft.com/en-us/library/system.windows.forms.view.aspx
rollout mc2Gallery2Dialog "3DsMax Gallery II" width:592 height:692
(
--> Local
local jpg_images_dir = "E:\\3DGallery\\Weapons\\Swords"
--< Local
dotNetControl lv "System.Windows.Forms.ListView" pos:[84,38] width:504 height:650
dropdownList ddl1 "" pos:[84,8] width:228 height:21 items:#("Class")
dropdownList ddl2 "" pos:[360,8] width:228 height:21 items:#("Type")
--> Functions
fn myCallback = ( return false )
fn fillTagsWith images =
(
fn callback_abort = ( dotnetObject "System.Drawing.Image+GetThumbnailImageAbort" myCallback())
local ptr_callback_abort = dotNetClass "System.IntPtr"
image_list = dotNetObject "System.Windows.Forms.ImageList"
image_list.ColorDepth = image_list.ColorDepth.Depth24Bit
image_list.ImageSize = dotNetObject "System.Drawing.Size" 160 120
for i in images do
(
local thumb = dotNetObject "System.Drawing.Bitmap" i
image_list.images.add thumb
)
return image_list
)
fn inicialitzaListView lv =
(
lv.View = (dotNetClass "System.Windows.Forms.View").List -- LargeIcon --X--
lv.showitemtooltips = true
)
fn fillListView lv image_list =
(
lv.Clear()
lv.SmallImageList = fillTagsWith image_list
for i = 1 to image_list.count do
(
tag = image_list[i]
ListViewOps.AddLvItem lv pTextItems:#("",(getFilenameFile tag)) pImgIndex:(i-1)
)
)
--< Functions
on mc2Gallery2Dialog open do
(
inicialitzaListView lv
--load images
if doesFileExist jpg_images_dir do
(
jpg_images = getFiles (jpg_images_dir + "\\*.jpg")
fillListView lv jpg_images
)
)
)
createDialog mc2Gallery2Dialog style:#(#style_titlebar,
#style_sysmenu, #style_minimizebox, #style_maximizebox, #style_sunkenedge, #style_resizing)
if anybody knows, please let me know... thanks
Here is a pic of my old browser...
http://mithrillgate.wgz.cz/image/14781902
Browser Usage:
1)add /store scene models (snap model to surface if exist)
2)paint models in to surface (setup random count, pos ,rotation, for each model in the set)
3)add/store scene materials
4)add/store textures
Browser Property:
1)Resizable with automatic thumbnails sorting
2)Add, delete or rename items
2)Remember user settings: thumb size, random params in set, dialog position, dialog scale, dropdown list selection ….
4) drag and drop method for models and materials + ctrl alt shift hotkeys for rotation and scale
|
|
Sure this can be done without it. You will have to be a bit more creative maybe with how you go about it. Have a look at placing the images in grid view cels or even try out extraTreeList out lined here (http://forums.cgsociety.org/showpost.php?p=6026663&postcount=373).
MerlinEl
08-10-2009, 02:52 PM
hi PEN thanks for the advice…:wavey:
but there is another problem.. it seems the XtraTreeList has no property…
maybe is because I’m using 3DsMax 9
rollout tltest "XtraTreeList Test" width: 300 height: 200
(
dotNetControl tl "DevExpress.XtraTreeList.TreeList" width: 274 height: 180
fn getInfo itm =
(
try ( format "show:%\n" (show itm) ) catch (print "undefined")
try ( format "interface:%\n" (showinterface itm) ) catch (print "undefined")
try ( format "methods:%\n" (showmethods itm) ) catch (print "undefined")
try ( format "prop:%\n" (showproperties itm) ) catch (print "undefined")
)
on tltest open do getInfo tl
)
createdialog tltest
Result in Listener:
Rollout:tltest
show:false
"undefined"
methods:false
prop:false
true
OK
MarcoBrunetta
08-10-2009, 03:15 PM
You could also create a flowLayoutPanel, and add labels or imageboxes or whatever to it's "controls" property. The flowLayoutPanel will take care of the sorting which is pretty nice.
MerlinEl
08-10-2009, 06:29 PM
I found some references about flowlayoutpanel from LoneRobot site.
I’m already made some basic functions, but I’m worry with it is to difficult for me...
rollout mc2TestGalleryDilog "3DsMax 9 Gallery II" width:556 height:597
(
--> Local
local jpg_images_dir = "E:\\3DGallery\\Weapons\\Swords"
local colorclass = dotnetclass "system.drawing.color"
--< Local
-->Interface
dotNetControl flp "flowlayoutpanel" pos:[5,52] width:543 height:531
dotNetControl legend "textbox" pos:[5,4] width:543 height:20
--<Interface
-->functions
fn Btn_Pressed sender eventargs =
(
local stringdata
legend.forecolor = sender.forecolor
legend.backcolor = if sender.text == "Transparent" then colorclass.white else sender.backcolor
--higlight thumbnails
if sender.backcolor == colorclass.yellow
then
(
stringdata = "pressed 1"--sender.tag
sender.backcolor = colorclass.cadetblue
)
else
(
stringdata = "pressed 2"--sender.text
sender.backcolor = colorclass.yellow --not working too
)
--mouse up
--btndragdrop.backcolor = (dotnetclass "System.Drawing.Color").yellow
--mouse down
--btndragdrop.backcolor = (dotnetclass "System.Drawing.Color").orangered
legend.text = stringdata
--showmethods eventargs
show eventargs
--show eventargs.Clicks
--changing cursor --not works
/*
-- sender.clientrectangle.contains args.x args.y --cant implement
if (eventargs.x !=0 and eventargs.y != 0) then
(
setsyscur #arrow
)
else
(
setSysCur #select
)
*/
)
--<functions
-->Actions
on mc2TestGalleryDilog open do
(
local singleborder = (dotNetClass "System.Windows.Forms.BorderStyle").fixedsingle
local dnfont = dotNetObject "System.Drawing.Font" "Verdana" 6.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnfontlarge = dotNetObject "System.Drawing.Font" "Verdana" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnMXSlarge = dotNetObject "System.Drawing.Font" "System" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
flp.autoscroll = true
flp.padding = dotnetobject "system.windows.forms.padding" 2
local dnobjarray = #()
Images_Array = getFiles (jpg_images_dir + "\\*.jpg")
for i in Images_Array do
(
btndragdrop = dotnetobject "button"
btndragdrop.size = dotnetobject "system.drawing.size" 160 120
--btndragdrop.backcolor = colorclass.yellow --cadetblue -- tag color
btndragdrop.forecolor = colorclass.ivory --text color
btndragdrop.margin = dotnetobject "system.windows.forms.padding" 2 -- thumbs distance
btndragdrop.flatstyle = (dotNetclass "System.Windows.Forms.FlatStyle").flat
btndragdrop.font= dnfont
btndragdrop.text = getFilenameFile i
btndragdrop.textalign = (dotnetclass "System.Drawing.ContentAlignment").BottomCenter
--btndragdrop.BackgroundImage = (dotnetclass "System.Drawing.Image").FromFile i
--btndragdrop.Image = (dotnetclass "System.Drawing.Image").FromFile i
btndragdrop.Image = dotNetObject "System.Drawing.Bitmap" i
--btndragdrop.AllowDrop = true
-----btndragdrop.AutoSize = true -- autosize thumbnail to image
--btndragdrop.DisplayRectangle
--.BorderStyle : <System.Windows.Forms.BorderStyle>
--.AllowDrop
--.Bounds : <System.Drawing.Rectangle>
dotNet.addEventHandler btndragdrop "click" Btn_Pressed
append dnobjarray btndragdrop
btndragdrop = nothing
)
--> Title of gallery type
colorlabel = dotnetobject "label"
colorlabel.borderstyle = singleborder
colorlabel.margin = dotnetobject "system.windows.forms.padding" 2
colorlabel.backcolor = colorclass.cadetblue
colorlabel.font= dnfontlarge
colorlabel.text = "3D Models"
colorlabel.size = dotnetobject "system.drawing.size" 516 24
colorlabel.textalign = (dotnetclass "System.Drawing.ContentAlignment").MiddleCenter
--show colorlabel
--< Title of gallery type
flp.controls.add colorlabel
flp.controls.addrange dnobjarray
)
--<Actions
)-- end rollout
createDialog mc2TestGalleryDilog style:#(#style_titlebar,
#style_sysmenu, #style_minimizebox, #style_maximizebox, #style_sunkenedge, #style_resizing)
thanks MacroBruneta for you tip ;)
thanks to you LoneRobot, DotNetClass Color Chart is very cool. (much stuff to learn...)
I didn't even think about flowlayoutpanel, that would be the way to go.
MarcoBrunetta
08-10-2009, 07:35 PM
I actually started experimenting with it a few weeks ago and it seems extremely useful. Sure wish there was a .net for dummies guide somewhere online.
I'm slowly trying to write it. But there is so much to know.
MarcoBrunetta
08-10-2009, 07:52 PM
Well... do you accept contributions? :)
Always...how ever, it doesn't mean it will get done faster .
MarcoBrunetta
08-10-2009, 07:54 PM
Cool, I'll see about reformatting my .net notes into something readable if I get some time.
MerlinEl
08-11-2009, 08:57 AM
So.. is one step forward now
I have :
-sorted images
-highlighting
-multiselection
rollout mc2TestGalleryDilog "3DsMax 9 Gallery II" width:556 height:597
(
--> Local
local jpg_images_dir = "E:\\3DGallery\\Weapons\\Swords"
local colorclass = dotnetclass "system.drawing.color"
--< Local
-->Interface
dotNetControl flp "flowlayoutpanel" pos:[5,52] width:543 height:531
dotNetControl legend "textbox" pos:[5,4] width:543 height:20
--<Interface
-->functions
fn showInfo itm =
(
print "---------------------------------------------------------------------------"
format "Info:%\n" itm
print "---------------------------------------------------------------------------"
try ( format "show:%\n" (show itm) ) catch (print "undefined")
try ( format "interface:%\n" (showinterface itm) ) catch (print "undefined")
try ( format "methods:%\n" (showmethods itm) ) catch (print "undefined")
try ( format "prop:%\n" (showproperties itm) ) catch (print "undefined")
)
fn onMouseDown ctrl evnt =
(
format "MouseDown: % [%]\n" ctrl (evnt.button.tostring())
if ctrl.forecolor == colorclass.red
then (ctrl.forecolor = colorclass.yellow; legend.text = "MouseDown Unselected")
else (ctrl.forecolor = colorclass.red; legend.text = "MouseDown Selected")
)
fn onMouseUp ctrl evnt =
(
-- format "MouseUp: % [%]\n" ctrl (evnt.button.tostring())
)
fn onMouseEnter ctrl evnt =
(
--format "MouseEnter % [%]\n" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.yellow
legend.text = "MouseEnter"
)
fn onMouseLeave ctrl evnt =
(
--format "MouseLeave % [%]\n" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.ivory
legend.text = "MouseLeave"
)
--<functions
-->Actions
on mc2TestGalleryDilog open do
(
local singleborder = (dotNetClass "System.Windows.Forms.BorderStyle").fixedsingle
local dnfont = dotNetObject "System.Drawing.Font" "Verdana" 6.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnfontlarge = dotNetObject "System.Drawing.Font" "Verdana" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnMXSlarge = dotNetObject "System.Drawing.Font" "System" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
flp.autoscroll = true
flp.padding = dotnetobject "system.windows.forms.padding" 2
flp.BackColor = colorclass.fromARGB 40 45 66
--flp.
local dnobjarray = #()
Images_Array = getFiles (jpg_images_dir + "\\*.jpg")
for i in Images_Array do
(
btndragdrop = dotnetobject "button"
btndragdrop.size = dotnetobject "system.drawing.size" 160 120
--btndragdrop.backcolor = colorclass.yellow --cadetblue -- tag color
btndragdrop.forecolor = colorclass.ivory --text color
btndragdrop.margin = dotnetobject "system.windows.forms.padding" 2 -- thumbs distance
btndragdrop.flatstyle = (dotNetclass "System.Windows.Forms.FlatStyle").flat
btndragdrop.font= dnfont
btndragdrop.text = getFilenameFile i
btndragdrop.textalign = (dotnetclass "System.Drawing.ContentAlignment").BottomCenter
btndragdrop.Image = dotNetObject "System.Drawing.Bitmap" i
btndragdrop.AllowDrop = true
-- Setup an event handler for both buttons
dotnet.addEventHandler btndragdrop "MouseDown" onMouseDown
dotnet.addEventHandler btndragdrop "MouseUp" onMouseUp
dotnet.addEventHandler btndragdrop "MouseEnter" onMouseEnter
dotnet.addEventHandler btndragdrop "MouseLeave" onMouseLeave
append dnobjarray btndragdrop
btndragdrop = nothing
)
--> Title of gallery type
colorlabel = dotnetobject "label"
colorlabel.borderstyle = singleborder
colorlabel.margin = dotnetobject "system.windows.forms.padding" 2
colorlabel.backcolor = colorclass.cadetblue
colorlabel.font= dnfontlarge
colorlabel.text = "3D Models"
colorlabel.size = dotnetobject "system.drawing.size" 516 24
colorlabel.textalign = (dotnetclass "System.Drawing.ContentAlignment").MiddleCenter
--show colorlabel
--< Title of gallery type
flp.controls.add colorlabel
flp.controls.addrange dnobjarray
)
--<Actions
)-- end rollout
createDialog mc2TestGalleryDilog style:#(#style_titlebar,
#style_sysmenu, #style_minimizebox, #style_maximizebox, #style_sunkenedge, #style_resizing)
What I can’t find is:
-how to stretch an image to button size (if is some method here or must be done by fn)
-how to make bigger the outline around button to be more visible
-how to resize and update flowlayoutpanel if dialog size changes
MarcoBrunetta
08-11-2009, 01:28 PM
-how to stretch an image to button size (if is some method here or must be done by fn)
There might be a better method, but here's the function I use when I need to resize a .NET bitmap object:
fn resizeBitmapNET srcBitmap width height useHighQuality:false=
--Resizes the specified NET bitmap
(
local destBitmap = (dotNetObject "System.Drawing.Bitmap" width height) --Create new bitmap object
destBitmap.SetResolution srcBitmap.HorizontalResolution srcBitmap.VerticalResolution
local theGraphics = (dotNetClass "System.Drawing.Graphics").fromImage destBitmap --Create new Graphics object
local destRec = (dotnetObject "System.Drawing.rectangle" 0 0 width height) --Set destination image size
IF useHighQuality DO theGraphics.InterpolationMode = theGraphics.InterpolationMode.HighQualityBicubic
theGraphics.drawImage srcBitmap destRec --Resize the image
theGraphics.dispose() --gc
return destBitmap
)
-how to make bigger the outline around button to be more visible
No clue...sorry
-how to resize and update flowlayoutpanel if dialog size changes
There's no need to update the FLP panel, if it's properly configured, then the buttons will re-align by themselves. What you need to do is set up a rollout resized event to the FLP's with and height, so that when the rollout is resized so is the FLP (and the label control).
MerlinEl
08-11-2009, 04:11 PM
oho! :beer: MarcoBrunetta you function is very fast, and doing exactly what I need. Thanks for this!
New updates:
-add cursors arrrowHand and dragHand on tags
-add MarcoBrunetta's function for resize images
-add first quick control to resize dialog and thumbnail form
Global mc2TestGalleryDilog
if mc2TestGalleryDilog != undefined do destroyDialog mc2TestGalleryDilog
rollout mc2TestGalleryDilog "3DsMax 9 Gallery II" width:556 height:597
(
--> Local
local jpg_images_dir = "E:\\3DGallery\\Weapons\\Swords" --put a path with images here
local colorclass = dotnetclass "system.drawing.color"
local cursor_harrow = dotNetObject "System.Windows.Forms.Cursor" "C:\WINDOWS\Cursors\harrow.cur"
local cursor_hmove = dotNetObject "System.Windows.Forms.Cursor" "C:\WINDOWS\Cursors\hmove.cur"
local thumb_size = [160, 120]
--< Local
-->Interface
dotNetControl flp "flowlayoutpanel" pos:[5,52] width:543 height:531
--MaxWidth for forms Width, MaxHeight to = (unset)
dotNetControl legend "textbox" pos:[5,4] width:543 height:20
--<Interface
-->functions
fn showInfo itm =
(
print "---------------------------------------------------------------------------"
format "Info:%\n" itm
print "---------------------------------------------------------------------------"
try ( format "show:%\n" (show itm) ) catch (print "undefined")
try ( format "interface:%\n" (showinterface itm) ) catch (print "undefined")
try ( format "methods:%\n" (showmethods itm) ) catch (print "undefined")
try ( format "prop:%\n" (showproperties itm) ) catch (print "undefined")
)
fn resizeBitmapNET srcBitmap width height useHighQuality:false=
--Resizes the specified NET bitmap // MarcoBrunetta
(
local destBitmap = (dotNetObject "System.Drawing.Bitmap" width height) --Create new bitmap object
destBitmap.SetResolution srcBitmap.HorizontalResolution srcBitmap.VerticalResolution
local theGraphics = (dotNetClass "System.Drawing.Graphics").fromImage destBitmap --Create new Graphics object
local destRec = (dotnetObject "System.Drawing.rectangle" 0 0 width height) --Set destination image size
IF useHighQuality DO theGraphics.InterpolationMode = theGraphics.InterpolationMode.HighQualityBicubic
theGraphics.drawImage srcBitmap destRec --Resize the image
theGraphics.dispose() --gc --but images is stil locked. cant be deleted
return destBitmap
)
fn onMouseDown ctrl evnt =
(
format "MouseDown: % [%]\n" ctrl (evnt.button.tostring())
if ctrl.forecolor == colorclass.red
then (ctrl.forecolor = colorclass.yellow; legend.text = ctrl.text + " Unselected")
else (ctrl.forecolor = colorclass.red; legend.text = ctrl.text + " Selected")
ctrl.Cursor = cursor_hmove
)
fn onMouseUp ctrl evnt =
(
ctrl.Cursor = cursor_harrow
-- format "MouseUp: % [%]\n" ctrl (evnt.button.tostring())
)
fn onMouseEnter ctrl evnt =
(
--format "MouseEnter % [%]\n" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.yellow
legend.text = "MouseEnter: " + ctrl.text
ctrl.Cursor = cursor_harrow
)
fn onMouseLeave ctrl evnt = --drag and drop
(
--format "MouseLeave % [%]\n" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.ivory
--legend.text = "MouseLeave: " + ctrl.text
)
fn onMouseMove ctrl evnt =
(
--format "Move!\n\tSender : %\n\tMouse Pos : %\n" ctrl.Text [evnt.X, evnt.Y]
)
--<functions
-->Actions
on mc2TestGalleryDilog open do
(
local singleborder = (dotNetClass "System.Windows.Forms.BorderStyle").fixedsingle
local dnfont = dotNetObject "System.Drawing.Font" "Verdana" 6.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnfontlarge = dotNetObject "System.Drawing.Font" "Verdana" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnMXSlarge = dotNetObject "System.Drawing.Font" "System" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnobjarray = #()
Images_Array = getFiles (jpg_images_dir + "\\*.jpg")
for i in Images_Array do
(
btndragdrop = dotnetobject "button"
btndragdrop.size = dotnetobject "system.drawing.size" thumb_size.x thumb_size.y --160 120
--btndragdrop.backcolor = colorclass.yellow --cadetblue -- tag color
btndragdrop.forecolor = colorclass.ivory --text color
btndragdrop.margin = dotnetobject "system.windows.forms.padding" 2 -- thumbs distance
btndragdrop.flatstyle = (dotNetclass "System.Windows.Forms.FlatStyle").flat
btndragdrop.font= dnfont
btndragdrop.text = getFilenameFile i
btndragdrop.textalign = (dotnetclass "System.Drawing.ContentAlignment").BottomCenter
local img = dotNetObject "System.Drawing.Bitmap" i
img = resizeBitmapNET img thumb_size.x thumb_size.y
btndragdrop.Image = img
btndragdrop.AllowDrop = true
gc()
-- Setup an event handlers for both buttons
dotnet.addEventHandler btndragdrop "MouseDown" onMouseDown
dotnet.addEventHandler btndragdrop "MouseUp" onMouseUp
dotnet.addEventHandler btndragdrop "MouseEnter" onMouseEnter
dotnet.addEventHandler btndragdrop "MouseLeave" onMouseLeave
dotnet.addEventHandler btndragdrop "MouseMove" onMouseMove
append dnobjarray btndragdrop
btndragdrop = nothing
)
--> Title of gallery type
colorlabel = dotnetobject "label"
colorlabel.borderstyle = singleborder
colorlabel.margin = dotnetobject "system.windows.forms.padding" 2
colorlabel.backcolor = colorclass.cadetblue
colorlabel.font= dnfontlarge
colorlabel.text = "3D Models"
colorlabel.size = dotnetobject "system.drawing.size" 516 24
colorlabel.textalign = (dotnetclass "System.Drawing.ContentAlignment").MiddleCenter
--show colorlabel
--< Title of gallery type
flp.controls.add colorlabel
flp.controls.addrange dnobjarray
--flp.MaximumSize = [1000,1000]
--flp.MinimumSize = [100,100]
flp.AutoSize = true
flp.autoscroll = true
flp.padding = dotnetobject "system.windows.forms.padding" 2
flp.BackColor = colorclass.fromARGB 40 45 66
showinfo flp
)
on mc2TestGalleryDilog resized size do
(
flp.width = flp.width + (size.x - flp.width) - 13 --offset
flp.height = flp.height + (size.y - flp.height) - 66 --offset
--format "v:%\th:%\tsize:%\n" flp.width flp.height size
)
--<Actions
)-- end rollout
createDialog mc2TestGalleryDilog style:#(#style_titlebar,
#style_sysmenu, #style_minimizebox, #style_maximizebox, #style_sunkenedge, #style_resizing)
for now ,all is going pretty good... next steps is to add some rollouts and buttons
I think I can do that
MarcoBrunetta
08-11-2009, 04:21 PM
Nice. I've noticed you've done some work with the cursors, personally when a script is gonna requiere some loading that might take more that say a second, I like to include something like:
local cursors = dotNetClass "System.Windows.Forms.Cursors"
local cursor = dotNetClass "System.Windows.Forms.Cursor"
cursor.current = cursors.WaitCursor
--SOME CODE THAT TAKES TIME
cursor.current = cursors.arrowCursor
That way people KNOW that the script is working. It's pretty easy to implement and it makes it look a lot more "professional" I think.
MerlinEl
08-12-2009, 07:49 AM
Yes Indeed! I like it.
Thanks Again MacroBrunetta :thumbsup:
MerlinEl
08-14-2009, 03:23 PM
Hi
again I'm need some help here...if is possible?
when I'm run this scrip all works fine ... almost
the problem is.. when I'm press any butoon loaded in "flowlayoutpanel" with command
mergeMAXFile maxFilePath
or
simple reseting max from his own menu file/reset
Then buttons loaded in "flowlayoutpanel" stops working.
(no hilglights , no rc menu, the buttons is only sortable when i resize dialog else is comlpetly dead)
here is code
------------------
------------------
-- --
-- 3D Gallery --
-- --
------------------
------------------
Global mc3DgalleryDialog
Global mc2TextBoxDialog
if mc3DgalleryDialog != undefined do destroyDialog mc3DgalleryDialog
rollout mc3DgalleryDialog " 3DGallery II: Models" width:624 height:444
(
--> Local
local Root_Dir="", Current_Dir = "", lastMainCat="", lastSubCat=""
local Img_Logo = (mc2Path()+"Img\\3DGall_About_01.bmp")
local colorclass = dotnetclass "system.drawing.color"
local cursor_harrow = dotNetObject "System.Windows.Forms.Cursor" "C:\WINDOWS\Cursors\harrow.cur" --temp cursor
local cursor_hmove = dotNetObject "System.Windows.Forms.Cursor" "C:\WINDOWS\Cursors\hmove.cur" --temp cursor
local singleborder = (dotNetClass "System.Windows.Forms.BorderStyle").fixedsingle
local dnfontlarge = dotNetObject "System.Drawing.Font" "Verdana" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnMXSlarge = dotNetObject "System.Drawing.Font" "System" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnfont = dotNetObject "System.Drawing.Font" "Verdana" 6.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local thumb_size = [160, 120]
local selected_items = #(), cat_offset, grp_offset, prg_offset
--< Local
-->Interface
GroupBox grp_cat "" pos:[64,76] width:556 height:348
Timer tmr_resize "Timer" pos:[4,4] width:24 height:24 enabled:true interval:100 active:false
--progressBar progbar "ProgressBar" pos:[64,428] width:555 height:12
dotNetControl progbar "Windows.Forms.Progressbar" pos:[64,428] width:555 height:12
--
bitmap bmpBg1 "Bitmap" pos:[72,20] width:268 height:28 bitmap:(BitMap 1 1 color:(color 244 220 50))
bitmap bmpBg2 "Bitmap" pos:[348,20] width:268 height:28 bitmap:(BitMap 1 1 color:(color 50 200 240))
dropdownList ddlMainClass "" pos:[76,24] width:260 height:21
dropdownList ddlSubCalss "" pos:[352,24] width:260 height:21
--
button btnCreMainCls "" pos:[8,24] width:24 height:24 images:(mc2Call.getIcon 161) toolTip:"Create Main Class"
button btnDelMainCls "" pos:[32,24] width:24 height:24 images:(mc2Call.getIcon 150) toolTip:"Delete Main Class"
button btnCreSubCls "" pos:[8,48] width:24 height:24 images:(mc2Call.getIcon 142) toolTip:"Create Sub Class"
button btnDelSubCls "" pos:[32,48] width:24 height:24 images:(mc2Call.getIcon 141) toolTip:"Delete Sub Class"
button btnAddModel "" pos:[32,104] width:24 height:24 images:(mc2Call.getIcon 149) toolTip:"Add selection to Library (press <Ctrl> for quick preview)"
button btnMergeModel "" pos:[8,104] width:24 height:24 images:(mc2Call.getIcon 147) toolTip:"Add selection to Scene (press <Ctrl> to disable automatic rename)"
button btnRenModel "" pos:[8,128] width:24 height:24 images:(mc2Call.getIcon 144) toolTip:"Rename Model"
button btnDelModel "" pos:[32,128] width:24 height:24 images:(mc2Call.getIcon 148) toolTip:"Delete Model"
checkbutton ckb_plant "" pos:[8,208] width:24 height:24 images:(mc2Call.getIcon 145) toolTip:"Planting"
checkbutton ckbPSurf "" pos:[8,184] width:24 height:24 images:(mc2Call.getIcon 146) toolTip:"Pick a surface for planting"
checkbutton ckb_cfg "" pos:[8,264] width:24 height:24 images:(mc2Call.getIcon 143) toolTip:"3DGallery..."
checkbutton ckb_multi_plant "" pos:[32,208] width:24 height:24 images:(mc2Call.getIcon 163) toolTip:"Multiplanting"
checkbutton ckb_plant_dialog "" pos:[32,184] width:24 height:24 images:(mc2Call.getIcon 164) toolTip:"Plant Customize..."
button btnHlp "" pos:[32,264] width:24 height:24 images:(mc2Call.getIcon 162) toolTip:"Help..."
--
--
label lbl4 "Main class:" pos:[72,4] width:180 height:16
label lbl5 "Sub class:" pos:[348,4] width:180 height:16
--
dotNetControl flp_cat "flowlayoutpanel" pos:[66,86] width:548 height:332
dotNetControl tb "System.Windows.Forms.Tabcontrol" pos:[72,56] width:160 height:20
dotNetControl edt_search "textbox" pos:[348,56] width:267 height:20
GroupBox grp8 "Catalog:" pos:[4,4] width:56 height:76
GroupBox grp11 "Models:" pos:[4,84] width:56 height:76
GroupBox grp12 "Paint:" pos:[4,164] width:56 height:76
GroupBox grp13 "SetUp:" pos:[4,244] width:56 height:52
button btn_search "Search" pos:[296,56] width:48 height:20
button btn_rename "Rename" pos:[244,56] width:48 height:20
--<Interface
-->functions
fn getLastDirFrom path =
(
local arr = ( filterString path "\\" )
return arr[arr.count]
)
fn resizeBitmapNET srcBitmap width height useHighQuality:false=
(
local destBitmap = (dotNetObject "System.Drawing.Bitmap" width height) --Create new bitmap object
destBitmap.SetResolution srcBitmap.HorizontalResolution srcBitmap.VerticalResolution
local theGraphics = (dotNetClass "System.Drawing.Graphics").fromImage destBitmap --Create new Graphics object
local destRec = (dotnetObject "System.Drawing.rectangle" 0 0 width height) --Set destination image size
IF useHighQuality DO theGraphics.InterpolationMode = theGraphics.InterpolationMode.HighQualityBicubic
theGraphics.drawImage srcBitmap destRec --Resize the image
theGraphics.dispose() --gc
return destBitmap
)
fn resizeInterface size =
(
--local h = cat_size.x + (size.x - cat_size.x)
--local v = cat_size.y + (size.y - cat_size.y)
flp_cat.width += size.x - flp_cat.width - cat_offset.x
flp_cat.height += size.y - flp_cat.height - cat_offset.y
grp_cat.width += size.x - grp_cat.width - grp_offset.x
grp_cat.height += size.y - grp_cat.height - grp_offset.y
progbar.width += size.x - progbar.width - grp_offset.x
progbar.pos.y += size.y - progbar.pos.y - prg_offset.y
)
fn textBox =
(
rollout mc2TextBoxDialog " Command Box v0.1" width:444 height:40
(
-->locals
local dir = getINISetting mc2UserINI "3DGallery" "Current_Dir"
--<locals
edittext edtBox "New Name:" pos:[12,12] width:312 height:16 bold:true
button btnAcpt "Accept" pos:[332,12] width:48 height:16
button btnCncl "Cancel" pos:[384,12] width:48 height:16
groupBox grpTx "" pos:[4,0] width:436 height:36
fn correctSymbolCheck text =
(
if text.count == 0 do return false
local badSymbols = "\/*?"
for t=1 to text.count do
(
for s=1 to badSymbols.count do
(
if text[t] == badSymbols[s] do
(
messagebox "Incorrect Name.\nSymbols \ / ?* are not allowed." title:"3DGallery!"
return false
)
)
)
return true
)
on mc2TextBoxDialog open do (setFocus edtBox)
on mc2TextBoxDialog rbuttonup pos do(edtBox.text = "" ;destroyDialog mc2TextBoxDialog)
on btnAcpt pressed do
(
local theName = edtBox.text
if correctSymbolCheck theName then
(
local existingNames = (for i in (getFiles (dir+"*.*")) collect (getFilenameFile i)) --check for duplicate names
if (findItem existingNames theName) == 0 --check for duplicate names
then (DestroyDialog mc2TextBoxDialog)
else (messagebox ("The name:<"+edtBox.text+"> is allready exist.") title:" 3D Gallery:" ; setFocus edtBox)
)
else (setFocus edtBox)
)
on btnCncl pressed do (edtBox.text = "" ; DestroyDialog mc2TextBoxDialog)
)
--center to main dialog
local dPos = getDialogPos mc3DgalleryDialog
local dSize = getDialogSize mc3DgalleryDialog
local inPos =[dPos.x + (dSize.x/2) - 222, dPos.y + (dSize.y/2)]
CreateDialog mc2TextBoxDialog pos:inPos style:#(#style_border) modal:true
return mc2TextBoxDialog.edtBox.text
)
fn renderModel img_path =
(
--get ini setting for render
local anti = execute(getIniSetting mc2UserINI "3DGallery" "AntiAliasing" )
local samp = execute(getIniSetting mc2UserINI "3DGallery" "PixelSampler" )
local shad = execute(getIniSetting mc2UserINI "3DGallery" "Shadows" )
local quei = execute(getIniSetting mc2UserINI "3DGallery" "Quiet" )
--Render to vbf
local oldBgColor = backgroundColor
backgroundColor = execute (getIniSetting mc2UserINI "3DGallery" "Thumb_Color")
local imgSize = execute (getIniSetting mc2UserINI "3DGallery" "Thumb_Render_Size")
local img = bitmap imgSize.x imgSize.y color:backgroundColor
--render phase
render outputsize:imgSize antiAliasing:anti enablePixelSampler:samp shadows:shad \
quiet:quei renderType:#selection to:img vfb:off -- outputFile:(img_path+".jpg")
--if path is undefined make render with prewiew
img.filename = img_path
save img quiet:on
backgroundColor = oldBgColor -- return old bg color
return img
)
fn deleteFromGallery =
(
if selected_items.count == 0 do return false
if not (queryBox "You are sure to delete selected models?" title:" Deleting Models:?") do return false
local cat_IniFile = (Root_Dir+"User_"+lastMainCat+".ini")
progbar.foreColor = colorclass.red
for i=1 to selected_items.count do
(
try flp_cat.controls.RemoveByKey selected_items[i] catch ()
flp_cat.Refresh()
--.IsReadOnly = false
try deleteFile (Current_Dir+selected_items[i]+".jpg") catch (print ("deleting: "+Current_Dir+selected_items[i]+".jpg failed"))
try deleteFile (Current_Dir+selected_items[i]+".max") catch (print ("deleting: "+Current_Dir+selected_items[i]+".max failed"))
try delINISetting cat_IniFile lastSubCat selected_items[i] catch ()
progbar.value = 100.*i/selected_items.count
)
progbar.value = 0
--flp_cat.Refresh() --flp_cat.update() --.SuspendLayout() --.ResetBindings()-- .ResetImeMode()
)
fn mergeModels =
(
if selected_items.count == 0 do return false
progbar.foreColor = colorclass.LightSteelBlue
for i=1 to selected_items.count do
(
local f = Current_Dir+selected_items[i]+".max"
if doesFileExist f do
(
try (mergeMAXFile f #useSceneMtlDups #mergeDups #select )
catch (messagebox ( "Merging model:<" + selected_items[i] + "> is failed.\nFile is mising or is corupted." ) title: " Warning!")
--prevent dupplicate names in scene
if not keyboard.controlPressed then (for o in selection do o.name = uniqueName (o.name))
)
progbar.value = 100.*i/selected_items.count
)
progbar.value = 0
--setfocus mc3DgalleryDialog.flp_cat
)
fn onMouseDown ctrl evnt =
(
--format "MouseDown: % [%]\n" ctrl (evnt.button.tostring())
local RButton = (evnt.button == (dotNetClass "System.Windows.Forms.MouseButtons").Right)
local itmName = ctrl.text
if RButton then --"Show RC Menu"
(
rcMenu thumbMenu
(
menuItem new_1 "Add To Scene..."
separator file_menu_1
menuItem new_2 "Rename ..."
menuItem new_3 "Delete..."
on new_1 picked do mergeModels()
on new_2 picked do format " Rename... %\n" selected_items
on new_3 picked do deleteFromGallery()
)
PopupMenu thumbMenu
)
--if System.Windows.Forms.Control.MouseButtons == System.Windows.Forms.MouseButtons.Left
else if ctrl.forecolor == colorclass.red
then
(
deleteItem selected_items (findItem selected_items itmName)
ctrl.forecolor = colorclass.yellow
)
else
(
append selected_items itmName
ctrl.forecolor = colorclass.red
edt_search.text = ctrl.text
)
ctrl.Cursor = cursor_hmove
)
fn onMouseUp ctrl evnt =
(
ctrl.Cursor = cursor_harrow
-- format "MouseUp: % [%]\n" ctrl (evnt.button.tostring())
)
fn onMouseEnter ctrl evnt =
(
--format "MouseEnter % [%]\n" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.yellow
ctrl.Cursor = cursor_harrow
)
fn onMouseLeave ctrl evnt = --drag and drop
(
--format "MouseLeave % [%]\n" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.LightSteelBlue
--edt_search.text = "MouseLeave: " + ctrl.text
)
fn onMouseMove ctrl evnt =
(
--format "Move!\n\tSender : %\n\tMouse Pos : %\n" ctrl.Text [evnt.X, evnt.Y]
)
fn getRootDir =
(
if mc2UserINI == undefined or not doesFileExist mc2UserINI do return false
local Root_Dir = (getINISetting mc2UserINI "3DGallery" "Root_Dir")
if doesFileExist Root_Dir do return Root_Dir
if mc2GallerySetupDialog != undefined do destroyDialog mc2GallerySetupDialog
rollout mc2GallerySetupDialog " Inicialize 3DGallery Database:" width:332 height:148
(
local Root_Dir = ""
GroupBox grpDir "Please put you 3DGallery directory..." pos:[8,4] width:316 height:136
button btnSetDir "Set Dir" pos:[16,108] width:164 height:24
bitmap bmpPop1 "Bitmap" pos:[16,24] width:300 height:80 fileName:Img_Logo
button BtnCancel "Cancel" pos:[252,108] width:64 height:24
on btnCancel pressed do (destroyDialog mc2GallerySetupDialog)
on btnSetDir pressed do
(
local p = (getSavePath caption:"Chose Catalog Directory.")
if p != undefined do
(
Root_Dir = p+"\\"
setINISetting mc2UserINI "3DGallery" "Root_Dir" Root_Dir
destroyDialog mc2GallerySetupDialog
)
)
)
createDialog mc2GallerySetupDialog style:#(#style_toolwindow) modal:true
return mc2GallerySetupDialog.Root_Dir
)
fn addImageToButton img_path =
(
local img_btn = dotnetobject "button"
img_btn.size = dotnetobject "system.drawing.size" thumb_size.x thumb_size.y --160 120
--img_btn.backcolor = colorclass.yellow --cadetblue -- tag color
img_btn.forecolor = colorclass.LightSteelBlue --text color
img_btn.margin = dotnetobject "system.windows.forms.padding" 2 -- thumbs distance
img_btn.flatstyle = (dotNetclass "System.Windows.Forms.FlatStyle").flat
img_btn.font= dnfont
img_btn.text = getFilenameFile img_path
img_btn.name = img_btn.text
img_btn.textalign = (dotnetclass "System.Drawing.ContentAlignment").BottomCenter
local img_path = dotNetObject "System.Drawing.Bitmap" img_path
local img_copy = resizeBitmapNET img_path thumb_size.x thumb_size.y
img_path.Dispose()
img_btn.Image = img_copy
img_btn.AllowDrop = true
--img_btn.showTooltip -- WIP
-- Setup an event handlers for both buttons
dotnet.addEventHandler img_btn "MouseDown" onMouseDown
dotnet.addEventHandler img_btn "MouseUp" onMouseUp
dotnet.addEventHandler img_btn "MouseEnter" onMouseEnter
dotnet.addEventHandler img_btn "MouseLeave" onMouseLeave
dotnet.addEventHandler img_btn "MouseMove" onMouseMove
--mc2system.show img_path
--gc()
return img_btn
)
fn loadGallery type:1 = --type = tab controll state
(
selected_items = #()
flp_cat.controls.clear()
Current_Dir = Root_Dir + lastMainCat + "\\" + lastSubCat + "\\"
setINISetting mc2UserINI "3DGallery" "Current_Dir" Current_Dir
--format "Current_Dir:%\n" Current_Dir
if not doesFileExist Current_Dir do return false
local Images_Array = getFiles (Current_Dir + "*.jpg")
--change cursor to wait
local cursors = dotNetClass "System.Windows.Forms.Cursors"
local cursor = dotNetClass "System.Windows.Forms.Cursor"
cursor.current = cursors.WaitCursor
case type of -- WIP
(
0:(print "Loading... Models")
1:(print "Loading... Materials" )
2:(print "Loading... Textures")
)
progbar.foreColor = colorclass.LightSteelBlue
local dnobjarray = #()
for i=1 to Images_Array.count do
(
flp_cat.controls.add (addImageToButton Images_Array[i])
--append dnobjarray (addImageToButton Images_Array[i])
progbar.value = 100.*i/Images_Array.count
)
--flp_cat.controls.addrange dnobjarray
cursor.current = cursors.Arrow
progbar.value = 0
)
fn addTogallery =
(
if selection.count == 0 do (messageBox "Select some object to add." title:"3DGallery!" ;return false)
if lastSubCat == undefined do (messageBox "Create <Sub clas> catalog." title:"3DGallery!" ;return false)
local name_from_box = textBox()
if name_from_box == "" do return false
--render selection
local img_path = Current_Dir+name_from_box+".jpg"
local max_path = Current_Dir+name_from_box+".max"
local useIniFile = (Root_Dir+"User_"+lastMainCat+".ini")
renderModel img_path
--save selection
saveNodes selection max_path
--security lock and user data
if not doesFileExist useIniFile do
(
local f = createFile useIniFile
close f
)
--reload , resort gallery
loadGallery type:tb.SelectedIndex
--mc2system.show flp_cat
--create a button and load thummbnail
--flp_cat.controls.add (addImageToButton img_path)
--flp_cat.Refresh().flp_cat.update().SuspendLayout().ResetBindings().ResetImeMode().Invalidate()
)
fn loadMainCat = --remember main dir where you browse last time
(
--collect folders for main cat
local mainDirs = sort(getDirectories (Root_Dir+"*.*"))
if mainDirs.count == 0 do return false
ddlMainClass.items = for i in mainDirs collect (getLastDirFrom i)--get the last dir from path
--last main cat
lastMainCat = getINISetting mc2UserINI "3DGallery" "lastMainCat"
if (local num = findItem ddlMainClass.items lastMainCat) != 0
then (ddlMainClass.selection = num)
else (ddlMainClass.selection = 1 ; lastMainCat = ddlMainClass.items[1])
return true
)
fn loadSubCat = --remember sub dir where you browse last time
(
--collect folders for sub cat
local subDirs = sort( getDirectories (Root_Dir + lastMainCat + "\\*.*") )
if subDirs.count == 0 do return false
ddlSubCalss.items = for i in subDirs collect (getLastDirFrom i)--get the last dir from path
--last sub cat
lastSubCat = getINISetting mc2UserINI "3DGallery" "lastSubCat"
if (local num = findItem ddlSubCalss.items lastSubCat) != 0
then (ddlSubCalss.selection = num)
else (ddlSubCalss.selection = 1 ; lastSubCat = ddlSubCalss.items[1])
loadGallery type:tb.SelectedIndex
return true
)
fn tabControll iobj lvl =
(
case lvl of
(
0:(iobj.title = " 3DGallery II: Models")
1:(iobj.title = " 3DGallery II: Materials")
2:(iobj.title = " 3DGallery II: Textures")
)
)
fn inicializeInterface =
(
-->check gallery root dir
Root_Dir = getRootDir()
if not doesFileExist Root_Dir do return false
--format "Root_Dir:%\n" Root_Dir
-->collect params for resizing interface
local cat_size = [flp_cat.width , flp_cat.height ]
local grp_size = [grp_cat.width , grp_cat.height ]
local dia_size = [mc3DgalleryDialog.width, mc3DgalleryDialog.height]
cat_offset = dia_size - cat_size
grp_offset = dia_size - grp_size
prg_offset = dia_size - progbar.pos
--<collect params for resizing interface
-->Tabs
local Tabs_Array = #("Models", "Materials", "Textures")
for i in Tabs_Array do
(
tb.TabPages.add i
)
--<Tabs
-->Progress Bar
--progbar.style = progbar.style.continuous
progbar.backColor = colorclass.fromARGB 40 45 66
--<Progress Bar
--flp_cat.MaximumSize
--flp_cat.MinimumSize
flp_cat.AutoSize = true
flp_cat.autoscroll = true
flp_cat.padding = dotnetobject "system.windows.forms.padding" 2
flp_cat.BackColor = colorclass.fromARGB 40 45 66
-->load dropDown lists Main & Sub
local sub_cat_found = if loadMainCat() then loadSubCat() else false
--mc2System.show flp_cat
return true
)
--<functions
-->Actions
on mc3DgalleryDialog open do (if not inicializeInterface() do destroyDialog mc3DgalleryDialog)
on tb Selected itm do (tabControll mc3DgalleryDialog itm.TabPageIndex )
on mc3DgalleryDialog resized size do (resizeInterface size)
on mc3DgalleryDialog lbuttondblclk pos do (loadGallery type:tb.SelectedIndex)
on ddlMainClass selected sel do
(
if sel != 0 do
(
setINISetting mc2UserINI "3DGallery" "lastMainCat" ddlMainClass.items[sel]
lastMainCat = ddlMainClass.items[sel]
loadSubCat()
)
)
on ddlSubCalss selected sel do
(
if sel != 0 do
(
setINISetting mc2UserINI "3DGallery" "lastSubCat" ddlSubCalss.items[sel]
lastSubCat = ddlSubCalss.items[sel]
loadGallery type:tb.SelectedIndex
)
)
--on btnCreMainCls pressed do (fun.createMainClass() )
--on btnDelMainCls pressed do (fun.deleteMainClass() )
--on btnCreSubCls pressed do (fun.createSubClass () )
--on btnDelSubCls pressed do (fun.deleteSubClass () )
on btnAddModel pressed do (addToGallery())
on btnMergeModel pressed do (mergeModels ())
--on btnRenModel pressed do (fun.renameModel () )
--on btnDelModel pressed do (fun.deleteModel () )
--on btnHlp pressed do (ShellLaunch helpFile "")
--<Actions
)-- end rollout
createDialog mc3DgalleryDialog style:#(#style_titlebar,
#style_sysmenu, #style_minimizebox, #style_maximizebox, #style_sunkenedge, #style_resizing)
/*
[628,420] - [544,324]
[628,420] - [560,340]
setINISetting useIniFile lastSubCat name_from_box (#(sysInfo.username,localTime) as string) --save thumb info to ini
/*
Many Thanks To:
LoneRobot
MarcoBrunetta
Mike Biddlecombe
/**/
I'm searching this all day and cant find the solution....:banghead:
MarcoBrunetta
08-14-2009, 03:32 PM
I get a few missing variables when I try to run the code, any chance you could clean it up a bit so I can try it? (I'm lazy, I know =P)
MerlinEl
08-14-2009, 04:13 PM
hehe is ok , I will try to remove some parts of code
here is it :
------------------
------------------
-- --
-- 3D Gallery --
-- --
------------------
------------------
Global mc3DgalleryDialog
Global mc2TextBoxDialog
----
if mc3DgalleryDialog != undefined do destroyDialog mc3DgalleryDialog
----
rollout mc3DgalleryDialog " 3DGallery II: Models" width:624 height:444
(
--> Local
local Root_Dir="", Current_Dir = "", lastMainCat="", lastSubCat=""
local Img_Logo = "C:\\WINDOWS\\Coffee Bean.bmp"--(mc2Path()+"Img\\3DGall_About_01.bmp")
local colorclass = dotnetclass "system.drawing.color"
local cursor_harrow = dotNetObject "System.Windows.Forms.Cursor" "C:\WINDOWS\Cursors\harrow.cur" --temp cursor
local cursor_hmove = dotNetObject "System.Windows.Forms.Cursor" "C:\WINDOWS\Cursors\hmove.cur" --temp cursor
local singleborder = (dotNetClass "System.Windows.Forms.BorderStyle").fixedsingle
local dnfontlarge = dotNetObject "System.Drawing.Font" "Verdana" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnMXSlarge = dotNetObject "System.Drawing.Font" "System" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnfont = dotNetObject "System.Drawing.Font" "Verdana" 6.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local thumb_size = [160, 120]
local selected_items = #(), cat_offset, grp_offset, prg_offset
--< Local
-->Interface
GroupBox grp_cat "" pos:[64,76] width:556 height:348
Timer tmr_resize "Timer" pos:[4,4] width:24 height:24 enabled:true interval:100 active:false
--progressBar progbar "ProgressBar" pos:[64,428] width:555 height:12
dotNetControl progbar "Windows.Forms.Progressbar" pos:[64,428] width:555 height:12
--
bitmap bmpBg1 "Bitmap" pos:[72,20] width:268 height:28 bitmap:(BitMap 1 1 color:(color 244 220 50))
bitmap bmpBg2 "Bitmap" pos:[348,20] width:268 height:28 bitmap:(BitMap 1 1 color:(color 50 200 240))
dropdownList ddlMainClass "" pos:[76,24] width:260 height:21
dropdownList ddlSubClass "" pos:[352,24] width:260 height:21
--
button btnCreMainCls "" pos:[8,24] width:24 height:24 --images:(mc2Call.getIcon 161) toolTip:"Create Main Class"
button btnDelMainCls "" pos:[32,24] width:24 height:24 --images:(mc2Call.getIcon 150) toolTip:"Delete Main Class"
button btnCreSubCls "" pos:[8,48] width:24 height:24 --images:(mc2Call.getIcon 142) toolTip:"Create Sub Class"
button btnDelSubCls "" pos:[32,48] width:24 height:24 --images:(mc2Call.getIcon 141) toolTip:"Delete Sub Class"
button btnAddModel "" pos:[32,104] width:24 height:24 --images:(mc2Call.getIcon 149) toolTip:"Add selection to Library (press <Ctrl> for quick preview)"
button btnMergeModel "" pos:[8,104] width:24 height:24 --images:(mc2Call.getIcon 147) toolTip:"Add selection to Scene (press <Ctrl> to disable automatic rename)"
button btnRenModel "" pos:[8,128] width:24 height:24 --images:(mc2Call.getIcon 144) toolTip:"Rename Model"
button btnDelModel "" pos:[32,128] width:24 height:24 --images:(mc2Call.getIcon 148) toolTip:"Delete Model"
checkbutton ckb_plant "" pos:[8,208] width:24 height:24 --images:(mc2Call.getIcon 145) toolTip:"Planting"
checkbutton ckbPSurf "" pos:[8,184] width:24 height:24 --images:(mc2Call.getIcon 146) toolTip:"Pick a surface for planting"
checkbutton ckb_cfg "" pos:[8,264] width:24 height:24 --images:(mc2Call.getIcon 143) toolTip:"3DGallery..."
checkbutton ckb_multi_plant "" pos:[32,208] width:24 height:24 --images:(mc2Call.getIcon 163) toolTip:"Multiplanting"
checkbutton ckb_plant_dialog "" pos:[32,184] width:24 height:24 --images:(mc2Call.getIcon 164) toolTip:"Plant Customize..."
button btnHlp "" pos:[32,264] width:24 height:24 --images:(mc2Call.getIcon 162) toolTip:"Help..."
--
--
label lbl4 "Main class:" pos:[72,4] width:180 height:16
label lbl5 "Sub class:" pos:[348,4] width:180 height:16
--
dotNetControl flp_cat "flowlayoutpanel" pos:[66,86] width:548 height:332
dotNetControl tb "System.Windows.Forms.Tabcontrol" pos:[72,56] width:160 height:20
dotNetControl edt_search "textbox" pos:[348,56] width:267 height:20
GroupBox grp8 "Catalog:" pos:[4,4] width:56 height:76
GroupBox grp11 "Models:" pos:[4,84] width:56 height:76
GroupBox grp12 "Paint:" pos:[4,164] width:56 height:76
GroupBox grp13 "SetUp:" pos:[4,244] width:56 height:52
button btn_search "Search" pos:[296,56] width:48 height:20
button btn_rename "Rename" pos:[244,56] width:48 height:20
--<Interface
-->functions
fn getLastDirFrom path =
(
local arr = ( filterString path "\\" )
return arr[arr.count]
)
fn resizeBitmapNET srcBitmap width height useHighQuality:false=
(
local destBitmap = (dotNetObject "System.Drawing.Bitmap" width height) --Create new bitmap object
destBitmap.SetResolution srcBitmap.HorizontalResolution srcBitmap.VerticalResolution
local theGraphics = (dotNetClass "System.Drawing.Graphics").fromImage destBitmap --Create new Graphics object
local destRec = (dotnetObject "System.Drawing.rectangle" 0 0 width height) --Set destination image size
IF useHighQuality DO theGraphics.InterpolationMode = theGraphics.InterpolationMode.HighQualityBicubic
theGraphics.drawImage srcBitmap destRec --Resize the image
theGraphics.dispose() --gc
return destBitmap
)
fn resizeInterface size =
(
--local h = cat_size.x + (size.x - cat_size.x)
--local v = cat_size.y + (size.y - cat_size.y)
flp_cat.width += size.x - flp_cat.width - cat_offset.x
flp_cat.height += size.y - flp_cat.height - cat_offset.y
grp_cat.width += size.x - grp_cat.width - grp_offset.x
grp_cat.height += size.y - grp_cat.height - grp_offset.y
progbar.width += size.x - progbar.width - grp_offset.x
progbar.pos.y += size.y - progbar.pos.y - prg_offset.y
)
fn textBox =
(
rollout mc2TextBoxDialog " Command Box v0.1" width:444 height:40
(
-->locals
local dir = ""
--<locals
edittext edtBox "New Name:" pos:[12,12] width:312 height:16 bold:true
button btnAcpt "Accept" pos:[332,12] width:48 height:16
button btnCncl "Cancel" pos:[384,12] width:48 height:16
groupBox grpTx "" pos:[4,0] width:436 height:36
fn correctSymbolCheck text =
(
if text.count == 0 do return false
local badSymbols = "\/*?"
for t=1 to text.count do
(
for s=1 to badSymbols.count do
(
if text[t] == badSymbols[s] do
(
messagebox "Incorrect Name.\nSymbols \ / ?* are not allowed." title:"3DGallery!"
return false
)
)
)
return true
)
on mc2TextBoxDialog open do (setFocus edtBox)
on mc2TextBoxDialog rbuttonup pos do(edtBox.text = "" ;destroyDialog mc2TextBoxDialog)
on btnAcpt pressed do
(
local theName = edtBox.text
if correctSymbolCheck theName then
(
local existingNames = (for i in (getFiles (dir+"*.*")) collect (getFilenameFile i)) --check for duplicate names
if (findItem existingNames theName) == 0 --check for duplicate names
then (DestroyDialog mc2TextBoxDialog)
else (messagebox ("The name:<"+edtBox.text+"> is allready exist.") title:" 3D Gallery:" ; setFocus edtBox)
)
else (setFocus edtBox)
)
on btnCncl pressed do (edtBox.text = "" ; DestroyDialog mc2TextBoxDialog)
)
--center to main dialog
local dPos = getDialogPos mc3DgalleryDialog
local dSize = getDialogSize mc3DgalleryDialog
local inPos =[dPos.x + (dSize.x/2) - 222, dPos.y + (dSize.y/2)]
CreateDialog mc2TextBoxDialog pos:inPos style:#(#style_border) modal:true
return mc2TextBoxDialog.edtBox.text
)
fn renderModel img_path =
(
--get ini setting for render
local anti = execute(getIniSetting mc2UserINI "3DGallery" "AntiAliasing" )
local samp = execute(getIniSetting mc2UserINI "3DGallery" "PixelSampler" )
local shad = execute(getIniSetting mc2UserINI "3DGallery" "Shadows" )
local quei = execute(getIniSetting mc2UserINI "3DGallery" "Quiet" )
--Render to vbf
local oldBgColor = backgroundColor
backgroundColor = execute (getIniSetting mc2UserINI "3DGallery" "Thumb_Color")
local imgSize = execute (getIniSetting mc2UserINI "3DGallery" "Thumb_Render_Size")
local img = bitmap imgSize.x imgSize.y color:backgroundColor
--render phase
render outputsize:imgSize antiAliasing:anti enablePixelSampler:samp shadows:shad \
quiet:quei renderType:#selection to:img vfb:off -- outputFile:(img_path+".jpg")
--if path is undefined make render with prewiew
img.filename = img_path
save img quiet:on
backgroundColor = oldBgColor -- return old bg color
return img
)
fn mergeModels =
(
if selected_items.count == 0 do return false
progbar.foreColor = colorclass.LightSteelBlue
for i=1 to selected_items.count do
(
local f = Current_Dir+selected_items[i]+".max"
if doesFileExist f do
(
try (mergeMAXFile f #useSceneMtlDups #mergeDups #select )
catch (messagebox ( "Merging model:<" + selected_items[i] + "> is failed.\nFile is mising or is corupted." ) title: " Warning!")
--prevent dupplicate names in scene
if not keyboard.controlPressed then (for o in selection do o.name = uniqueName (o.name))
)
progbar.value = 100.*i/selected_items.count
)
progbar.value = 0
--setfocus mc3DgalleryDialog.flp_cat
)
fn onMouseDown ctrl evnt =
(
--format "MouseDown: % [%]\n" ctrl (evnt.button.tostring())
local RButton = (evnt.button == (dotNetClass "System.Windows.Forms.MouseButtons").Right)
local itmName = ctrl.text
if RButton then --"Show RC Menu"
(
rcMenu thumbMenu
(
menuItem new_1 "Add To Scene..."
separator file_menu_1
menuItem new_2 "Rename ..."
menuItem new_3 "Delete..."
on new_1 picked do mergeModels()
on new_2 picked do format " Rename... %\n" selected_items
on new_3 picked do deleteFromGallery()
)
PopupMenu thumbMenu
)
--if System.Windows.Forms.Control.MouseButtons == System.Windows.Forms.MouseButtons.Left
else if ctrl.forecolor == colorclass.red
then
(
deleteItem selected_items (findItem selected_items itmName)
ctrl.forecolor = colorclass.yellow
)
else
(
append selected_items itmName
ctrl.forecolor = colorclass.red
edt_search.text = ctrl.text
)
ctrl.Cursor = cursor_hmove
)
fn onMouseUp ctrl evnt =
(
ctrl.Cursor = cursor_harrow
-- format "MouseUp: % [%]\n" ctrl (evnt.button.tostring())
)
fn onMouseEnter ctrl evnt =
(
--format "MouseEnter % [%]\n" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.yellow
ctrl.Cursor = cursor_harrow
)
fn onMouseLeave ctrl evnt = --drag and drop
(
--format "MouseLeave % [%]\n" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.LightSteelBlue
--edt_search.text = "MouseLeave: " + ctrl.text
)
fn onMouseMove ctrl evnt =
(
--format "Move!\n\tSender : %\n\tMouse Pos : %\n" ctrl.Text [evnt.X, evnt.Y]
)
fn getRootDir =
(
--if mc2UserINI == undefined or not doesFileExist mc2UserINI do return false
local Root_Dir = ""
if doesFileExist Root_Dir do return Root_Dir
if mc2GallerySetupDialog != undefined do destroyDialog mc2GallerySetupDialog
rollout mc2GallerySetupDialog " Inicialize 3DGallery Database:" width:332 height:148
(
local Root_Dir = ""
GroupBox grpDir "Please put you 3DGallery directory..." pos:[8,4] width:316 height:136
button btnSetDir "Set Dir" pos:[16,108] width:164 height:24
bitmap bmpPop1 "Bitmap" pos:[16,24] width:300 height:80 fileName:Img_Logo
button BtnCancel "Cancel" pos:[252,108] width:64 height:24
on btnCancel pressed do (destroyDialog mc2GallerySetupDialog)
on btnSetDir pressed do
(
local p = (getSavePath caption:"Chose Catalog Directory.")
if p != undefined do
(
Root_Dir = p+"\\"
destroyDialog mc2GallerySetupDialog
)
)
)
createDialog mc2GallerySetupDialog style:#(#style_toolwindow) modal:true
return mc2GallerySetupDialog.Root_Dir
)
fn addImageToButton img_path =
(
local img_btn = dotnetobject "button"
img_btn.size = dotnetobject "system.drawing.size" thumb_size.x thumb_size.y --160 120
--img_btn.backcolor = colorclass.yellow --cadetblue -- tag color
img_btn.forecolor = colorclass.LightSteelBlue --text color
img_btn.margin = dotnetobject "system.windows.forms.padding" 2 -- thumbs distance
img_btn.flatstyle = (dotNetclass "System.Windows.Forms.FlatStyle").flat
img_btn.font= dnfont
img_btn.text = getFilenameFile img_path
img_btn.name = img_btn.text
img_btn.textalign = (dotnetclass "System.Drawing.ContentAlignment").BottomCenter
local img_path = dotNetObject "System.Drawing.Bitmap" img_path
local img_copy = resizeBitmapNET img_path thumb_size.x thumb_size.y
img_path.Dispose()
img_btn.Image = img_copy
img_btn.AllowDrop = true
--img_btn.showTooltip -- WIP
-- Setup an event handlers for both buttons
dotnet.addEventHandler img_btn "MouseDown" onMouseDown
dotnet.addEventHandler img_btn "MouseUp" onMouseUp
dotnet.addEventHandler img_btn "MouseEnter" onMouseEnter
dotnet.addEventHandler img_btn "MouseLeave" onMouseLeave
dotnet.addEventHandler img_btn "MouseMove" onMouseMove
--mc2system.show img_path
--gc()
return img_btn
)
fn loadGallery type:1 = --type = tab controll state
(
selected_items = #()
flp_cat.controls.clear()
Current_Dir = Root_Dir + lastMainCat + "\\" + lastSubCat + "\\"
--format "Current_Dir:%\n" Current_Dir
if not doesFileExist Current_Dir do return false
local Images_Array = getFiles (Current_Dir + "*.jpg")
--change cursor to wait
local cursors = dotNetClass "System.Windows.Forms.Cursors"
local cursor = dotNetClass "System.Windows.Forms.Cursor"
cursor.current = cursors.WaitCursor
case type of -- WIP
(
0:(print "Loading... Models")
1:(print "Loading... Materials" )
2:(print "Loading... Textures")
)
progbar.foreColor = colorclass.LightSteelBlue
local dnobjarray = #()
for i=1 to Images_Array.count do
(
flp_cat.controls.add (addImageToButton Images_Array[i])
--append dnobjarray (addImageToButton Images_Array[i])
progbar.value = 100.*i/Images_Array.count
)
--flp_cat.controls.addrange dnobjarray
cursor.current = cursors.Arrow
progbar.value = 0
)
fn addTogallery =
(
if selection.count == 0 do (messageBox "Select some object to add." title:"3DGallery!" ;return false)
if lastSubCat == undefined do (messageBox "Create <Sub clas> catalog." title:"3DGallery!" ;return false)
local name_from_box = textBox()
if name_from_box == "" do return false
--render selection
local img_path = Current_Dir+name_from_box+".jpg"
local max_path = Current_Dir+name_from_box+".max"
local useIniFile = (Root_Dir+"User_"+lastMainCat+".ini")
renderModel img_path
--save selection
saveNodes selection max_path
--security lock and user data
if not doesFileExist useIniFile do
(
local f = createFile useIniFile
close f
)
--reload , resort gallery
loadGallery type:tb.SelectedIndex
--mc2system.show flp_cat
--create a button and load thummbnail
--flp_cat.controls.add (addImageToButton img_path)
--flp_cat.Refresh().flp_cat.update().SuspendLayout().ResetBindings().ResetImeMode().Invalidate()
)
fn loadMainCat = --remember main dir where you browse last time
(
--collect folders for main cat
local mainDirs = sort(getDirectories (Root_Dir+"*.*"))
if mainDirs.count == 0 do return false
ddlMainClass.items = for i in mainDirs collect (getLastDirFrom i)--get the last dir from path
--last main cat
ddlMainClass.selection = 1
lastMainCat = ddlMainClass.items[1]
return true
)
fn loadSubCat = --remember sub dir where you browse last time
(
--collect folders for sub cat
local subDirs = sort( getDirectories (Root_Dir + lastMainCat + "\\*.*") )
if subDirs.count == 0 do return false
ddlSubClass.items = for i in subDirs collect (getLastDirFrom i)--get the last dir from path
--last sub cat
ddlSubClass.selection = 1
lastSubCat = ddlSubClass.items[1]
loadGallery type:tb.SelectedIndex
return true
)
fn tabControll iobj lvl =
(
case lvl of
(
0:(iobj.title = " 3DGallery II: Models")
1:(iobj.title = " 3DGallery II: Materials")
2:(iobj.title = " 3DGallery II: Textures")
)
)
fn inicializeInterface =
(
-->check gallery root dir
Root_Dir = getRootDir()
if not doesFileExist Root_Dir do return false
--format "Root_Dir:%\n" Root_Dir
-->collect params for resizing interface
local cat_size = [flp_cat.width , flp_cat.height ]
local grp_size = [grp_cat.width , grp_cat.height ]
local dia_size = [mc3DgalleryDialog.width, mc3DgalleryDialog.height]
cat_offset = dia_size - cat_size
grp_offset = dia_size - grp_size
prg_offset = dia_size - progbar.pos
--<collect params for resizing interface
-->Tabs
local Tabs_Array = #("Models", "Materials", "Textures")
for i in Tabs_Array do
(
tb.TabPages.add i
)
--<Tabs
-->Progress Bar
--progbar.style = progbar.style.continuous
progbar.backColor = colorclass.fromARGB 40 45 66
--<Progress Bar
--flp_cat.MaximumSize
--flp_cat.MinimumSize
flp_cat.AutoSize = true
flp_cat.autoscroll = true
flp_cat.padding = dotnetobject "system.windows.forms.padding" 2
flp_cat.BackColor = colorclass.fromARGB 40 45 66
-->load dropDown lists Main & Sub
local sub_cat_found = if loadMainCat() then loadSubCat() else false
--mc2System.show flp_cat
return true
)
--<functions
-->Actions
on mc3DgalleryDialog open do (if not inicializeInterface() do destroyDialog mc3DgalleryDialog)
on tb Selected itm do (tabControll mc3DgalleryDialog itm.TabPageIndex )
on mc3DgalleryDialog resized size do (resizeInterface size)
on mc3DgalleryDialog lbuttondblclk pos do (loadGallery type:tb.SelectedIndex)
on ddlMainClass selected sel do
(
if sel != 0 do
(
lastMainCat = ddlMainClass.items[sel]
loadSubCat()
)
)
on ddlSubClass selected sel do
(
if sel != 0 do
(
lastSubCat = ddlSubClass.items[sel]
loadGallery type:tb.SelectedIndex
)
)
--<Actions
)-- end rollout
createDialog mc3DgalleryDialog style:#(#style_titlebar,
#style_sysmenu, #style_minimizebox, #style_maximizebox, #style_sunkenedge, #style_resizing)
/*
Many Thanks To:
LoneRobot
MarcoBrunetta
Mike Biddlecombe
/**/
I hope is ok now :D (http://forums.cgsociety.org/misc.php?do=getsmilies&wysiwyg=1&forumid=0#)
--set dir when dialog is open
--in the dir must be jpg images with same names as the maxFiles
test.jpg and test.max , test2.jpg and test2.max ......
--after right click on thumbnail and chose Add models To scene
--you will see ...
MerlinEl
08-14-2009, 04:49 PM
I'm looked at the LoneRobot site http://lonerobot.com/ColorChart.html
and tried his script ..
The same problem is here
-After merging some object in to scene or reset max file
the buttons stops working.....
MarcoBrunetta
08-14-2009, 06:14 PM
The LoneRobot script seems to work fine here. What Max version are you on? Also I couldn't get your script yo display any buttons...
denisT
08-14-2009, 06:48 PM
I'm looked at the LoneRobot site http://lonerobot.com/ColorChart.html
and tried his script ..
The same problem is here
-After merging some object in to scene or reset max file
the buttons stops working.....
I confirm this BUG!!! All controls added to FlowLayoutPanel loose their event Handlers after any max operation which causes garbage collection (open file, new, merge, reset, etc.), and gc() itself. I've tested it in MAX 2009 and 2010... Same story.
FlowLayoutPanel keeps its own events, but all its controls loose own event handlers. It scared me a lot and I’ve tested other controls for same behavior. Label, Button, Splitter work fine...
MerlinEl
08-14-2009, 06:56 PM
I have 3DsMax 9
In my script you must do these steps to load images in to form
1) make a dir
2) create one subdir inside
3) put there some jpg images
4) run the script, dialog will be apear
5) press button browse and assing the first dir
6) images will be loaded in to buttons
now check the buttons if is highliting and rClick menu is apearing
merge some model in scene and check it again... image buttons will be dead
Wow, that is one nasty bug. Is there a way to check for them and add them back?
denisT
08-14-2009, 07:07 PM
Wow, that is one nasty bug. Is there a way to check for them and add them back?
IMHO it's the TERRIBLE BUG! It's possible to handle some general events and re-add event handlers to layout's controls... But there is no way to handle gc itself.
denisT
08-14-2009, 07:11 PM
now check the buttons if is highliting and rClick menu is apearing
merge some model in scene and check it again... image buttons will be dead
Actually the buttons are not dead. They are staying alive, but their event handlers are dead...
MerlinEl
08-14-2009, 07:37 PM
actualy Yes! they ar not dead ,but the result is nearly same.
This gallery is supposed to store and add meshes to scene.
To make work going "faster".
Now if I'm merge an object in to scene.
Then I must every time fil flowlayoutpanel with event Handlers(slow down)
And if will be there more than 100 obj in the Gallery...?
:cry::cry::cry:
Well get that bug reported over at ADSK's bug reporting page so that it gets corrected. Does this still happen if you are not using a rollout and use a dotNet dialog instead?
MerlinEl
08-14-2009, 09:12 PM
Well get that bug reported over at ADSK's bug reporting page so that it gets corrected. Does this still happen if you are not using a rollout and use a dotNet dialog instead?
Hi PEN
here is all made in DotNet form:
(
local jpg_images_dir = "E:\\3DGallery\\Objects\\Table" --set dir with JPG IMAGES
local colorclass = dotnetclass "system.drawing.color"
local colors = dotNetClass "System.Drawing.Color"
local dockStyle = dotNetClass "System.Windows.Forms.DockStyle"
local singleborder = (dotNetClass "System.Windows.Forms.BorderStyle").fixedsingle
local dnfont = dotNetObject "System.Drawing.Font" "Verdana" 6.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnfontlarge = dotNetObject "System.Drawing.Font" "Verdana" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local dnMXSlarge = dotNetObject "System.Drawing.Font" "System" 8.5 ((dotNetClass "System.Drawing.FontStyle").bold)
local leg = dotnetobject "label"
leg.text = "textbox"
leg.margin = dotnetobject "system.windows.forms.padding" 2
leg.size = dotnetobject "system.drawing.size" 543 531
fn Btn_Pressed sender eventargs =
(
local stringdata
leg.forecolor = sender.forecolor
leg.backcolor = if sender.text == "Transparent" then colorclass.white else sender.backcolor
--higlight thumbnails
if sender.backcolor == colorclass.yellow
then
(
stringdata = "pressed 1"--sender.tag
sender.backcolor = colorclass.cadetblue
)
else
(
stringdata = "pressed 2"--sender.text
sender.backcolor = colorclass.yellow --not working too
)
leg.text = stringdata
show eventargs
)
local flp = dotnetobject "flowlayoutpanel"
flp.width=543
flp.height=531
flp.padding = dotnetobject "system.windows.forms.padding" 2
local Images_Array = getFiles (jpg_images_dir + "\\*.jpg")
local dnobjarray = #()
for i in Images_Array do
(
local btndragdrop = dotnetobject "button"
btndragdrop.size = dotnetobject "system.drawing.size" 160 120
btndragdrop.forecolor = colorclass.ivory --text color
btndragdrop.margin = dotnetobject "system.windows.forms.padding" 2 -- thumbs distance
btndragdrop.flatstyle = (dotNetclass "System.Windows.Forms.FlatStyle").flat
btndragdrop.font= dnfont
btndragdrop.text = getFilenameFile i
btndragdrop.textalign = (dotnetclass "System.Drawing.ContentAlignment").BottomCenter
btndragdrop.Image = dotNetObject "System.Drawing.Bitmap" i
dotNet.addEventHandler btndragdrop "click" Btn_Pressed
append dnobjarray btndragdrop
)
flp.controls.addrange dnobjarray
local dotForm = (dotNetObject "System.Windows.Forms.Form")
dotForm.Controls.addrange #(flp,leg)
--dotForm.Controls.add leg
dotForm.Text = " Picture Box Test 1"
dotForm.topmost = true
dotForm.show()
)
The dotNetBug is won again...:shrug:
denisT
08-14-2009, 09:40 PM
I would NEVER let MAX kick my a$$!!!
I found how to fix this bug...
Doesn't work:
try(destroydialog dlg) catch()
rollout dlg ""
(
dotNetControl flp "flowlayoutpanel" height:60
fn whenButtonClick s e = (format "\"%\" clicked\n" s.text)
fn makeButtons = for k=1 to 2 collect
(
btn = dotnetobject "button"
btn.text = "Layout B" + (k as string)
dotNet.addEventHandler btn "click" whenButtonClick
btn
)
on dlg open do
(
local buttons = makeButtons()
flp.controls.addrange buttons
)
)
createdialog dlg
Works!!!
try(destroydialog dlg) catch()
rollout dlg ""
(
dotNetControl flp "flowlayoutpanel" height:60
local buttons = #()
fn whenButtonClick s e = (format "\"%\" clicked\n" s.text)
fn makeButtons = for k=1 to 2 collect
(
btn = dotnetobject "button"
btn.text = "Layout B" + (k as string)
dotNet.addEventHandler btn "click" whenButtonClick
btn
)
on dlg open do
(
buttons = makeButtons()
flp.controls.addrange buttons
)
)
createdialog dlg
Find one difference :)
denisT
08-14-2009, 09:57 PM
Actually this is not a bug at all. I understand now why it happens. (... and not with only Layout control).
Is it because the controls/eventhandlers are created and assigned in a global or local scope and then assigned to a dotnet control. The eventhandler stays in that scope but is not used and thus cleared whenever a gc occurs. So when the time comes to call the eventhandler it's gone.
Something like that?
-Johan
MerlinEl
08-17-2009, 09:48 AM
It seems no solution be found here… I will try to find some other way :D
but thanks guys anyway :wavey:
Zbuffer
08-17-2009, 12:54 PM
Maybe a bit late, but i saw you got the showproperties a tad wrong.
here is how to get the properties of various controls:
rollout tltest "XtraTreeList Test" width: 300 height: 200
(
dotNetControl tl "DevExpress.XtraTreeList.TreeList" width: 274 height: 180
fn ListProps ax p:true m:true e:true =
(
clearlistener()
format "%: %\n" ax (classof ax)
if p do try (format "PROPERTIES:\n"; showProperties ax) catch (format "No Properties for %\n" ax)
if m do try (format "METHODS:\n"; showMethods ax) catch (format "No Methods for %\n" ax)
if e do try (format "EVENTS:\n"; showEvents ax) catch (format "No Events for %\n" ax)
)
on tltest open do ListProps tl
)
createdialog tltest
now you get all the properties, methods and event hadlers.
MerlinEl
08-17-2009, 03:53 PM
Nice.. always is here something new to learn ....:beer:
Zbuffer , thanks!
denisT
08-17-2009, 04:18 PM
It seems no solution be found here… I will try to find some other way :D
but thanks guys anyway :wavey:
You didn't read carefully... There is the solution in my post http://forums.cgsociety.org/showpost.php?p=6046649&postcount=30
JHaywood
08-17-2009, 04:53 PM
You didn't read carefully... There is the solution in my post http://forums.cgsociety.org/showpost.php?p=6046649&postcount=30
This also works...
try(destroydialog dlg) catch()
rollout dlg ""
(
dotNetControl flp "flowlayoutpanel" height:60
fn whenButtonClick s e = (format "\"%\" clicked\n" s.text)
fn makeButtons = for k=1 to 2 collect
(
btn = dotnetobject "button"
btn.text = "Layout B" + (k as string)
dotNet.addEventHandler btn "click" whenButtonClick
dotNet.setLifetimeControl btn #dotnet
btn
)
on dlg open do
(
local buttons = makeButtons()
flp.controls.addrange buttons
)
)
createdialog dlg
And so you don't have to search for the difference, I'll just tell you. Look up dotNet.setLifetimeControl in the help doc. This was added in 2010 specifically to fix this problem. Setting the lifetime control to #dotnet mean that the even handlers don't get garbage collected by Max.
denisT
08-17-2009, 06:17 PM
This also works...
dotNet.setLifetimeControl
This was added in 2010 specifically to fix this problem. Setting the lifetime control to #dotnet mean that the even handlers don't get garbage collected by Max.
dotNet.setLifetimeControl :thumbsup:
martroyx
08-17-2009, 08:53 PM
dotNet.setLifetimeControl :thumbsup:
well ... the only reason I was happy that they added this thing was to free the tag property for the timer... but ,well, it doesn't work...
edit : Ho well , it does work now ...but I swear it wasn't the other day... I'll try to find back what I was doing ...:rolleyes:
MerlinEl
08-18-2009, 07:38 AM
wow!!! , thats it!
How I miss it ?(one local variable....)
Finaly I can continue on my project....:applause:
You have right denisT (NEVER let MAX kick my a$$!!! :-))))))
Many Thanks for This!
CGTalk Moderation
08-18-2009, 07:38 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.