/// <summary> /// Przygotowuje bitmapę oraz scenę. /// </summary> /// <param name="view"></param> public Zadanie1(IZadanie1 view) { _view = view; _view.Loaded += OnLoaded; _bmp = new BufferedBitmap(750, 450); _device = new Device(_bmp, new Bresenham(), new LiangBarskyClipping()); _scene = new Scene { Camera = new Camera { Position = Vector3.Zero, LookDirection = Vector3.UnitZ, FieldOfView = 60 } }; _scene = SceneImporter.LoadJsonFile(Path.Combine("Resources", "scene.unity.babylon")); // Przypisujemy płaszczyźnie kolor szary, aby mieć punkt odniesienia do "podłogi". _scene.Meshes.First(m => m.Name == "Plane").Color = Colors.DarkGrey; _fpsCounter.StatsChanged += UpdateDebugInfo; }
// Prepares the bitmap and the scene. public SceneViewModel(ISceneViewModel view) { _view = view; _view.Loaded += OnLoaded; _bmp = new BufferedBitmap(750, 450); _device = new Device(_bmp, new Bresenham(), new LiangBarskyClipping()); _scene = new Scene { Camera = new Camera { Position = Vector3.Zero, LookDirection = Vector3.UnitZ, FieldOfView = 60 } }; _scene = SceneImporter.LoadJsonFile(Path.Combine("Resources", "scene.unity.babylon")); _scene.Meshes.First(m => m.Name == "Plane").Color = Engine.Utilities.Colors.DarkGrey; //_scene.Meshes.Add(new Cube()); //_scene.Meshes.Add(new Sphere()); //_scene.Meshes.Add(new Cone()); //_scene.Meshes.Add(new Tube()); }
protected override void WndProc(ref Message m) { const int WM_PAINT = 0xF; const int WM_PRINTCLIENT = 0x0318; const int WM_CTLCOLORLISTBOX = 0x0134; const int CB_ADDSTRING = 0x143; const int CB_INSERTSTRING = 0x14A; const int CB_DELETESTRING = 0x0144; WinApi.RECT rect = new WinApi.RECT(); switch (m.Msg) { case WM_CTLCOLORLISTBOX: if (IsMultiColumnDropDown && base.DroppedDown) { BarUtilities.InvokeDelayed(new MethodInvoker(delegate { base.DroppedDown = false; }), 10); break; } if (BarFunctions.IsWindows7 && !IsMultiColumnDropDown) { if (m_DropDownHandle != m.LParam) ReleasePopupHandler(); if (_PopupMsgHandler == null) CreatePopupHandler(m.LParam); } m_DropDownHandle = m.LParam; if (!IsMultiColumnDropDown && (m_DropDownHeight > 0 || this.Items.Count == 0)) { WinApi.GetWindowRect(m.LParam, ref rect); int height = m_DropDownHeight; if (this.Items.Count == 0) height = Math.Max(18, this.ItemHeight); Point thisLocation = this.PointToScreen(Point.Empty); if (rect.Top < thisLocation.Y) rect.Top = thisLocation.Y + this.Height; NativeFunctions.SetWindowPos(m.LParam, IntPtr.Zero, rect.Left, rect.Top, rect.Width, height, NativeFunctions.SWP_NOACTIVATE); } break; case (int)WinApi.WindowsMessages.CB_GETDROPPEDSTATE: base.WndProc(ref m); if (m.Result == IntPtr.Zero && DroppedDownInternal && !IsMultiColumnDropDown) DroppedDownInternal = false; return; case NativeFunctions.WM_SETFOCUS: if (m.WParam != this.Handle) m_LastFocusWindow = m.WParam; break; case CB_ADDSTRING: if (this.Items.Count > 0) { ComboItem cb = this.Items[this.Items.Count - 1] as ComboItem; if (cb != null) cb.m_ComboBox = this; } break; case CB_INSERTSTRING: int index = WinApi.ToInt(m.WParam); if (index >= 0 && index < this.Items.Count) { ComboItem cb = this.Items[index] as ComboItem; if (cb != null) cb.m_ComboBox = this; } m_SelectedIndexInternal = -1; break; case CB_DELETESTRING: m_SelectedIndexInternal = -1; break; case NativeFunctions.WM_USER + 7: if (this.DropDownStyle == ComboBoxStyle.DropDown && !m_Focused) this.SelectionLength = 0; this.Invalidate(true); return; case (int)WinApi.WindowsMessages.WM_LBUTTONDOWN: { if (IsMultiColumnDropDown) { if (IsPopupOpen) CloseMultiColumnDropDown(); else if (DateTime.Now.Subtract(_MultiDropDownClosedAtTime).TotalMilliseconds > 500 && (this.Focused || this.Focus())) { OpenMultiColumnDropDown(); } return; // Don't call base } break; } case (int)WinApi.WindowsMessages.WM_REFLECTCOMMAND: { if (IsMultiColumnDropDown) { int wp = WinApi.HIWORD(m.WParam); if (wp == CBN_DROPDOWN) { OpenMultiColumnDropDown(); return; // Don't call base } else if (wp == CBN_CLOSEUP) { if (DateTime.Now.Subtract(_MultiDropDownOpenedAtTime).TotalMilliseconds > 900) { CloseMultiColumnDropDown(); return; // Don't call base } } } break; } } if (m_DefaultStyle) { base.WndProc(ref m); return; } if ((m.Msg == WM_PAINT || m.Msg == WM_PRINTCLIENT) && DrawMode != DrawMode.Normal) { WinApi.GetWindowRect(m.HWnd, ref rect); Rectangle r = new Rectangle(0, 0, rect.Width, rect.Height); if (m.Msg == WM_PAINT) { WinApi.PAINTSTRUCT ps = new WinApi.PAINTSTRUCT(); IntPtr hdc = WinApi.BeginPaint(m.HWnd, ref ps); using (Graphics gHdc = Graphics.FromHdc(hdc)) { using (BufferedBitmap bmp = new BufferedBitmap(gHdc, r)) { PaintComboBox(bmp.Graphics, r); bmp.Render(gHdc); } } WinApi.EndPaint(m.HWnd, ref ps); } else { using (Graphics g = Graphics.FromHdc(m.WParam)) PaintComboBox(g, r); } if (this.Parent is ItemControl) ((ItemControl)this.Parent).UpdateKeyTipsCanvas(); } else { base.WndProc(ref m); } }
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { UpdateDebugInfo(); var bmp = new BufferedBitmap(300, 300); _view.Render2.Source = bmp.BitmapSource; _shader = new PixelShader(bmp); _view.RefreshButton.Click += (o, args) => RenderScene(); _view.IlluminationObjectChanged += o => { _currentObject = o; UpdateDebugInfo(); }; _view.KeyDown += (o, args) => { var move = Vector3.Zero; var step = 0.25f; switch (args.Key) { case Key.W: move = new Vector3(0, step, 0); break; case Key.S: move = new Vector3(0, -step, 0); break; case Key.A: move = new Vector3(-step, 0, 0); break; case Key.D: move = new Vector3(step, 0, 0); break; case Key.E: move = new Vector3(0, 0, step); break; case Key.C: move = new Vector3(0, 0, -step); break; case Key.I: _scenes[_currentObject].Lights[0].AttenuationCutoff += 1; RenderScene(); break; case Key.K: _scenes[_currentObject].Lights[0].AttenuationCutoff -= 1; RenderScene(); break; case Key.O: _scenes[_currentObject].Lights[0].Radius += 1; RenderScene(); break; case Key.L: _scenes[_currentObject].Lights[0].Radius -= 1; RenderScene(); break; } if (move.Length() > 0) { _scenes[_currentObject].Lights[0].Position += move; RenderScene(); UpdateDebugInfo(); } }; RenderScene(); }
private void PaintInternal(Graphics g, IntPtr hdc) { UpdateScrollValues(); using (BufferedBitmap bmp = new BufferedBitmap(g, new Rectangle(0, 0, m_ParentScrollBar.Width, m_ParentScrollBar.Height))) { m_ScrollBarCore.Paint(GetItemPaintArgs(bmp.Graphics)); bmp.Render(g); } }
//private void PaintUnBuffered() //{ // IntPtr dc = WinApi.GetWindowDC(m_Control.Handle); // try // { // using (Graphics g = Graphics.FromHdc(dc)) // { // g.SetClip(GetClientRectangle(), CombineMode.Exclude); // if (!ShouldSkinScrollbars) // { // WinApi.SCROLLBARINFO psbi = new WinApi.SCROLLBARINFO(); // psbi.cbSize = Marshal.SizeOf(psbi); // WinApi.GetScrollBarInfo(m_Control.Handle, (uint)WinApi.eObjectId.OBJID_VSCROLL, ref psbi); // if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) // { // Rectangle rvs = ScreenToNonClientRectangle(psbi.rcScrollBar.ToRectangle()); // g.SetClip(rvs, System.Drawing.Drawing2D.CombineMode.Exclude); // } // psbi = new WinApi.SCROLLBARINFO(); // psbi.cbSize = Marshal.SizeOf(psbi); // WinApi.GetScrollBarInfo(m_Control.Handle, (uint)WinApi.eObjectId.OBJID_HSCROLL, ref psbi); // if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) // { // Rectangle rvs = ScreenToNonClientRectangle(psbi.rcScrollBar.ToRectangle()); // g.SetClip(rvs, System.Drawing.Drawing2D.CombineMode.Exclude); // } // } // PaintNonClientArea(g); // g.ResetClip(); // } // } // finally // { // WinApi.ReleaseDC(m_Control.Handle, dc); // } //} private void RenderNonClientAreaBitmap(BufferedBitmap bmp) { if (bmp == null) return; IntPtr dc = WinApi.GetWindowDC(m_Control.Handle); try { using (Graphics g = Graphics.FromHdc(dc)) { Rectangle[] clips = new Rectangle[3]; clips[0] = GetClientRectangle(); if (!ShouldSkinScrollbars) { WinApi.SCROLLBARINFO psbi = new WinApi.SCROLLBARINFO(); psbi.cbSize = Marshal.SizeOf(psbi); WinApi.GetScrollBarInfo(m_Control.Handle, (uint)WinApi.eObjectId.OBJID_VSCROLL, ref psbi); if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) { Rectangle rvs = ScreenToNonClientRectangle(psbi.rcScrollBar.ToRectangle()); clips[1] = rvs; } psbi = new WinApi.SCROLLBARINFO(); psbi.cbSize = Marshal.SizeOf(psbi); WinApi.GetScrollBarInfo(m_Control.Handle, (uint)WinApi.eObjectId.OBJID_HSCROLL, ref psbi); if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) { Rectangle rvs = ScreenToNonClientRectangle(psbi.rcScrollBar.ToRectangle()); clips[2] = rvs; } } bmp.Render(g, clips); } } finally { WinApi.ReleaseDC(m_Control.Handle, dc); } }
//private Bitmap GetNonClientAreaBitmap() //{ // if (m_Control.Width <= 0 || m_Control.Height <= 0 || m_SuspendPaint || !m_Control.IsHandleCreated) return null; // Bitmap bmp = new Bitmap(m_Control.Width, m_Control.Height); // using (Graphics g = Graphics.FromImage(bmp)) // { // PaintNonClientArea(g); // } // return bmp; //} private BufferedBitmap GetNonClientAreaBitmap() { if (m_Control.Width <= 0 || m_Control.Height <= 0 || m_SuspendPaint || !m_Control.IsHandleCreated) return null; BufferedBitmap bmp = null; IntPtr hdc = WinApi.GetWindowDC(m_Control.Handle); Rectangle r = GetControlRectangle(); try { bmp = new BufferedBitmap(hdc, new Rectangle(0, 0, r.Width, r.Height)); PaintNonClientArea(bmp.Graphics); } finally { WinApi.ReleaseDC(m_Control.Handle, hdc); } return bmp; }
protected override void WndProc(ref Message m) { if (m.Msg == (int)WinApi.WindowsMessages.WM_PAINT) { WinApi.PAINTSTRUCT ps = new WinApi.PAINTSTRUCT(); IntPtr hdc = WinApi.BeginPaint(m.HWnd, ref ps); try { Graphics g = Graphics.FromHdc(hdc); try { WinApi.RECT r = new WinApi.RECT(); WinApi.GetWindowRect(m.HWnd, ref r); Rectangle rc = new Rectangle(0, 0, r.Width, r.Height); using (BufferedBitmap bb = new BufferedBitmap(hdc, rc)) { m_Parent.PaintHeaderBackground(bb.Graphics, rc); IList columns = m_Parent.GetOrderedColumnList(); int x = 0; foreach (ColumnHeader h in columns) { Rectangle hr = new Rectangle(x, 0, h.Width, r.Height); ListViewItemStates state = ListViewItemStates.ShowKeyboardCues; if (m_MouseDown && hr.Contains(m_MouseDownPoint)) { Rectangle rt = hr; rt.Inflate(-6, 0); if (rt.Contains(m_MouseDownPoint)) state |= ListViewItemStates.Selected; } m_Parent.DrawColumnHeaderInternal(new DrawListViewColumnHeaderEventArgs(bb.Graphics, hr, h.DisplayIndex, h, state, SystemColors.ControlText, Color.Empty, m_Parent.ColumnHeaderFont ?? m_Parent.Font)); x += h.Width; } bb.Render(g); } } finally { g.Dispose(); } } finally { WinApi.EndPaint(m.HWnd, ref ps); } return; } else if (m.Msg == (int)WinApi.WindowsMessages.WM_LBUTTONDOWN) { if (m_Parent.HeaderStyle == ColumnHeaderStyle.Clickable) { m_MouseDown = true; m_MouseDownPoint = new Point(WinApi.LOWORD(m.LParam), WinApi.HIWORD(m.LParam)); WinApi.RedrawWindow(m.HWnd, IntPtr.Zero, IntPtr.Zero, WinApi.RedrawWindowFlags.RDW_INVALIDATE); } } else if (m.Msg == (int)WinApi.WindowsMessages.WM_LBUTTONUP) { m_MouseDown = false; m_MouseDownPoint = Point.Empty; } else if (m.Msg == (int)WinApi.WindowsMessages.WM_MOUSEMOVE && m_MouseDown) { m_MouseDownPoint = new Point(WinApi.LOWORD(m.LParam), WinApi.HIWORD(m.LParam)); } base.WndProc(ref m); }