Index 扉へ 首頁
人類の品種・宇宙人・系外銀河など
【3D】UI ライブラリのソースコードです (C#)
0   商湯      2026年2月5日 木 10:17
Download source files:
http://www.jkofsp.net/files/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Takaku.Simulation;

namespace Takaku.UI3D
{
   public abstract class Element : ISimulationRemovable
   {
       public int X, Y, DX, DY;
       public Cached<int> FullX, FullY;
       public Cached<int> MouseX, MouseY;
       public Cached<bool> MouseInside, MouseInsideTmp;
       public bool Visible, Enabled;
       public Cached<bool> TrueVisible, TrueEnabled;

       public Element Parent; // controls
       public List<Element> Children = new List<Element>(); // forms

       public Cached<bool> OnMouseButtonDown, OnMouseButtonUp, OnMouseButtonDownTmp;

       public Element(int x, int y, int dx, int dy)
       {
           X = x;
           Y = y;
           DX = dx;
           DY = dy;

           FullX = new Cached<int>(() => Parent == null ? X : Parent.X + X);
           FullY = new Cached<int>(() => Parent == null ? Y : Parent.Y + Y);

           MouseX = new Cached<int>(() => Core.TheCore.MouseX - (Parent == null ? 0 : Parent.X) - X);
           MouseY = new Cached<int>(() => Core.TheCore.MouseY - (Parent == null ? 0 : Parent.Y) - Y);

           MouseInside = new Cached<bool>(() =>
               {
                   if (MouseX < 0 || MouseX >= DX || MouseY < 0 || MouseY >= DY
                       || (!TrueVisible))
                       return false;
                   // truely visible:
                   if (Parent == null) // a form
                   {
                       for (int i = Core.TheCore.Root.Count - 1; i >= 0; i--)
                       {
                           Element e = Core.TheCore.Root[i];
                           if (e == this)
                               break;
                           else
                               if (e.MouseX >= 0 && e.MouseX < e.DX && e.MouseY >= 0 && e.MouseY < e.DY
                                   && e.TrueVisible)
                                   return false;
                       }
                       for (int i = Children.Count - 1; i >= 0; i--)
                       {
                           Element e = Children[i];
                           if (e.MouseX >= 0 && e.MouseX < e.DX && e.MouseY >= 0 && e.MouseY < e.DY
                               && e.TrueVisible)
                               return false;
                       }
                       return MouseX >= 0 && MouseX < DX && MouseY >= 0 && MouseY < DY;
                   }
                   else // a control
                   {
                       for (int i = Core.TheCore.Root.Count - 1; i >= 0; i--)
                       {
                           Element e = Core.TheCore.Root[i];
                           if (e == Parent)
                               break;
                           else
                               if (e.MouseX >= 0 && e.MouseX < e.DX && e.MouseY >= 0 && e.MouseY < e.DY
                                   && e.TrueVisible)
                                   return false;
                       }
                       return MouseX >= 0 && MouseX < DX && MouseY >= 0 && MouseY < DY;                        
                   }
               });

           MouseInsideTmp = new Cached<bool>(() =>
               {
                   if (MouseX < 0 || MouseX >= DX || MouseY < 0 || MouseY >= DY
                          || (!TrueVisible))
                       return false;
                   // truely visible:
                   if (Parent == null) // a form
                   {
                       for (int i = Core.TheCore.Root.Count - 1; i >= 0; i--)
                       {
                           Element e = Core.TheCore.Root[i];
                           if (e == this)
                               return MouseX >= 0 && MouseX < DX && MouseY >= 0 && MouseY < DY;
                           else
                               if (e.MouseX >= 0 && e.MouseX < e.DX && e.MouseY >= 0 && e.MouseY < e.DY
                                   && e.TrueVisible)
                                   return false;
                       }
                       return false;
                   }
                   else // a control
                       return MouseInside;
               });

           Visible = true;
           Enabled = true;

           TrueVisible = new Cached<bool>(() => (Parent == null ? true : Parent.Visible) && Visible);
           TrueEnabled = new Cached<bool>(() => (Parent == null ? true : Parent.Enabled) && Enabled);
           
           OnMouseButtonDown = new Cached<bool>(() => (TrueEnabled && MouseInside) ? Core.TheCore.MouseButtonDown : false);
           OnMouseButtonUp = new Cached<bool>(() => (TrueEnabled && MouseInside) ? Core.TheCore.MouseButtonUp : false);
           OnMouseButtonDownTmp = new Cached<bool>(() => (TrueEnabled && MouseInsideTmp) ? Core.TheCore.MouseButtonDown : false);
       }

       public virtual void RemoveSimulation()
       {
           FullX.Remove();
           FullY.Remove();
           MouseX.Remove();
           MouseY.Remove();
           MouseInside.Remove();
           MouseInsideTmp.Remove();
           TrueVisible.Remove();
           TrueEnabled.Remove();
           OnMouseButtonDown.Remove();
           OnMouseButtonUp.Remove();
           OnMouseButtonDownTmp.Remove();
       }

       public abstract Element Update(); // returns a form to be bringed to the top
       public abstract void Render(Device dev);
   }

   public class Core
   {
       public static Core TheCore;

       public bool AllowDragging;

       public int DX, DY;

       public int MouseDX, MouseDY, MouseDZ, MouseX, MouseY;
       public bool MouseLeftButton, MouseRightButton, MouseMiddleButton;
       public bool MouseButtonDown, MouseButtonUp;

       public Cached<bool> MouseOutside;

       public List<Element> Root = new List<Element>();

       public Microsoft.DirectX.Direct3D.Font D3DXFont;

       public Core(int dx, int dy, bool allowDragging, Device dev)
       {
           AllowDragging = allowDragging;

           DX = dx;
           DY = dy;

           MouseOutside = new Cached<bool>(() =>
               {
                   foreach (Element e in Root)
                   {
                       if (e.MouseInsideTmp || ((Form)e).IsDragging)
                           return false;
                   }

                   return true;
               });

           D3DXFont = new Microsoft.DirectX.Direct3D.Font(dev, new System.Drawing.Font("Arial", 10.0f));
       }

       public void Update()
       {
           List<Element> tmps = new List<Element>();
           foreach (Element e in Root)
           {
               Element tmp = e.Update();
               if (tmp != null)
                   tmps.Add(tmp);

               foreach (Element f in e.Children)
                   f.Update();
           }
           foreach (Element tmp in tmps)
           {
               Root.Remove(tmp);
               Root.Add(tmp);
           }
       }

       public void Render(Device dev)
       {
           foreach (Element e in Root)
           {
               if (e.TrueVisible)
                   e.Render(dev);

               foreach (Element f in e.Children)
                   if (f.TrueVisible)
                       f.Render(dev);
           }
       }

       public struct MyVertex
       {
           public Vector4 X;
           public int Color;
           public MyVertex(float x, float y, int color)
           {
               X = new Vector4(x, y, 0.0f, 1.0f);
               Color = color;
           }

           public static readonly VertexFormats Format = VertexFormats.Transformed /*PositionWではなく!*/ | VertexFormats.Diffuse;
       }

       public static void DrawRect(Device dev, int x1, int y1, int x2, int y2, Color color)
       {
           VertexBuffer vb = new VertexBuffer(typeof(MyVertex), 8, dev, Usage.None, MyVertex.Format, Pool.Managed);
           MyVertex[] vert = (MyVertex[])vb.Lock(0, LockFlags.None);

           vert[0] = new MyVertex((float)x1, (float)y1, color.ToArgb());
           vert[1] = new MyVertex((float)x2, (float)y1, color.ToArgb());

           vert[2] = new MyVertex((float)x1, (float)y2, color.ToArgb());
           vert[3] = new MyVertex((float)x2, (float)y2, color.ToArgb());

           vert[4] = new MyVertex((float)x1, (float)y1, color.ToArgb());
           vert[5] = new MyVertex((float)x1, (float)y2, color.ToArgb());

           vert[6] = new MyVertex((float)x2, (float)y1, color.ToArgb());
           vert[7] = new MyVertex((float)x2, (float)y2, color.ToArgb());

           vb.Unlock();

           dev.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
           dev.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
           dev.SetStreamSource(0, vb, 0);
           dev.VertexFormat = MyVertex.Format;
           dev.DrawPrimitives(PrimitiveType.LineList, 0, 4);
       }

       public static void FillRect(Device dev, int x1, int y1, int x2, int y2, Color color)
       {
           VertexBuffer vb = new VertexBuffer(typeof(MyVertex), 6, dev, Usage.None, MyVertex.Format, Pool.Managed);
           MyVertex[] vert = (MyVertex[])vb.Lock(0, LockFlags.None);

           vert[0] = new MyVertex((float)x1, (float)y1, color.ToArgb());
           vert[1] = new MyVertex((float)x2, (float)y1, color.ToArgb());
           vert[2] = new MyVertex((float)x1, (float)y2, color.ToArgb());

           vert[3] = new MyVertex((float)x2, (float)y2, color.ToArgb());
           vert[4] = new MyVertex((float)x1, (float)y2, color.ToArgb());
           vert[5] = new MyVertex((float)x2, (float)y1, color.ToArgb());

           vb.Unlock();

           dev.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
           dev.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
           dev.SetStreamSource(0, vb, 0);
           dev.VertexFormat = MyVertex.Format;
           dev.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
       }
   }

   public class Form : Element
   {
       public Color BorderColor, FillColor;

       public bool IsDragging;
       private int OldMouseX, OldMouseY;

       public Form(int x, int y, int dx, int dy)
           : base(x, y, dx, dy)
       {
           Core.TheCore.Root.Add(this);

           BorderColor = Color.FromArgb(unchecked((int)0xFF0000ff));
           FillColor = Color.FromArgb(unchecked((int)0xFF000000));
       }

       public override void RemoveSimulation()
       {
           base.RemoveSimulation();
       }

       public override Element Update() // returns a form to be bringed to the top
       {
           if (Core.TheCore.AllowDragging)
           {
               if (OnMouseButtonDown)
               {
                   IsDragging = true;
                   OldMouseX = MouseX;
                   OldMouseY = MouseY;
               }
               if (Core.TheCore.MouseButtonUp)
               {
                   IsDragging = false;
               }

               if (IsDragging)
               {
                   X += MouseX - OldMouseX;
                   Y += MouseY - OldMouseY;
                   
                   if (X < 0)
                       X = 0;
                   if (Y < 0)
                       Y = 0;
                   if (X + DX >= Core.TheCore.DX)
                       X = Core.TheCore.DX - DX;
                   if (Y + DY >= Core.TheCore.DY)
                       Y = Core.TheCore.DY - DY;
                   if (DX > Core.TheCore.DX)
                       DX = Core.TheCore.DX;
                   if (DY > Core.TheCore.DY)
                       DY = Core.TheCore.DY;
               }
           }

           if (OnMouseButtonDownTmp)
               return this;
           return null;
       }

       public override void Render(Device dev)
       {
           Core.FillRect(dev, X, Y, X + DX, Y + DY, FillColor);
           Core.DrawRect(dev, X, Y, X + DX, Y + DY, BorderColor);
       }
   }

   public enum ButtonState
   {
       Normal,
       Hovered,
       Pressed,

       PressedToHovered,
   }

   public class Button : Element
   {
       public string Text;
       //public int TextX, TextY, TextDX, TextDY;
       public Color BorderColor, FillColor, TextColor;
       public Color HoveredBorderColor, HoveredFillColor, HoveredTextColor;
       public Color PressedBorderColor, PressedFillColor, PressedTextColor;
       public Surface Picture, HoveredPicture, PressedPicture;
       public State<ButtonState> State;

       private Diff<ButtonState> dState;
       public Cached<bool> OnMouseClick;

       public Button(Form form, int x, int y, int dx, int dy)
           : base(x, y, dx, dy)
       {
           form.Children.Add(this);
           Parent = form;
           
           Text = "Button";

           BorderColor = Color.FromArgb(unchecked((int)0xFF0000ff));
           FillColor = Color.FromArgb(unchecked((int)0xFF000000));
           TextColor = Color.FromArgb(unchecked((int)0xFFffff00));

           HoveredBorderColor = Color.FromArgb(unchecked((int)0xFFff0000));
           HoveredFillColor = Color.FromArgb(unchecked((int)0xFFffff00));
           HoveredTextColor = Color.FromArgb(unchecked((int)0xFFff0000));

           PressedBorderColor = Color.FromArgb(unchecked((int)0xFF00ff00));
           PressedFillColor = Color.FromArgb(unchecked((int)0xFFff0000));
           PressedTextColor = Color.FromArgb(unchecked((int)0xFF0000ff));

           State = new State<ButtonState>(ButtonState.Normal,
               state =>
               {
                   if (!TrueEnabled)
                       return ButtonState.Normal;
                   if (state == ButtonState.Normal)
                   {
                       if (MouseInside)
                       {
                           if (Core.TheCore.MouseLeftButton)
                               return ButtonState.Pressed;
                           else
                               return ButtonState.Hovered;
                       }
                       else
                           return ButtonState.Normal;
                   }
                   else if (state == ButtonState.Hovered)
                   {
                       if (MouseInside)
                       {
                           if (Core.TheCore.MouseLeftButton)
                               return ButtonState.Pressed;
                           else
                               return ButtonState.Hovered;
                       }
                       else
                           return ButtonState.Normal;
                   }
                   else if (state == ButtonState.Pressed)
                   {
                       if (Core.TheCore.MouseLeftButton)
                           return ButtonState.Pressed;
                       else
                       {
                           if (MouseInside)
                               return ButtonState.Hovered;
                           else
                               return ButtonState.Normal;
                       }
                   }
                   else
                       return ButtonState.Normal;
               });

           Diff<ButtonState>.FuncSub = new Func<ButtonState, ButtonState, ButtonState>((a, b) => (a == ButtonState.Hovered && b == ButtonState.Pressed) ? ButtonState.PressedToHovered : a);
           dState = new Diff<ButtonState>(ButtonState.Normal, () => State);
           OnMouseClick = new Cached<bool>(() => dState == ButtonState.PressedToHovered ? true : false);
       }

       public override void RemoveSimulation()
       {
           State.Remove();
           dState.Remove();
           OnMouseClick.Remove();

           base.RemoveSimulation();
       }

       public override Element Update() // returns a form to be bringed to the top
       {
           return null;
       }

       public override void Render(Device dev)        
       {
           Color foreColor = new Color(), fillColor = new Color();
           if (State == ButtonState.Normal)
           {
               foreColor = BorderColor;
               fillColor = FillColor;
           }
           else if (State == ButtonState.Hovered)
           {
               foreColor = HoveredBorderColor;
               fillColor = HoveredFillColor;
           }
           else if (State == ButtonState.Pressed)
           {
               foreColor = PressedBorderColor;
               fillColor = PressedFillColor;
           }
           Core.FillRect(dev, FullX, FullY, FullX + DX, FullY + DY, fillColor);
           Core.DrawRect(dev, FullX, FullY, FullX + DX, FullY + DY, foreColor);

           Color textColor = new Color();
           if (State == ButtonState.Normal)
               textColor = TextColor;
           else if (State == ButtonState.Hovered)
               textColor = HoveredTextColor;
           else if (State == ButtonState.Pressed)
               textColor = PressedTextColor;

           Core.TheCore.D3DXFont.DrawText(null,
               Text,
               new Rectangle(FullX, FullY, DX, DY),
               DrawTextFormat.Center | DrawTextFormat.VerticalCenter,
               textColor);
       }
   }

   public class TextBox : Element
   {
       public Bind<string> Text;
       public Color BorderColor, FillColor, TextColor;
       public bool Transparent;

       public TextBox(Form form, int x, int y, int dx, int dy)
           : base(x, y, dx, dy)
       {
           form.Children.Add(this);
           Parent = form;

           BorderColor = Color.FromArgb(unchecked((int)0xFF0000ff));
           FillColor = Color.FromArgb(unchecked((int)0xFF000000));
           TextColor = Color.FromArgb(unchecked((int)0xFFffff00));
           Transparent = false;
       }

       public override Element Update() // returns a form to be bringed to the top
       {
           return null;
       }

       public override void Render(Device dev)
       {
           if (!Transparent)
           {
               Core.FillRect(dev, FullX, FullY, FullX + DX, FullY + DY, FillColor);
               Core.DrawRect(dev, FullX, FullY, FullX + DX, FullY + DY, BorderColor);
           }

           Core.TheCore.D3DXFont.DrawText(null,
               Text(),
               new Rectangle(FullX + 5, FullY + 5, DX - 10, DY - 10),
               DrawTextFormat.WordBreak,
               TextColor);
       }
   }

   public class ListBox : Element
   {
       public Color BorderColor, FillColor, TextColor;
       public Color SelectedBorderColor, SelectedFillColor, SelectedTextColor;
       public bool Transparent;
       public List<List<string>> Items = new List<List<string>>();
       public int? SelectedIndex;
       public int LineDY;
       public List<int> ColumnsX = new List<int>();

       public ListBox(Form form, int x, int y, int dx, int dy)
           : base(x, y, dx, dy)
       {
           form.Children.Add(this);
           Parent = form;

           BorderColor = Color.FromArgb(unchecked((int)0xFF0000ff));
           FillColor = Color.FromArgb(unchecked((int)0xFF000000));
           TextColor = Color.FromArgb(unchecked((int)0xFFffff00));
           SelectedBorderColor = Color.FromArgb(unchecked((int)0xFFff0000));
           SelectedFillColor = Color.FromArgb(unchecked((int)0xFFffff00));
           SelectedTextColor = Color.FromArgb(unchecked((int)0xFF000000));
           Transparent = false;
           SelectedIndex = null;
           LineDY = 15;
       }

       public override Element Update() // returns a form to be bringed to the top
       {
           if (Core.TheCore.MouseLeftButton && OnMouseButtonDown)
           {
               SelectedIndex = MouseY / LineDY;
           }

           if (SelectedIndex >= Items.Count)
               SelectedIndex = null;

           return null;
       }

       public override void Render(Device dev)
       {
           if (!Transparent)
           {
               Core.FillRect(dev, FullX, FullY, FullX + DX, FullY + DY, FillColor);
               Core.DrawRect(dev, FullX, FullY, FullX + DX, FullY + DY, BorderColor);
           }

           for (int i = 0; i < Items.Count; i++) // line
           {
               if (SelectedIndex != null && SelectedIndex == i)
               {
                   Core.FillRect(dev,
                       FullX,
                       FullY + SelectedIndex.Value * LineDY,
                       FullX + DX,
                       FullY + SelectedIndex.Value * LineDY + LineDY,
                       SelectedFillColor);
                   Core.DrawRect(dev,
                       FullX,
                       FullY + SelectedIndex.Value * LineDY,
                       FullX + DX,
                       FullY + SelectedIndex.Value * LineDY + LineDY,
                       SelectedBorderColor);
               }
               for (int j = 0; j < Items[i].Count; j++) // column
               {                    
                   Core.TheCore.D3DXFont.DrawText(null,
                       Items[i][j],
                       new Rectangle(FullX + ColumnsX[j], FullY + LineDY * i, ((j < ColumnsX.Count - 1) ? ColumnsX[j + 1] : DX) - ColumnsX[j], LineDY),
                       DrawTextFormat.None,
                       (SelectedIndex == null || SelectedIndex != i) ? TextColor : SelectedTextColor);
               }
           }
       }
   }

   public class ProgressBar : Element
   {
       public Bind<double> Progress;
       public Color BorderColor, BackColor, ForeColor;

       public ProgressBar(Form form, int x, int y, int dx, int dy)
           : base(x, y, dx, dy)
       {
           form.Children.Add(this);
           Parent = form;

           BorderColor = Color.FromArgb(unchecked((int)0xFF0000ff));
           BackColor = Color.FromArgb(unchecked((int)0xFFffffff));
           ForeColor = Color.FromArgb(unchecked((int)0xFF00ff00));
       }

       public override void Render(Device dev)
       {
           Core.FillRect(dev, FullX, FullY, FullX + DX, FullY + DY, BackColor);
           Core.FillRect(dev, FullX, FullY, FullX + (int)(Progress() * DX), FullY + DY, ForeColor);
           Core.DrawRect(dev, FullX, FullY, FullX + DX, FullY + DY, BorderColor);
       }

       public override Element Update() // returns a form to be bringed to the top
       {
           return null;
       }
   }
}
この記事は 2026年9月9日 水 18:02 に作者によって編集されました
1   商湯      2026年2月5日 木 10:18
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;
using System.Runtime.InteropServices;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX.DirectInput;
using Takaku.Simulation;
using Takaku.UI3D;

namespace UITest
{
   public partial class Form1 : System.Windows.Forms.Form
   {
       int GWL_STYLE = -16;
       [DllImport("user32.dll", CharSet = CharSet.Unicode)]
       static extern int GetWindowLong(IntPtr hwnd, int nIndex);
       [StructLayout(LayoutKind.Sequential)]
       struct RECT
       {
           public int Left, Top, Right, Bottom;
       }
       [DllImport("user32.dll", CharSet = CharSet.Unicode)]
       static extern int AdjustWindowRect(ref RECT rc, int style, bool bMenu);
       [StructLayout(LayoutKind.Sequential)]
       struct POINT
       {
           public int X, Y;
       }
       [DllImport("user32.dll", CharSet = CharSet.Unicode)]
       static extern int GetCursorPos(out POINT pt);
       [DllImport("user32.dll", CharSet = CharSet.Unicode)]
       static extern int SetCursorPos(int x, int y);

       Microsoft.DirectX.Direct3D.Device Dev;

       Microsoft.DirectX.DirectInput.Device DInputDevice;
       int MouseDX, MouseDY, MouseDZ, MouseScreenX, MouseScreenY, MouseX, MouseY;
       bool MouseLeftButton, MouseRightButton, MouseMiddleButton;
       bool OldMouseLeftButton, OldMouseRightButton, OldMouseMiddleButton;
       bool MouseButtonDown, MouseButtonUp;

       int SizeW = 1024, SizeH = 768;

       public Form1()
       {
           InitializeComponent();
       }

       private void Form1_Load(object sender, EventArgs e)
       {
           RECT rc;
           rc.Left = 0;
           rc.Top = 0;
           rc.Right = SizeW;
           rc.Bottom = SizeH;
           AdjustWindowRect(ref rc, GetWindowLong(Handle, GWL_STYLE), false);
           Width = rc.Right - rc.Left;
           Height = rc.Bottom - rc.Top;
           Left = Screen.PrimaryScreen.Bounds.Width / 2 - Width / 2;
           Top = Screen.PrimaryScreen.Bounds.Height / 2 - Height / 2;

           PresentParameters pp = new PresentParameters();
           pp.Windowed = true;
           pp.SwapEffect = SwapEffect.Copy;
           pp.BackBufferCount = 1;
           pp.BackBufferWidth = SizeW;
           pp.BackBufferHeight = SizeH;
           //pp.BackBufferFormat = Format.X8R8G8B8;
           pp.EnableAutoDepthStencil = false;
           pp.AutoDepthStencilFormat = DepthFormat.D16;
           pp.PresentFlag = PresentFlag.DeviceClip | PresentFlag.Video;
           pp.DeviceWindow = this;

           Dev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, new PresentParameters[] { pp });

           POINT pt;
           GetCursorPos(out pt);
           MouseScreenX = pt.X;
           MouseScreenY = pt.Y;
           Point point;
           point = PointToClient(new Point(MouseScreenX, MouseScreenY));
           MouseX = point.X;
           MouseY = point.Y;

           DInputDevice = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);
           DInputDevice.SetCooperativeLevel(Handle, Microsoft.DirectX.DirectInput.CooperativeLevelFlags.Background
               | Microsoft.DirectX.DirectInput.CooperativeLevelFlags.NonExclusive);
           DInputDevice.SetDataFormat(DeviceDataFormat.Mouse);
           DInputDevice.Acquire();

           Core.TheCore = new Core(SizeW, SizeH, true, Dev);

           MouseState mouseState;

           Show();
           Activate();

           Takaku.UI3D.Form formA = new Takaku.UI3D.Form(0, 0, 100, 200);

           Takaku.UI3D.Button buttonA = new Takaku.UI3D.Button(formA, 10, 10, 50, 30);
           buttonA.FillColor = Color.Green;
           buttonA.Text = "btn";

           Takaku.UI3D.Form formB = new Takaku.UI3D.Form(50, 50, 100, 200);

           Takaku.UI3D.TextBox textBoxA = new Takaku.UI3D.TextBox(formB, 10, 10, 80, 50);
           textBoxA.Text = () => "aaaa aaaa aaaa aaaa aaaa aaaa aaaa";
           textBoxA.FillColor = Color.Green;
           
           Takaku.UI3D.ListBox listBoxA = new Takaku.UI3D.ListBox(formA, 10, 60, 80, 80);
           listBoxA.ColumnsX.Add(0);
           listBoxA.ColumnsX.Add(50);
           listBoxA.Items.Add(new List<string>());
           listBoxA.Items[0].Add("(0,0)");
           listBoxA.Items[0].Add("(0,1)");
           listBoxA.Items.Add(new List<string>());
           listBoxA.Items[1].Add("(1,0)");
           listBoxA.Items[1].Add("(1,1)");
           listBoxA.Items.Add(new List<string>());
           listBoxA.Items[2].Add("(2,0)");
           listBoxA.Items[2].Add("(2,1)");
           listBoxA.FillColor = Color.Green;
           listBoxA.SelectedTextColor = Color.Red;

           Takaku.UI3D.ProgressBar progressBarA = new Takaku.UI3D.ProgressBar(formB, 10, 65, 80, 15);
           progressBarA.Progress = () => 0.5;
           progressBarA.BorderColor = Color.Red;
           progressBarA.BackColor = Color.Yellow;
2   商湯      2026年2月5日 木 10:18

           while (Visible)
           {
               Application.DoEvents();

               Takaku.Simulation.ManagerState.TheManagerState.Update();
               Takaku.Simulation.ManagerDiff.TheManagerDiff.Update();

               mouseState = DInputDevice.CurrentMouseState;
               byte[] mouseButtons = mouseState.GetMouseButtons();
               MouseLeftButton = mouseButtons[0] != 0;
               MouseRightButton = mouseButtons[1] != 0;
               MouseMiddleButton = mouseButtons[2] != 0;
               if ((MouseLeftButton && (!OldMouseLeftButton))
                   || (MouseRightButton && (!OldMouseRightButton))
                   || (MouseMiddleButton && (!OldMouseMiddleButton)))
                   MouseButtonDown = true;
               if (((!MouseLeftButton) && OldMouseLeftButton)
                   || ((!MouseRightButton) && OldMouseRightButton)
                   || ((!MouseMiddleButton) && OldMouseMiddleButton))
                   MouseButtonUp = true;
               if (MouseLeftButton == OldMouseLeftButton
                   && MouseRightButton == OldMouseRightButton
                   && MouseMiddleButton == OldMouseMiddleButton)
                   MouseButtonUp = MouseButtonDown = false;
               OldMouseLeftButton = MouseLeftButton;
               OldMouseRightButton = MouseRightButton;
               OldMouseMiddleButton = MouseMiddleButton;
               MouseDX = mouseState.X;
               MouseDY = mouseState.Y;
               MouseDZ = mouseState.Z;
               MouseScreenX += mouseState.X;
               MouseScreenY += mouseState.Y;
               if (MouseScreenX < 0)
                   MouseScreenX = 0;
               if (MouseScreenX >= Screen.PrimaryScreen.Bounds.Width)
                   MouseScreenX = Screen.PrimaryScreen.Bounds.Width - 1;
               if (MouseScreenY < 0)
                   MouseScreenY = 0;
               if (MouseScreenY >= Screen.PrimaryScreen.Bounds.Height)
                   MouseScreenY = Screen.PrimaryScreen.Bounds.Height - 1;
               SetCursorPos(MouseScreenX, MouseScreenY);
               try
               {
                   point = PointToClient(new Point(MouseScreenX, MouseScreenY));
                   MouseX = point.X;
                   MouseY = point.Y;
                   //MouseX = Math.Min(Math.Max(0, point.X), SizeW - 1);
                   //MouseY = Math.Min(Math.Max(0, point.Y), SizeH - 1);

               }
               catch (Exception) { }
               /*if (MouseX == 0 || MouseX == SizeW - 1)
                   MouseDX = 0;
               if (MouseY == 0 || MouseY == SizeH - 1)
                   MouseDY = 0;*/


               Core.TheCore.MouseDX = MouseDX;
               Core.TheCore.MouseDY = MouseDY;
               Core.TheCore.MouseDZ = MouseDZ;
               Core.TheCore.MouseX = MouseX;
               Core.TheCore.MouseY = MouseY;
               Core.TheCore.MouseLeftButton = MouseLeftButton;
               Core.TheCore.MouseRightButton = MouseRightButton;
               Core.TheCore.MouseMiddleButton = MouseMiddleButton;
               Core.TheCore.MouseButtonDown = MouseButtonDown;
               Core.TheCore.MouseButtonUp = MouseButtonUp;

               Core.TheCore.Update();

               if (buttonA.OnMouseClick)
               {
                   //Core.TheCore.Root.Remove(formA);
                   formA.Visible = false;
                   Text += "x";
               }
               if (Core.TheCore.MouseOutside)
               {
                   Text = Core.TheCore.MouseX.ToString() + ", " + Core.TheCore.MouseY.ToString();
               }
               else
               {
                   Text = "-";
               }

               try
               {
                   Dev.Clear(ClearFlags.Target/* | ClearFlags.ZBuffer*/, 0, 1.0f, 0);
                   Dev.BeginScene();

                   Core.TheCore.Render(Dev);

                   Dev.EndScene();
                   Dev.Present();
               }
               catch (Exception) { }

               Takaku.Simulation.ManagerCached.TheManagerCached.Flush();
Takaku.Simulation.ManagerState.TheManagerState.Flush();
           }

           formA.RemoveSimulation();
           buttonA.RemoveSimulation();
           formB.RemoveSimulation();
           textBoxA.RemoveSimulation();
           listBoxA.RemoveSimulation();

           Application.Exit();
       }
   }
}
この記事は 2026年9月9日 水 18:06 に作者によって編集されました
名前      編集用パスワード(省略可)    パスワードの記憶
数式 αβγ IPA http:// 画像 B I U 上 下
(添付ファイルは http://www.jkofsp.net/up/ にアップロードしてください)