3D Gallery DotNet controls Picture Box
------------------
------------------
-- --
-- 3D Gallery --
-- --
------------------
------------------
----20119.19 这个有好多的链接 这个现在运行是不通的。
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