public void LoadExample(DemoBase demoBase) { _gfxViewRoot.MakeCurrent(); GLPainterCore pcx = _gfxViewRoot.GLPainterCore(); GLPainter glPainter = _gfxViewRoot.GetGLPainter(); pcx.SmoothMode = SmoothMode.Smooth;//set anti-alias //create text printer for opengl demoBase.Init(); _demoBase = demoBase; _demoUI = new DemoUI(demoBase, _myWidth, _myHeight); _demoUI.SetCanvasPainter(pcx, glPainter); //----------------------------------------------- //demoBase.SetEssentialGLHandlers( // () => _glControl.SwapBuffers(), // () => _glControl.GetEglDisplay(), // () => _glControl.GetEglSurface() //); //----------------------------------------------- DemoBase.InvokeGLPainterReady(demoBase, pcx, glPainter); //Add to RenderTree _rootGfx.AddChild(_demoUI.GetPrimaryRenderElement()); }
static DemoBase InitDemo(ExampleAndDesc exampleAndDesc) { DemoBase exBase = Activator.CreateInstance(exampleAndDesc.Type) as DemoBase; if (exBase == null) { return(null); } exBase.Init(); return(exBase); }
public void LoadExample(ExampleAndDesc exAndDesc) { DemoBase exBase = Activator.CreateInstance(exAndDesc.Type) as DemoBase; if (exBase == null) { return; } this.Text = exAndDesc.ToString(); //---------------------------------------------------------------------------- this.exampleBase = exBase; exampleBase.Init(); }
void listBox1_DoubleClick(object sender, EventArgs e) { //load sample form ExampleAndDesc exAndDesc = this.listBox1.SelectedItem as ExampleAndDesc; if (exAndDesc != null) { DemoBase exBase = Activator.CreateInstance(exAndDesc.Type) as DemoBase; if (exBase == null) { return; } exBase.Init(); //FormTestBed1 testBed = new FormTestBed1(); //testBed.WindowState = FormWindowState.Maximized; //testBed.Show(); //testBed.LoadExample(exAndDesc); } }
public void LoadExample(DemoBase demoBase) { _glControl.MakeCurrent(); _demoBase = demoBase; demoBase.Init(); if (WithGdiPlusDrawBoard) { _bridgeUI = new GdiOnGLESUIElement(_myWidth, _myHeight); } else { //pure agg's cpu blit _bridgeUI = new CpuBlitGLESUIElement(_myWidth, _myHeight); } // _bridgeUI.SetUpdateCpuBlitSurfaceDelegate((p, updateArea) => _demoBase.Draw(p)); DemoBase.InvokePainterReady(_demoBase, _bridgeUI.GetAggPainter()); // //use existing GLRenderSurface and GLPainter //see=>UISurfaceViewportControl.InitRootGraphics() GLPainterContext pcx = _surfaceViewport.GetGLRenderSurface(); GLPainter glPainter = _surfaceViewport.GetGLPainter(); _bridgeUI.CreatePrimaryRenderElement(pcx, glPainter, _rootGfx); //----------------------------------------------- demoBase.SetEssentialGLHandlers( () => _glControl.SwapBuffers(), () => _glControl.GetEglDisplay(), () => _glControl.GetEglSurface() ); //----------------------------------------------- DemoBase.InvokeGLPainterReady(demoBase, pcx, glPainter); //Add to RenderTree _rootGfx.AddChild(_bridgeUI.GetPrimaryRenderElement(_rootGfx)); //----------------------------------------------- //*** GeneralEventListener genEvListener = new GeneralEventListener(); genEvListener.MouseDown += e => { _demoBase.MouseDown(e.X, e.Y, e.Button == UIMouseButtons.Right); _bridgeUI.InvalidateGraphics(); }; genEvListener.MouseMove += e => { if (e.IsDragging) { _bridgeUI.InvalidateGraphics(); _demoBase.MouseDrag(e.X, e.Y); _bridgeUI.InvalidateGraphics(); } }; genEvListener.MouseUp += e => { _demoBase.MouseUp(e.X, e.Y); }; //----------------------------------------------- _bridgeUI.AttachExternalEventListener(genEvListener); }
public void LoadExample(ExampleAndDesc exAndDesc) { DemoBase exBase = Activator.CreateInstance(exAndDesc.Type) as DemoBase; if (exBase == null) { return; } this.exampleBase = exBase; exampleBase.Init(); this.softAggControl2.LoadExample(exampleBase); this.Text = exAndDesc.ToString(); //------------------------------------------- //description: if (!string.IsNullOrEmpty(exAndDesc.Description)) { TextBox tt = new TextBox(); tt.Width = this.flowLayoutPanel1.Width - 5; tt.Text = exAndDesc.Description; tt.Multiline = true; tt.ScrollBars = ScrollBars.Vertical; tt.Height = 250; tt.BackColor = Color.Gainsboro; tt.Font = new Font("tahoma", 10); this.flowLayoutPanel1.Controls.Add(tt); } //------------------------------------------- this.configList = exAndDesc.GetConfigList(); if (configList != null) { int j = configList.Count; for (int i = 0; i < j; ++i) { ExampleConfigDesc config = configList[i]; switch (config.PresentaionHint) { case DemoConfigPresentaionHint.CheckBox: { CheckBox checkBox = new CheckBox(); checkBox.Text = config.Name; checkBox.Width = 400; bool currentValue = (bool)config.InvokeGet(exampleBase); checkBox.Checked = currentValue; checkBox.CheckedChanged += (s, e) => { config.InvokeSet(exBase, checkBox.Checked); InvalidateSampleViewPort(); }; this.flowLayoutPanel1.Controls.Add(checkBox); } break; case DemoConfigPresentaionHint.SlideBarDiscrete: { Label descLabel = new Label(); descLabel.Width = 400; this.flowLayoutPanel1.Controls.Add(descLabel); var originalConfig = config.OriginalConfigAttribute; HScrollBar hscrollBar = new HScrollBar(); hscrollBar.Width = flowLayoutPanel1.Width; hscrollBar.Minimum = originalConfig.MinValue; hscrollBar.Maximum = originalConfig.MaxValue + 10; hscrollBar.SmallChange = 1; //current value int value = (int)config.InvokeGet(exampleBase); hscrollBar.Value = value; //------------- descLabel.Text = config.Name + ":" + hscrollBar.Value; hscrollBar.ValueChanged += (s, e) => { config.InvokeSet(exampleBase, hscrollBar.Value); descLabel.Text = config.Name + ":" + hscrollBar.Value; InvalidateSampleViewPort(); }; this.flowLayoutPanel1.Controls.Add(hscrollBar); } break; case DemoConfigPresentaionHint.SlideBarContinuous_R4: { Label descLabel = new Label(); descLabel.Width = 400; this.flowLayoutPanel1.Controls.Add(descLabel); var originalConfig = config.OriginalConfigAttribute; HScrollBar hscrollBar = new HScrollBar(); //100 => for scale factor hscrollBar.Width = flowLayoutPanel1.Width; hscrollBar.Minimum = originalConfig.MinValue * 100; hscrollBar.Maximum = (originalConfig.MaxValue * 100) + 10; hscrollBar.SmallChange = 1; //current value float doubleValue = ((float)config.InvokeGet(exampleBase) * 100); hscrollBar.Value = (int)doubleValue; //------------- descLabel.Text = config.Name + ":" + ((float)hscrollBar.Value / 100d).ToString(); hscrollBar.ValueChanged += (s, e) => { float value = (float)(hscrollBar.Value / 100f); config.InvokeSet(exampleBase, value); descLabel.Text = config.Name + ":" + value.ToString(); InvalidateSampleViewPort(); }; this.flowLayoutPanel1.Controls.Add(hscrollBar); } break; case DemoConfigPresentaionHint.SlideBarContinuous_R8: { Label descLabel = new Label(); descLabel.Width = 400; this.flowLayoutPanel1.Controls.Add(descLabel); var originalConfig = config.OriginalConfigAttribute; HScrollBar hscrollBar = new HScrollBar(); //100 => for scale factor hscrollBar.Width = flowLayoutPanel1.Width; hscrollBar.Minimum = originalConfig.MinValue * 100; hscrollBar.Maximum = (originalConfig.MaxValue * 100) + 10; hscrollBar.SmallChange = 1; //current value double doubleValue = ((double)config.InvokeGet(exampleBase) * 100); hscrollBar.Value = (int)doubleValue; //------------- descLabel.Text = config.Name + ":" + ((double)hscrollBar.Value / 100d).ToString(); hscrollBar.ValueChanged += (s, e) => { double value = (double)hscrollBar.Value / 100d; config.InvokeSet(exampleBase, value); descLabel.Text = config.Name + ":" + value.ToString(); InvalidateSampleViewPort(); }; this.flowLayoutPanel1.Controls.Add(hscrollBar); } break; case DemoConfigPresentaionHint.OptionBoxes: { List <ExampleConfigValue> optionFields = config.GetOptionFields(); FlowLayoutPanel panelOption = new FlowLayoutPanel(); int totalHeight = 0; int m = optionFields.Count; //current value int currentValue = (int)config.InvokeGet(exampleBase); for (int n = 0; n < m; ++n) { ExampleConfigValue ofield = optionFields[n]; RadioButton radio = new RadioButton(); panelOption.Controls.Add(radio); radio.Text = ofield.Name; radio.Width = 400; radio.Checked = ofield.ValueAsInt32 == currentValue; radio.Click += (s, e) => { if (radio.Checked) { ofield.InvokeSet(this.exampleBase); InvalidateSampleViewPort(); } }; totalHeight += radio.Height + 10; } panelOption.Height = totalHeight; panelOption.FlowDirection = FlowDirection.TopDown; this.flowLayoutPanel1.Controls.Add(panelOption); } break; case DemoConfigPresentaionHint.TextBox: { Label descLabel = new Label(); descLabel.Width = 400; descLabel.Text = config.Name; this.flowLayoutPanel1.Controls.Add(descLabel); TextBox textBox = new TextBox(); textBox.Width = 400; this.flowLayoutPanel1.Controls.Add(textBox); } break; } } } }
public void LoadSample(DemoBase demobase) { this.demobase = demobase; //1. //note:when we init, //no glcanvas/ painter are created demobase.Init(); //----------------------------------------------- //2. check if demo will create canvas/painter context //or let this GLDemoContext create for it hh1 = glControl.Handle; //ensure that contrl handler is created glControl.MakeCurrent(); demobase.BuildCustomDemoGLContext(out this._glsx, out this.canvasPainter); // if (this._glsx == null) { //if demo not create canvas and painter //the we create for it int max = Math.Max(glControl.Width, glControl.Height); _glsx = PixelFarm.Drawing.GLES2.GLES2Platform.CreateGLRenderSurface(max, max, glControl.Width, glControl.Height); _glsx.SmoothMode = SmoothMode.Smooth;//set anti-alias canvasPainter = new GLPainter(_glsx); //create text printer for opengl //---------------------- //1. win gdi based //var printer = new WinGdiFontPrinter(_glsx, glControl.Width, glControl.Height); //canvasPainter.TextPrinter = printer; //---------------------- //2. raw vxs //var openFontStore = new Typography.TextServices.OpenFontStore(); //var printer = new PixelFarm.Drawing.Fonts.VxsTextPrinter(canvasPainter,openFontStore); //canvasPainter.TextPrinter = printer; //---------------------- //3. agg texture based font texture //var printer = new AggTextSpanPrinter(canvasPainter, glControl.Width, 30); //canvasPainter.TextPrinter = printer; //---------------------- //4. texture atlas based font texture //------------ //resolve request font var printer = new GLBitmapGlyphTextPrinter(canvasPainter, PixelFarm.Drawing.GLES2.GLES2Platform.TextService); canvasPainter.TextPrinter = printer; //var openFontStore = new Typography.TextServices.OpenFontStore(); //var printer = new GLBmpGlyphTextPrinter(canvasPainter, openFontStore); //canvasPainter.TextPrinter = printer; } //----------------------------------------------- demobase.SetEssentialGLHandlers( () => this.glControl.SwapBuffers(), () => this.glControl.GetEglDisplay(), () => this.glControl.GetEglSurface() ); //----------------------------------------------- this.glControl.SetGLPaintHandler((s, e) => { demobase.InvokeGLPaint(); }); DemoBase.InvokeGLContextReady(demobase, this._glsx, this.canvasPainter); DemoBase.InvokePainterReady(demobase, this.canvasPainter); }