Rev 1390 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tao.OpenGl;
using BauzoidNET.app;
using System.IO;
using SpriteEditor.file;
namespace SpriteEditor
{
public partial class MainForm
: Form
{
private static BauzoidApp mApp
= null;
private Document mDocument
= null;
private BauzoidNET
.graphics.sprite.SimpleSprite mSprite
= null;
private BauzoidNET
.graphics.texture.Framebuffer mOffscreen
= null;
private BauzoidNET
.graphics.model.SimpleGeometry mQuad
= null;
private BauzoidNET
.graphics.shader.ShaderProgram mShader
= null;
private BauzoidNET
.graphics.shader.ShaderUniform mTextureHandle
= null;
public MainForm
()
{
InitializeComponent
();
}
public static BauzoidApp getApp
()
{
return mApp
;
}
private void MainForm_Load
(object sender, EventArgs e
)
{
mApp
= new BauzoidApp
();
mApp
.init(mGlView
.Width, mGlView
.Height);
mQuad
= BauzoidNET
.graphics.model.GeometryUtil.createQuad(mApp
.getGraphics(), 0
.0f,
0, 100
.0f, 100
.0f
);
//mShader = ShaderUtil.createShaderFromFile(mApp.getGraphics(), Gdx.files.internal("data/shaders/offscreen.vert"),
//Gdx.files.internal("data/shaders/offscreen.frag"));*/
mShader
= BauzoidNET
.graphics.shader.ShaderUtil.createShaderFromFile(mApp
.getGraphics(),
"data/shaders/offscreen.vert",
"data/shaders/offscreen.frag");
if (mShader
!= null)
{
mTextureHandle
= mShader
.getUniform("uDiffuse");
}
mSprite
= new BauzoidNET
.graphics.sprite.SimpleSprite(mApp
.getGraphics(),
"data/textures/test.png");
mSprite
.init();
mSprite
.getSpriteTransform().x = 10;
mSprite
.getSpriteTransform().y = 10;
mSprite
.getSpriteTransform().w = 300;
mSprite
.getSpriteTransform().h = 300;
mSprite
.getSpriteTransform().pivotX = 0;
mSprite
.getSpriteTransform().pivotY = 0;
mOffscreen
= new BauzoidNET
.graphics.texture.Framebuffer(mApp
.getGraphics(),
128,
128,
false);
String s
= Path
.Combine(Application
.StartupPath,
@"..\\..\\..\\..\\..\\BauzoidApps\\BurutaruZ_v2\\burutaru-android\\assets\\data\\levels");
openFileDialog
.InitialDirectory = Path
.GetFullPath(s
);
saveFileDialog
.InitialDirectory = Path
.GetFullPath(s
);
mDocument
= new Document
();
}
private void MainForm_Shown
(object sender, EventArgs e
)
{
if (!PerformFileNew
())
Close
();
}
private void MainForm_FormClosing
(object sender, FormClosingEventArgs e
)
{
if (!CheckDocumentModifiedAndSave
())
{
e
.Cancel = true;
return;
}
if (mSprite
!= null)
{
mSprite
.dispose();
mSprite
= null;
}
if (mOffscreen
!= null)
{
mOffscreen
.dispose();
mOffscreen
= null;
}
if (mQuad
!= null)
{
mQuad
.dispose();
mQuad
= null;
}
if (mApp
!= null)
mApp
.exit();
mDocument
= null;
}
private void GlView_Paint
(object sender, PaintEventArgs e
)
{
mOffscreen
.activate();
mApp
.getGraphics().clear(1, 0
.5f, 0
.3f,
0);
mApp
.getRenderStates().projection.setOrtho(
0
.0f,
480,
480,
0
.0f,
0
.0f,
1
.0f
);
mSprite
.render();
mOffscreen
.deactivate();
mApp
.getGraphics().clear(0, 0
.5f, 0
.3f,
0);
//Gl.glViewport(0, 0, mGlView.Width, mGlView.Height);
mApp
.getRenderStates().projection.setOrtho(
0
.0f,
mApp
.getGraphics().getWidth(),
mApp
.getGraphics().getHeight(),
0
.0f,
0
.0f,
1
.0f
);
BauzoidNET
.graphics.renderstates.RenderStates rs
= mApp
.getGraphics().renderStates;
rs
.view.identity();
rs
.model.identity();
mShader
.activate();
{
mTextureHandle
.set(0);
rs
.getTextureStage(0).bindTexture(mOffscreen
.getColorTexture());
rs
.blending.setEnabled(false);
rs
.culling.setEnabled(false);
rs
.depthTest.setEnabled(false);
rs
.activate();
{
mQuad
.render();
}
rs
.deactivate();
rs
.popModelMatrix();
rs
.popViewMatrix();
}
mShader
.deactivate();
}
private void GlView_Resize
(object sender, EventArgs e
)
{
if (mApp
!= null)
mApp
.getGraphics().updateSurfaceDimensions(mGlView
.Width, mGlView
.Height);
}
private void FileNew_Click
(object sender, EventArgs e
)
{
if (!CheckDocumentModifiedAndSave
())
return;
PerformFileNew
();
}
private void FileOpen_Click
(object sender, EventArgs e
)
{
if (!CheckDocumentModifiedAndSave
())
return;
// open file
PerformFileOpen
();
}
/** Check if the document has been modified, and if yes, ask for saving.
* Returns true if everything is ok and the operation should be continued, or false when Cancel has been pressed. */
private bool CheckDocumentModifiedAndSave
()
{
if (mDocument
.IsDirty())
{
switch (MessageBox
.Show("File has been modified. Save?",
"New File", MessageBoxButtons
.YesNoCancel, MessageBoxIcon
.Question))
{
case DialogResult
.Yes:
if (!PerformFileSave
())
return false;
break;
case DialogResult
.No:
break;
case DialogResult
.Cancel:
return false;
}
}
return true;
}
/** Perform a file new operation.
* Returns false if the operation was aborted. */
private bool PerformFileNew
()
{
NewSpriteDialog dlg
= new NewSpriteDialog
();
if (dlg
.ShowDialog() == DialogResult
.Cancel)
return false;
// new file
mDocument
.NewDocument(dlg
.GetFilenames());
return true;
}
/** Perform a file save operation with a file save dialog.
* Returns false if the operation has been canceled. */
private bool PerformFileSave
(bool alwaysShowDialog
= false)
{
if (alwaysShowDialog
|| !mDocument
.IsFilenameSet())
{
if (saveFileDialog
.ShowDialog() == DialogResult
.Cancel)
return false;
mDocument
.SetFilename(saveFileDialog
.FileName);
}
return mDocument
.SaveDocument();
}
/** Perform a file open operation.
* Return false if the operation was canceled. */
private bool PerformFileOpen
()
{
if (openFileDialog
.ShowDialog() == DialogResult
.Cancel)
return false;
return mDocument
.LoadDocument(openFileDialog
.FileName);
}
private void FileSave_Click
(object sender, EventArgs e
)
{
PerformFileSave
();
}
private void FileSaveAs_Click
(object sender, EventArgs e
)
{
PerformFileSave
(true);
}
private void FileExit_Click
(object sender, EventArgs e
)
{
Close
();
}
}
}