[C#] - 회전형태의 메뉴 화면 처리 GsiCarousel 데모
C# 2008. 3. 4. 13:05 |Carousel 의 기본 구동 알로리즘을 사용해서 구현해본 예제 입니다.
버튼 컨트롤로 사용한 거지만, GDI+ 또는 Panel 등을 이용해서
처리 하면 깔끔하게 처리가 가능할 거 같습니다.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GsiCarousel
{
public partial class Form1 : Form
{
static Single[] SpriteAngle = new Single[10];
const double PiDiv180 = 1.74532925199433E-2;
static int[] Zorder = new int[10];
static int[] FaceOrder = new int[10];
static Button[] ButtonList = new Button[10];
public Form1()
{
InitializeComponent();
LoadInfo();
}
private void LoadInfo()
{
int AngleStep = 0;
int UboundSpriteData = 10;
int StepAngle = (int)(360 / UboundSpriteData);
for (int K = 0; K < UboundSpriteData; K++)
{
SpriteAngle[K] = AngleStep;
ButtonList[K] = new Button();
ButtonList[K].Location = new System.Drawing.Point(this.Width / 2, this.Height / 2);
ButtonList[K].Name = "Item " + K.ToString();
ButtonList[K].Size = new System.Drawing.Size(100, 50);
ButtonList[K].TabIndex = 0;
ButtonList[K].Text = "Item " + K.ToString();
ButtonList[K].UseVisualStyleBackColor = true;
this.Controls.Add(ButtonList[K]);
AngleStep += StepAngle;
}
}
private void timerMainLoop_Tick(object sender, EventArgs e)
{
int Y = 60;
float speed = 2.0f;
float fl = 182.3f;
float Radius = 120.0f;
int Xcenter = ButtonList[0].Width / 2;
int Ycenter = ButtonList[0].Height / 2;
int Zcenter = Ycenter / 2;
int UboundSpriteData = 10;
int K;
for (K = UboundSpriteData - 1; K > -1; K--)
{
float angle = SpriteAngle[K];
float anglePi = (float)(angle * PiDiv180);
float z = (float)(Math.Sin(anglePi) * Radius + Zcenter);
float scale = fl / (fl + z);
int X = (int)(Math.Cos(anglePi) * Radius);
ButtonList[K].Left = 150 + (int)(X * scale + Xcenter);
ButtonList[K].Top = 100 + (int)(Y * scale + Ycenter - Y);
Zorder[K] = (int)(angle - 90); if (Zorder[K] > 180) Zorder[K] = 360 - Zorder[K];
FaceOrder[K] = K;
angle += speed; if (angle > 359) angle = angle - 360;
SpriteAngle[K] = angle;
}
// Compute current Z-order
Array.Sort(Zorder, FaceOrder);
// Z-order Change
K = FaceOrder[0];
ButtonList[K].SendToBack();
ButtonList[FaceOrder[UboundSpriteData - 1]].BringToFront();
}
}
}