Cool, I’ll see about reformatting my .net notes into something readable if I get some time.
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:%
" itm
print "---------------------------------------------------------------------------"
try ( format "show:%
" (show itm) ) catch (print "undefined")
try ( format "interface:%
" (showinterface itm) ) catch (print "undefined")
try ( format "methods:%
" (showmethods itm) ) catch (print "undefined")
try ( format "prop:%
" (showproperties itm) ) catch (print "undefined")
)
fn onMouseDown ctrl evnt =
(
format "MouseDown: % [%]
" 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: % [%]
" ctrl (evnt.button.tostring())
)
fn onMouseEnter ctrl evnt =
(
--format "MouseEnter % [%]
" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.yellow
legend.text = "MouseEnter"
)
fn onMouseLeave ctrl evnt =
(
--format "MouseLeave % [%]
" 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 cant 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
-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).
oho! 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:%
" itm
print "---------------------------------------------------------------------------"
try ( format "show:%
" (show itm) ) catch (print "undefined")
try ( format "interface:%
" (showinterface itm) ) catch (print "undefined")
try ( format "methods:%
" (showmethods itm) ) catch (print "undefined")
try ( format "prop:%
" (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: % [%]
" 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: % [%]
" ctrl (evnt.button.tostring())
)
fn onMouseEnter ctrl evnt =
(
--format "MouseEnter % [%]
" 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 % [%]
" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.ivory
--legend.text = "MouseLeave: " + ctrl.text
)
fn onMouseMove ctrl evnt =
(
--format "Move!
Sender : %
Mouse Pos : %
" 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:% h:% size:%
" 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
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.
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 [b][color=Cyan]"flowlayoutpanel"[/b][/color] with command
[b]mergeMAXFile maxFilePath
[/b]or[b]
[/b]simple[b] reseting[/b][color=#fffffe] max from his own menu [/color][b]file/reset
[/b]
Then buttons loaded in [b][color=Cyan]"flowlayoutpanel"[/b][/color] 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.
Symbols \ / ?* 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.
File 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: % [%]
" 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... %
" 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: % [%]
" ctrl (evnt.button.tostring())
)
fn onMouseEnter ctrl evnt =
(
--format "MouseEnter % [%]
" 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 % [%]
" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.LightSteelBlue
--edt_search.text = "MouseLeave: " + ctrl.text
)
fn onMouseMove ctrl evnt =
(
--format "Move!
Sender : %
Mouse Pos : %
" 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:%
" 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:%
" 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:
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)
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.
Symbols \ / ?* 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.
File 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: % [%]
" 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... %
" 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: % [%]
" ctrl (evnt.button.tostring())
)
fn onMouseEnter ctrl evnt =
(
--format "MouseEnter % [%]
" 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 % [%]
" ctrl evnt
if ctrl.forecolor != colorclass.red do ctrl.forecolor = colorclass.LightSteelBlue
--edt_search.text = "MouseLeave: " + ctrl.text
)
fn onMouseMove ctrl evnt =
(
--format "Move!
Sender : %
Mouse Pos : %
" 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:%
" 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:%
" 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
/**/
–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 …
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…
[color=red]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 [color=yellow]gc() itself. I’ve tested it in MAX 2009 and 2010… Same story. [/color]
FlowLayoutPanel keeps its own events, but all its controls loose own event handlers. It scared me a lot and Ive tested other controls for same behavior. Label, Button, Splitter work fine…
[/color]