实例介绍
【实例简介】net开发,实现三位效果
【实例截图】安装net环境即可运行
【核心代码】
// --------------------------------------------------------------------------
//| |
//| MagicBox |
//| Version 1.01 |
//| |
//| OpenGL project using the GDImage flat API to create texture and font |
//| on the fly. Polar coordinates smooth shading ambient light. |
//| |
//| The GDImage.dll unregistered version has no limitation, |
//| and all features of the API are fully functional. |
//| |
//| Buying a commercial license removes the copyright nag screen. |
//| |
// --------------------------------------------------------------------------
//| |
//| Author Patrice TERRIER |
//| copyright (c) 2006 |
//| |
//| pterrier@zapsolution.com |
//| |
//| www.zapsolution.com |
//| |
// --------------------------------------------------------------------------
//| Project started on : 11-06-2006 (MM-DD-YYYY) |
//| Last revised : 11-20-2006 (MM-DD-YYYY) |
// --------------------------------------------------------------------------
//using System.Diagnostics;
//////////////////////////
using System;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
//using System.Collections.Generic;
//using System.ComponentModel;
//using System.Data;
//using System.Drawing.Drawing2D;
//using System.Drawing.Imaging;
//using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using Win32;
using SkinEngine;
using GDImage;
using OpenGL;
namespace MagicBox
{
public delegate int CallBack(IntPtr hWnd, int wMsg, uint wParam, uint lParam);
public partial class MAIN_Form : Form
{
[DllImport("USER32", EntryPoint = "SetWindowLongA")]
public static extern int SetCallBack(IntPtr hWnd, int nIndex, CallBack lNewLong);
static CallBack UseCallBack = null;
const int TIMER_MAX = 2; // To perform smooth animation
const int ID_CTRL = 100; // GDImage Zoom control
static IntPtr hGLcontrol = IntPtr.Zero; // Default to Zero
static float grDistance, grSpinX, grSpinY, grYincr, grXincr;
static int GLwasX, GLwasY;
static bool bMousing;
static int ptLastMousePositX, ptLastMousePositY, ptCurrentMousePositX, ptCurrentMousePositY;
static GI.ZGLFONT UseFont = new GI.ZGLFONT();
static int ghGLproc; // OpenGL subclassing
static int gnxT, gnStW, gnStH, gnOne, gnMarqueeColor;
static string zText;
static int WasZoom = 0;
static bool Zooming = false;
static public IntPtr hFORM_Main = IntPtr.Zero; // Default to Zero
static public IntPtr hBACK_BtnSys = IntPtr.Zero; // Default to Zero
static public IntPtr hBackGround = IntPtr.Zero; // Default to Zero
public struct RECT { public int left, top, right, bottom;}
public MAIN_Form()
{
hFORM_Main = this.Handle;
// Setup Skin parameters
SetSkinParameters();
InitializeComponent();
// Create the GDImage/OpenGL control
hGLcontrol = GI.CreateGLcontrol(GL_Template, ID_CTRL);
}
private void SetSkinParameters()
{
// REM this out to disable the drop shadow effect.
//Api.UseDropShadow(hFORM_Main);
// Setup default Skin colors
SK.ColorLayerBackground = Color.FromArgb(192, 192, 202);
SK.ColorCaptionEnabled = Color.FromArgb(220, 220, 220);
SK.ColorCaptionDisabled = Color.FromArgb(164, 164, 192);
SK.TooltipBackColor = Color.FromArgb(192, 199, 209);
SK.TooltipForeColor = Color.FromArgb(8, 102, 128);
// Skin opacity in the range 0-255
SK.Alpha = 255;//204; // 80 % default transparency level
// Skin opacity of the hidden background in the range 0-254
SK.OpacityLayerBackground = 248;
//SK.IsResizable = false;
}
private void FORM_Load(object sender, EventArgs e)
{
// We need this to retrieve bitmap from resource
SK.UseNameSpace = this.GetType().Namespace;
// Use bitmap resources to setup public value for:
// FixCaptionLeft, FixCaptionHeight, FixCaptionRight, FixBottomHeight.
Bitmap bmp;
bmp = Properties.Resources.TopLeft;
SK.FixCaptionLeft = bmp.Width; SK.FixCaptionHeight = bmp.Height;
bmp = Properties.Resources.BottomRight;
SK.FixCaptionRight = bmp.Width; SK.FixBottomHeight = bmp.Height;
SK.DockMin = SK.FixCaptionHeight SK.FixBottomHeight; // Docking
// Setup the minimum size of the form
int UseMinWidth = Math.Max(this.MinimumSize.Width, SK.FixCaptionHeight SK.FixBottomHeight);
int UseMinHeight = Math.Max(this.MinimumSize.Height, SK.FixCaptionHeight SK.FixBottomHeight);
SK.UnDockingHeight = UseMinHeight; // Save the UnDockingHeight
this.MinimumSize = new System.Drawing.Size(UseMinWidth, UseMinHeight);
this.BackgroundImage = (Bitmap)SK.DrawBackGround(this.Width, this.Height);
Bitmap bmpFrmBack = (Bitmap)this.BackgroundImage;
SK.CreateFormRegion(this, bmpFrmBack);
//RECT rw = new RECT();
Api.RECT rw = new Api.RECT();
Api.GetWindowRect(hFORM_Main, ref rw);
SK.LastRgnWidth = rw.right - rw.left; SK.LastRgnHeight = rw.bottom - rw.top;
// Status text color
STATUS_Label.ForeColor = SK.ColorCaptionEnabled;
// Caption text color
if (this.Enabled)
{ CAPTION_Label.ForeColor = SK.ColorCaptionEnabled; }
else
{ CAPTION_Label.ForeColor = SK.ColorCaptionDisabled; }
CAPTION_Label.TextAlign = ContentAlignment.MiddleLeft;
CAPTION_Label.Text = this.Text;
// FORM_Tooltip colors
FORM_Tooltip.BackColor = SK.TooltipBackColor;
FORM_Tooltip.ForeColor = SK.TooltipForeColor;
//// Check first if we can use layered window.
//byte Alpha = 0;
//if ((Api.GetOsVersion() > 499) && (SK.Alpha < 255))
//{
// Alpha = 254; this.Opacity = (double)Alpha / 255;
//}
//else
//{
// Alpha = 255; this.Opacity = (double)Alpha / 255;
//}
//// Support for layered window is a prerequisite to create aero glass effect
//if (Alpha < 255)
//{
// Api.SetLayeredWindowAttributes(hFORM_Main, 0, SK.Alpha, 0x00000002);
// //Create the skin background
// Form BackGround = new Form();
// BackGround.ShowInTaskbar = false; // WS_EX_TOOLWINDOW
// BackGround.Visible = true;
// BackGround.FormBorderStyle = 0;
// BackGround.BackColor = SK.ColorLayerBackground;
// BackGround.Opacity = 0.999; // Don't change this !
// hBackGround = BackGround.Handle;
// Api.SetLayeredWindowAttributes(hBackGround, 0, SK.OpacityLayerBackground, 0x00000002);
// ResizeMoveHiddenWindows();
//}
if (hGLcontrol != IntPtr.Zero)
{
UseCallBack = new CallBack(glWndProc);
ghGLproc = SetCallBack(hGLcontrol, Api.GWL_WNDPROC, UseCallBack);
string sFileName = Api.ExePath() "cogs2.jpg";
if (GI.SetGLTextureFromFile(sFileName) == 0)
{
STATUS_Label.Text = sFileName;
glInitialize();
StartAnimation();
}
}
}
private void FORM_Close(object sender, EventArgs e)
{
this.Dispose();
}
private void ResizeMoveHiddenWindows()
{
if (Api.IsWindow(hBackGround))
{
if (SK.Alpha >= 254)
{
Api.RECT r = new Api.RECT();
Api.GetWindowRect(hFORM_Main, ref r);
Api.MoveWindow(hBackGround, -9990, -9990, r.right - r.left, r.bottom - r.top, false);
return;
}
if (SK.IsMaximized) return;
//Create hidden region
IntPtr hRgn = Api.CreateRectRgn(0, 0, 0, 0);
if (hRgn != IntPtr.Zero)
{
if (Api.GetWindowRgn(hFORM_Main, hRgn))
{
IntPtr hRgnTemp = Api.CreateRectRgn(0, 0, CLIENT_Panel.Width, CLIENT_Panel.Height);
Api.OffsetRgn(hRgnTemp, CLIENT_Panel.Location.X, CLIENT_Panel.Location.Y);
Api.CombineRgn(hRgn, hRgn, hRgnTemp, Api.RGN_AND);
Api.DeleteObject(hRgnTemp);
hRgnTemp = Api.CreateRectRgn(0, 0, BTN_Iconize.Width BTN_Maximize.Width BTN_Close.Width, BTN_Iconize.Height);
Api.OffsetRgn(hRgnTemp, BTN_Iconize.Location.X, 0);
Api.CombineRgn(hRgn, hRgn, hRgnTemp, Api.RGN_OR);
Api.DeleteObject(hRgnTemp);
if (Api.IsWindow(BTN_DockIn.Handle))
{
hRgnTemp = Api.CreateRectRgn(0, 0, BTN_DockIn.Width - 3, BTN_DockIn.Height - 2);
Api.OffsetRgn(hRgnTemp, BTN_DockIn.Location.X 1, 0);
Api.CombineRgn(hRgn, hRgn, hRgnTemp, Api.RGN_OR);
Api.DeleteObject(hRgnTemp);
}
if (Api.IsWindow(BTN_About.Handle))
{
hRgnTemp = Api.CreateRectRgn(0, 0, 0, 0);
if (Api.GetWindowRgn(BTN_About.Handle, hRgnTemp))
{
Api.OffsetRgn(hRgnTemp, BTN_About.Location.X, BTN_About.Location.Y);
Api.CombineRgn(hRgn, hRgn, hRgnTemp, Api.RGN_OR);
}
Api.DeleteObject(hRgnTemp);
}
// Set the new region to the form.
Api.SetWindowRgn(hBackGround, hRgn, false);
}
}
Api.RECT rw = new Api.RECT();
uint swpStyle = Api.SWP_NOSIZE | Api.SWP_NOMOVE | Api.SWP_NOSENDCHANGING | Api.SWP_NOOWNERZORDER | Api.SWP_NOACTIVATE;
Api.GetWindowRect(hFORM_Main, ref rw);
// Must use MoveWindow to restore location after Iconize/Restore in case of layered window.
Api.MoveWindow(hBackGround, rw.left, rw.top, rw.right - rw.left, rw.bottom - rw.top, false);
Api.SetWindowPos(hBackGround, Api.GetWindow(hFORM_Main, 2), 0, 0, 0, 0, swpStyle);
}
}
private void FORM_Move(object sender, EventArgs e)
{
ResizeMoveHiddenWindows();
}
private void FOCUS_Activated(object sender, EventArgs e)
{
if (Api.IsWindow(hBackGround))
{
uint swpStyle = Api.SWP_NOSIZE | Api.SWP_NOMOVE | Api.SWP_NOSENDCHANGING | Api.SWP_NOOWNERZORDER | Api.SWP_NOACTIVATE | Api.SWP_NOREDRAW;
Api.SetWindowPos(hBackGround, IntPtr.Zero, 0, 0, 0, 0, swpStyle);
swpStyle = Api.SWP_NOSIZE | Api.SWP_NOMOVE | Api.SWP_NOSENDCHANGING;
Api.SetWindowPos(hFORM_Main, IntPtr.Zero, 0, 0, 0, 0, swpStyle);
}
if (LED_Off.Visible)
{
CAPTION_Label.ForeColor = SK.ColorCaptionEnabled;
LED_On.Visible = true;
LED_Off.Visible = false;
}
}
private void SwitchOff()
{
CAPTION_Label.Select();
CAPTION_Label.ForeColor = SK.ColorCaptionDisabled;
LED_On.Visible = false;
LED_Off.Visible = true;
}
private void FOCUS_Deactivate(object sender, EventArgs e)
{
SwitchOff();
}
private void UpdateZoom(int z)
{
GI.SetGLzoom(hGLcontrol, z);
GI.ResizeGLWindow(hGLcontrol);
RenderOpenGL(hGLcontrol);
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case Api.WM_SIZE:
//Flicker free section
Api.LockWindowUpdate(m.HWnd);
StopAnimation();
Api.ShowWindow(CLIENT_Panel.Handle, Api.SW_HIDE);
Api.ShowWindow(Skin_STATUS_Dark.Handle, Api.SW_HIDE);
SK.BuildRegion(m.HWnd);
ResizeMoveHiddenWindows();
// Use the template to resize the GDImage OpenGL control
ResizeGLcontrol();
//Flicker free section
Api.ShowWindow(Skin_STATUS_Dark.Handle, Api.SW_SHOW);
Api.ShowWindow(CLIENT_Panel.Handle, Api.SW_SHOW);
Api.LockWindowUpdate(IntPtr.Zero);
StartAnimation();
GI.UpdateWindow(m.HWnd, false);
m.Result = (IntPtr)0;
return;
case Api.WM_NCLBUTTONDBLCLK:
// We handle this ourself to avoid havoc when using restore
// when using a form without caption.
if (SK.IsMaximized)
{
Api.ButtonClick(BTN_Restore.Handle);
}
else
{
Api.ButtonClick(BTN_Maximize.Handle);
}
m.Result = (IntPtr)0;
return;
case Api.WM_LBUTTONDBLCLK:
if (SK.IsMaximized)
{ // We simulate double click on caption to restore the window size
if (Api.HiWrd((uint)m.LParam) < SK.FixCaptionHeight) Api.ButtonClick(BTN_Restore.Handle);
}
break;
case Api.WM_ACTIVATEAPP: // Keep hidden background behind the form
if (Api.IsWindow(hBackGround))
{
if ((uint)m.WParam == 0)
{
uint swpStyle = Api.SWP_NOSIZE | Api.SWP_NOMOVE | Api.SWP_NOSENDCHANGING | Api.SWP_NOOWNERZORDER | Api.SWP_NOACTIVATE | Api.SWP_NOREDRAW;
Api.SetWindowPos(hBackGround, Api.GetWindow(hFORM_Main, 2), 0, 0, 0, 0, swpStyle);
}
}
break;
case Api.WM_COMMAND:
// Zooming part
if (m.LParam == ZOOM_Track.Handle)
{// So much easier than trying to raise an event
// Warning, we are using polar coordinates there
// thus convert it to Degree
if (Zooming == false)
{
Zooming = true;
double range = ZOOM_Track.Maximum - ZOOM_Track.Minimum;
double increment = range / 90.0f;
int ZoomIs = (int)Math.Max(range - (ZOOM_Track.Value * increment), 1);
if (WasZoom < ZoomIs)
{ for (int z = WasZoom; z < ZoomIs 1; z ) UpdateZoom(z); }
else if (WasZoom > ZoomIs)
{ for (int z = WasZoom; z > ZoomIs - 1; z--) UpdateZoom(z); }
WasZoom = ZoomIs;
Zooming = false;
}
}
break;
case Api.WM_TIMER:
if (m.WParam == (IntPtr)(TIMER_MAX 1))
{
glMarqueeProc();
}
else
{
RenderOpenGL(hGLcontrol);
}
m.Result = (IntPtr)0;
return;
case Api.WM_DESTROY:
DisposeGL(); // Free up OpenGL resources
break;
}
base.WndProc(ref m);
// This is the place where the skin NC area is handled.
if (m.Msg == Api.WM_NCHITTEST)
{
if (SK.IsMaximized) return;
if (m.Result == (IntPtr)Api.HTCLIENT)
{
int HITTEST = Api.HTCAPTION;
if (SK.IsResizable) // Check if the form is resizable
{
Point p = this.PointToClient(new Point(Api.LoWrd((uint)m.LParam), Api.HiWrd((uint)m.LParam)));
int xF = this.Width, yF = this.Height;
int xSide = 0;
int Border = System.Windows.Forms.SystemInformation.Border3DSize.Width;
if ((p.X >= xF - SK.FixBottomHeight) && ((p.Y >= yF - SK.FixBottomHeight)))
{
HITTEST = Api.HTBOTTOMRIGHT;
}
else
{
// Left side
if (p.X <= 8)
{
if (p.X <= Border) HITTEST = Api.HTLEFT;
xSide = 1;
}
// Right side
if (p.X >= xF - 8)
{
if (p.X >= xF - Border) HITTEST = Api.HTRIGHT;
xSide = 2;
}
// Top side
if (p.Y <= Border)
{
HITTEST = Api.HTTOP;
if (xSide == 1)
{
HITTEST = Api.HTTOPLEFT;
}
else if (xSide == 2)
{
HITTEST = Api.HTTOPRIGHT;
}
}
// Bottom side
if (p.Y >= yF - Border)
{
if (xSide == 1)
{
HITTEST = Api.HTBOTTOMLEFT;
}
else
{
HITTEST = Api.HTBOTTOM;
}
}
}
}
m.Result = (IntPtr)HITTEST;
}
}
}
private void BTN_Close_Click(object sender, EventArgs e)
{
Close();
}
private void BTN_Iconize_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private int WasX, WasY, WasWidth, WasHeight;
private void BTN_Restore_Click(object sender, EventArgs e)
{
CLIENT_Panel.Visible = false;
BTN_Maximize.Visible = true;
BTN_Restore.Visible = false;
bool RedrawMode = true;
if (SK.Alpha < 255)
{
Api.SetLayeredWindowAttributes(hFORM_Main, 0, SK.Alpha, 0x00000002);
RedrawMode = false;
if (Api.IsWindow(hBackGround)) Api.MoveWindow(hBackGround, WasX, WasY, WasWidth, WasHeight, false);
}
Api.MoveWindow(hFORM_Main, WasX, WasY, WasWidth, WasHeight, RedrawMode);
if (SK.IsDocked)
{
BTN_DockOut.Visible = true;
CLIENT_Panel.Visible = false;
}
else
{
BTN_DockIn.Visible = true;
CLIENT_Panel.Visible = true;
}
SK.IsMaximized = false;
}
private void BTN_Maximize_Click(object sender, EventArgs e)
{
WasX = this.Location.X;
WasY = this.Location.Y;
WasWidth = this.Width;
WasHeight = this.Height;
SK.IsMaximized = true;
CLIENT_Panel.Visible = false;
bool RedrawMode = true;
if (SK.Alpha < 255)
{
RedrawMode = false;
// Turn it to opaque mode
Api.SetLayeredWindowAttributes(hFORM_Main, 0, 255, 0x00000002);
if (Api.IsWindow(hBackGround)) Api.MoveWindow(hBackGround, -9990, -9990, WasWidth, WasHeight, false);
}
Api.MoveWindow(hFORM_Main, 0, 0, SystemInformation.WorkingArea.Width, SystemInformation.WorkingArea.Height, RedrawMode);
BTN_DockIn.Visible = false;
BTN_DockOut.Visible = false;
BTN_Restore.Visible = true;
BTN_Maximize.Visible = false;
if (CLIENT_Panel.Visible == false) CLIENT_Panel.Visible = true;
}
private void BTN_DockOut_Click(object sender, EventArgs e)
{
// Restore the minimum size of the form
this.MinimumSize = new System.Drawing.Size(this.MinimumSize.Width, SK.UnDockingHeight);
BTN_DockIn.Visible = true;
BTN_DockOut.Visible = false;
// Restore original window size
this.Height = SK.DockHeightMax;
this.Size = new Size(this.Width, SK.DockHeight);
CLIENT_Panel.Visible = true;
SK.IsDocked = false;
}
private void BTN_DockIn_Click(object sender, EventArgs e)
{
// Unlock the default minimum size of the form
this.MinimumSize = new System.Drawing.Size(this.MinimumSize.Width, SK.FixCaptionHeight SK.FixBottomHeight);
BTN_DockOut.Visible = true;
BTN_DockIn.Visible = false;
// Save current height of the window
SK.DockHeight = this.Height;
SK.DockHeightMax = this.MaximumSize.Height;
this.Size = new Size(this.Width, SK.DockMin);
CLIENT_Panel.Visible = false;
SK.IsDocked = true;
}
private void BTN_About_Click(object sender, EventArgs e)
{
// Switch to off mode, and redraw the form before screen shot.
SwitchOff(); GI.UpdateWindow(hFORM_Main, true);
DDW_Control.SHOW(92); // byte Opacity in the range 0-255
string Message = "GDImage version #\nSkin design Patrice Terrier\n\nwww.zapsolution.com".Replace("#", GI.Version());
Form MsgBox = new MsgBox_About(this.Text, Message);
MsgBox.ShowDialog(this);
DDW_Control.HIDE();
}
private void BTN_Url_Click(object sender, EventArgs e)
{
string target = "www.zapsolution.com";
if (null != target) System.Diagnostics.Process.Start(target);
}
//-----------------------------------------------------------
// OpenGL section
//-----------------------------------------------------------
private void ResizeGLcontrol()
{
// Use the template to resize the GDImage OpenGL control
if (Api.IsWindow(GL_Template.Handle))
{
Api.MoveWindow(hGLcontrol, GL_Template.Location.X, GL_Template.Location.Y, GL_Template.Width, GL_Template.Height, true);
GI.ResizeGLWindow(hGLcontrol);
RenderOpenGL(hGLcontrol);
}
}
private void glInitialize()
{
GI.InitGLControl(Api.ARGB(255, 0, 0, 16));
glSetDefault();
float[] LightAmbient = { 0.05f, 0.05f, 0.05f, 1.0f };
float[] LightDiffuse = { 1.0f, 1.0f, 1.0f, 1.0f };
float[] LightPosition = { 20.0f, 0.0f, 30.0f, 1.0f };
GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, LightAmbient); // Setup The Ambient Light
GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, LightPosition); // Position The Light
GL.glEnable(GL.GL_LIGHT0); // Enable Light ZERO
GL.glEnable(GL.GL_LIGHTING); // Enable Lighting
GL.glEnable(GL.GL_COLOR_MATERIAL); // Enable Coloring Of Material
UseFont.fontName = "Time Roman"; // A True Type font
UseFont.fontHeight = 12; // Size of the font
UseFont.fontWeight = Api.FW_BOLD; // Font style
GI.BuildGLfont(GI.GetGLDC(hGLcontrol), ref UseFont);
ResizeGLcontrol();
}
private void glSetDefault()
{
grDistance = -4.0f;
grSpinX = 0.0f;
grSpinY = 0.0f;
grYincr = 0.0f;
grXincr = 0.0f;
WasZoom = 50;
}
private void StartAnimation()
{
// Use API WM_TIMER to avoid aggressive garbage collection
// to occur before Main ends.
for (int T = 0; T < TIMER_MAX; T )
{
Api.SetTimer(hFORM_Main, T 1, 0, null);
}
Api.SetTimer(hFORM_Main, TIMER_MAX 1, 1, null);
}
private void RenderOpenGL(IntPtr hContainer)
{
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
grSpinX = grXincr; if (Math.Abs(grSpinX) > 360) grSpinX = grXincr;
grSpinY = grYincr; if (Math.Abs(grSpinY) > 360) grSpinY = grYincr;
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glLoadIdentity();
GL.glTranslatef(0.0f, 0.0f, grDistance);
GL.glRotatef(-grSpinY, 1.0f, 0.0f, 0.0f);
GL.glRotatef(-grSpinX, 0.0f, 1.0f, 0.0f);
GL.glBegin(GL.GL_QUADS);
// Front Face
GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture And Quad
GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture And Quad
GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(1.0f, 1.0f, 1.0f); // Top Right Of The Texture And Quad
GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture And Quad
GL.glEnd();
if (gnStW == 0)
{
zText = this.Text " does OpenGL";
GI.GetGLTextExtent(hContainer, ref UseFont, zText, ref gnStW, ref gnStH);
gnMarqueeColor = Api.ARGB(255, 64, 64, 92);
gnOne = -1;
gnxT = -gnStW;
}
int nyT = GL_Template.Height - gnStH - 10;
GI.DrawGLText(hContainer, ref UseFont, gnxT, nyT, zText, gnMarqueeColor);
// ***********************
// Draw the scene
// ***********************
GI.UpdateGLWindow(hContainer);
// ***********************
}
private void StopAnimation()
{
for (int T = 0; T < TIMER_MAX; T )
{
Api.KillTimer(hFORM_Main, T 1);
}
Api.KillTimer(hFORM_Main, TIMER_MAX 1);
}
// Free up resources
private void DisposeGL()
{
StopAnimation();
// Delete OpenGL font.
GI.DeleteGLFont(ref UseFont);
// Remove subclassing
if (ghGLproc != 0) Api.SetWindowLong(hGLcontrol, Api.GWL_WNDPROC, ghGLproc);
}
private void BTN_SelectFile_Click(object sender, EventArgs e)
{
//GI.LoadSavePath(Api.ExePath(), true);
string sFileName = GI.LoadDialog(hFORM_Main);
if (sFileName != null)
{
GI.SetGLTextureFromFile(sFileName);
STATUS_Label.Text = sFileName;
}
}
private void BTN_Up_Click(object sender, EventArgs e)
{
grYincr = 0.1f;
}
private void BTN_Left_Click(object sender, EventArgs e)
{
grXincr = 0.1f;
}
private void BTN_Pause_Click(object sender, EventArgs e)
{
grYincr = 0.0f; grXincr = 0.0f;
}
private void BTN_Right_Click(object sender, EventArgs e)
{
grXincr -= 0.05f;
}
private void BTN_Down_Click(object sender, EventArgs e)
{
grYincr -= 0.1f;
}
private void BTN_Reset_Click(object sender, EventArgs e)
{
glSetDefault();
GI.SetGLzoom(hGLcontrol, 0); ZOOM_Track.Value = WasZoom;
GI.ResizeGLWindow(hGLcontrol);
RenderOpenGL(hGLcontrol);
}
private void BTN_Info_Click(object sender, EventArgs e)
{
grYincr = 0.1f;
}
public static int glWndProc(IntPtr hWnd, int wMsg, uint wParam, uint lParam)
{
int x, y;
switch (wMsg)
{
case Api.WM_LBUTTONDOWN:
if (bMousing == false)
{
x = Api.LoWrd(lParam); y = Api.HiWrd(lParam);
ptLastMousePositX = x;
ptCurrentMousePositX = x;
ptLastMousePositY = y;
ptCurrentMousePositY = y;
bMousing = true;
}
if (Api.GetFocus() != hWnd) Api.SetFocus(hWnd);
break;
case Api.WM_LBUTTONUP:
bMousing = false;
break;
case Api.WM_MOUSEMOVE:
x = Api.LoWrd(lParam); y = Api.HiWrd(lParam);
if (GI.IsLButtonDown() == false)
{
bMousing = false;
}
else
{
if ((GLwasX != x) || (GLwasY != y))
{
ptCurrentMousePositX = x;
ptCurrentMousePositY = y;
if (bMousing)
{
grSpinX -= (ptCurrentMousePositX - ptLastMousePositX);
grSpinY -= (ptCurrentMousePositY - ptLastMousePositY);
}
ptLastMousePositX = ptCurrentMousePositX;
ptLastMousePositY = ptCurrentMousePositY;
}
GLwasX = x; GLwasY = y;
}
break;
}
return Api.CallWindowProc(ghGLproc, hWnd, wMsg, wParam, lParam);
}
private void glMarqueeProc()
{
gnxT = gnOne;
if (gnxT < 0) { gnxT = 0; gnOne = 1; }
if (gnxT > GL_Template.Width - gnStW)
{
gnxT = GL_Template.Width - gnStW; gnOne = -1;
}
}
} // END class MAIN_Form
} // END namespace
好例子网口号:伸出你的我的手 — 分享!
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


支持(0) 盖楼(回复)