//============================================================ // <T>合并压缩。</T> // // @autor DYWEN 20120712 //============================================================ public void tsbShowImage_Click(object sender, EventArgs e) { GetRectangle(); SIntPoint2 sintp2 = GetAllRectangle(maxW, maxH); Bitmap _bitmap = new Bitmap(sintp2.X, sintp2.Y); FRsResourceClip rcl = _resourceAnimation.FristClip; Graphics g = Graphics.FromImage(_bitmap); for (int i = 0; i < rcl.FrameCount; i++) { Bitmap bmn = rcl.Frames.Items[i].Bitmap.Native; _fCutBitmap = new FBitmap(bmn); SIntRectangle rct = _fCutBitmap.TestValidRectangle(1); Bitmap p = bmn.Clone(new Rectangle(rct.Left, rct.Top, rct.Width, rct.Height), PixelFormat.Format32bppArgb); // 防止图片缩放问题 g.DrawImage(p, i * maxW, 0, p.Width, p.Height); } QDsResourceViewForm sci = new QDsResourceViewForm(); foreach (Control item in sci.Controls) { if (item is PictureBox) { PictureBox picbox = item as PictureBox; picbox.Width = _bitmap.Width; picbox.Height = _bitmap.Height; picbox.BackgroundImage = _bitmap; } } String mapInfo = "宽:" + _bitmap.Width + " " + "高:" + _bitmap.Height; sci.Text = mapInfo; g.Dispose(); sci.Show(); }
//============================================================ // <T>根据坐标找到出生点。</T> //============================================================ public FMbMapBirth FindByLocation(SIntPoint2 point) { foreach (FMbMapBirth birth in _births) { SIntPoint2 location = birth.Location; if (point.ToString() == location.ToString()) { return birth; } } return null; }
//============================================================ // <T>获取合并以后资源的大小</T> // // @autor DYWEN 20120816 //============================================================ public SIntPoint2 GetAllRectangle(int maxW, int maxH) { SIntPoint2 sintp = new SIntPoint2(); FRsResourceClip rcl = _resourceAnimation.FristClip; int count = rcl.FrameCount; sintp.X = count * maxW; sintp.Y = maxH; return(sintp); }
//============================================================ // <T>结束绘制处理。</T> // // @param args 参数 //============================================================ public virtual bool OnTest(SUiTestArgs args) { float scale = _context.Scale; SIntPoint2 position = CalculateDisplayPosition(); bool test = RRectangle.ConstainsPoint(position.X, position.Y, (int)(ControlResource.Size.Width * scale), (int)(ControlResource.Size.Height * scale), args.Point.X, args.Point.Y); if (test) { args.Push(this); } return(test); }
//============================================================ // <T>加载配置文件。</T> //============================================================ public void LoadConfig(FXmlNode config) { if (config.Contains("cell_count")) { _cellCount.Parse(config.Get("cell_count")); } if (config.Contains("cell_size")) { _cellSize.Parse(config.Get("cell_size")); } if (config.Contains("type_cd")) { _typeCd = REnum.ToValue <EMapLayerType>(config.Get("type_cd")); } if (config.Contains("scroll_cd")) { _scrollCd = REnum.ToValue <EMapLayerScroll>(config.Get("scroll_cd")); } if (config.Contains("wrap_cd")) { _wrapCd = REnum.ToValue <EMapLayerWrap>(config.Get("wrap_cd")); } if (config.Contains("scroll_speed")) { _scrollSpeed = config.GetFloat("scroll_speed"); } _tileNode = config.Find("Tiles"); if (null == _tileNode) { return; } // 创建所有格子 for (int m = 0; m < _cellCount.Height; m++) { for (int n = 0; n < _cellCount.Width; n++) { FMbMapCell cell = new FMbMapCell(); cell.Index = new SIntPoint2(n, m); _mapCell.Push(cell); } } // 加载格子资源图片编号 foreach (FXmlNode cellNode in _tileNode.Nodes) { FDsMapCell cell = new FDsMapCell(); cell.Resource.LoadConfig(cellNode); SIntPoint2 cellIndex = cell.Resource.Index; FMbMapCell c = FingCellByIndex(cellIndex.X, cellIndex.Y); c.ResourceId = cell.Resource.ResourceId; } }
//============================================================ // <T>绘制处理。</T> // // @param args 参数 //============================================================ public override void Draw(SUiDrawArgs args) { // 设置数据 bool visible = TestVisible(); SIntPoint2 position = CalculatePosition(); args.Position.Assign(position); // 计算数据 _designLocation.Assign(CalculateDisplayPosition()); _designSize.Assign(CalculateDisplaySize()); // 开始层处理 _deviceLayer.Begin(_designLocation.X, _designLocation.Y, _designSize.Width, _designSize.Height); // 检查可见性 if (visible) { OnDrawBegin(args); } //............................................................ // 子控件测试 if (_activePage != null) { // 绘制分页 _activePage.Draw(args); // 绘制节点 if (_components != null) { foreach (FUiComponent componment in _components) { FUiControl control = componment as FUiControl; if (control == null) { continue; } if (control is FUiPage) { continue; } control.Draw(args); } } } //............................................................ // 结束绘制 if (visible) { _context.Context.TransformLocation(_designLocation.X, _designLocation.Y); OnDrawAfter(args); } // 结束层处理 _deviceLayer.End(); }
//============================================================ public SIntPoint2 CheckPoints(int x, int y) { SIntPoint2 point = new SIntPoint2(); int left = qdsProperty.PicLeft; int top = qdsProperty.PicTop; int width = qdsProperty.PicWidth; int height = qdsProperty.PicHeight; int centerX = Math.Abs(_currentClip.ValidBarycenter.X); int centerY = Math.Abs(_currentClip.ValidBarycenter.Y); int pointX = left + centerX; int pointY = top + centerY; point.X = x - pointX; point.Y = y - pointY; return(point); }
//============================================================ // <T>绘制处理。</T> // // @param args 参数 //============================================================ public virtual void Draw(SUiDrawArgs args) { // 检查有效性 if (!ComponentResource.OptionValid) { return; } // 设置数据 bool visible = TestVisible(); SIntPoint2 position = CalculatePosition(); args.Position.Assign(position); // 计算数据 _designLocation.Assign(CalculateDisplayPosition()); _designSize.Assign(CalculateDisplaySize()); // 开始层处理 _deviceLayer.Begin(_designLocation.X, _designLocation.Y, _designSize.Width, _designSize.Height); // 检查可见性 if (visible) { OnDrawBegin(args); } //............................................................ // 子控件测试 if (_components != null) { foreach (FUiComponent componment in _components) { FUiControl control = componment as FUiControl; if (control != null) { control.Draw(args); } } } //............................................................ // 结束绘制 if (visible) { _context.Context.TransformLocation(_designLocation.X, _designLocation.Y); OnDrawAfter(args); } // 结束层处理 _deviceLayer.End(); }
//============================================================ private void qdsProperty_OnControlMouseClick(object sender, MouseEventArgs e) { qdsProperty.IsMain = true; string center = btnSetCenter.Tag as string; string blood = btnBlood.Tag as string; string ride = btnSetRidePoint.Tag as string; if (center.Equals("1")) { SIntPoint2 point = CheckPoints(e.X, e.Y); int newx = point.X; int newy = point.Y; qdsProperty.Barycenter.Set(newx, newy); _currentClip.ValidBarycenter.X = newx; _currentClip.ValidBarycenter.Y = newy; txtbaryCenterX.Text = newx.ToString(); txtbaryCenterY.Text = newy.ToString(); } if (blood.Equals("1")) { SIntPoint2 point = CheckPoints(e.X, e.Y); int newx = point.X; int newy = point.Y; qdsProperty.Blood.Set(newx, newy); _currentClip.Blood.X = newx; _currentClip.Blood.Y = newy; BloodX.Text = newx.ToString(); BloodY.Text = newy.ToString(); } if (ride.Equals("1")) { SIntPoint2 point = CheckPoints(e.X, e.Y); int newx = point.X; int newy = point.Y; qdsProperty.RidePoint.Set(newx, newy); _currentClip.RidePoint.X = newx; _currentClip.RidePoint.Y = newy; txtRidePointX.Text = newx.ToString(); txtRidePointY.Text = newy.ToString(); } }
public FMbMapCell Find(int x, int y) { // 判断格子大小 if (0 == _resource.CellSize.Width || 0 == _resource.CellSize.Height) { return(null); } // 获取格子索引 int indexX = x / _resource.CellSize.Width; int indexY = y / _resource.CellSize.Height; foreach (FMbMapCell cell in _resource.MapCell) { SIntPoint2 cellIndex = cell.Index; if (indexX == cellIndex.X && indexY == cellIndex.Y) { return(cell); } } return(null); }
//============================================================ // <T>绘制出生点。</T> //============================================================ public void DrawBirths() { FObjects <FMbMapBirth> births = _map.Births; if (!births.IsEmpty()) { int count = births.Count; for (int n = 0; n < count; n++) { FMbMapBirth birth = births[n]; SIntPoint2 location = birth.Location; // 获取敌机集合 FObjects <FMbMapBirthEnemy> enemys = birth.BirthEnemys; int enemyCount = enemys.Count; for (int x = 0; x < enemyCount; x++) { FMbMapBirthEnemy birthEnemy = enemys[x]; int templateId = birthEnemy.TemplateId; FMbTplEnemy enemy = RMobileManager.TemplateConsole.EnemyConsole.FingById(templateId); int resourceRid = enemy.ResourceRid; // 获取资源图片 FRsResourcePicture resource = RContent2dManager.ResourceConsole.FindOpen(resourceRid) as FRsResourcePicture; Bitmap resourceMap = resource.Bitmap.Native; // 创建绘制对象 FDxBitmap bitmap = null; if (!_dxBitmapSet.Contains(resourceRid.ToString())) { bitmap = _context.Device.CreateBitmap(resourceMap); _dxBitmapSet.Set(resourceRid.ToString(), bitmap); } else { bitmap = _dxBitmapSet.Get(resourceRid.ToString()); } _context.DrawBitmap(bitmap, location.X - _location.X, location.Y - _location.Y); } } } }
//============================================================ // <T>绘制层。</T> //============================================================ public void DrawLayers() { FObjects <FMbMapLayer> layers = _map.Layers; if (!layers.IsEmpty()) { int count = layers.Count; for (int n = 0; n < count; n++) { FMbMapLayer layer = layers[n]; if (layer.OptionValid) { _cellSize = layer.CellSize; _cellCount = layer.CellCount; FObjects <FMbMapCell> cells = layer.MapCell; int cellCount = cells.Count; for (int x = 0; x < cellCount; x++) { FMbMapCell cell = cells[x]; int resourceId = cell.ResourceId; if (0 == resourceId) { continue; } SIntPoint2 cellIndex = cell.Index; FMbMapTile mapTile = RMobileManager.MapTileConsole.FindMapTile(resourceId); if (null != mapTile) { DrawMapTile(mapTile, cellIndex); } } } // 绘制方格 DrawLine(); } } }
//============================================================ // <T>加载出生点列表。</T> //============================================================ public void InnerBuildBirth() { int index = 0; // 清空 tvwCatalog.Nodes.Clear(); foreach (FMbMapBirth birth in _map.Resource.Births) { SIntPoint2 location = birth.Location; TreeNode birthNode = new TreeNode(); birthNode.Tag = birth; birthNode.Text = "出生点" + (++index) + ":" + location.ToString(); foreach (FMbMapBirthEnemy enemy in birth.BirthEnemys) { TreeNode enemyNode = new TreeNode(); enemyNode.Tag = enemy; enemyNode.Text = "模版编号:" + enemy.TemplateId; birthNode.Nodes.Add(enemyNode); } tvwCatalog.Nodes.Add(birthNode); } tvwCatalog.ExpandAll(); }
//============================================================ // <T>绘制瓦片。</T> //============================================================ public void DrawMapTile(FMbMapTile mapTile, SIntPoint2 cellIndex) { Bitmap bm = mapTile.Resource; int cellIndexX = cellIndex.X; int cellIndexY = cellIndex.Y; int cellLocationX = cellIndexX * _cellSize.Width; int cellLocationY = cellIndexY * _cellSize.Height; FDxBitmap bitmap = null; // 创建图片资源 if (!_dxBitmapSet.Contains(mapTile.Id.ToString())) { bitmap = _context.Device.CreateBitmap(mapTile.Resource); _dxBitmapSet.Set(mapTile.Id.ToString(), bitmap); } else { bitmap = _dxBitmapSet.Get(mapTile.Id.ToString()); } _context.DrawBitmap(bitmap, cellLocationX - _location.X, cellLocationY - _location.Y); }
//============================================================ // <T>绘制处理。</T> // // @param sender 发送者 // @param e:event 事件 //============================================================ public void DrawPreviewLayers() { if (!_designLayers) { return; } FUiControlLayers layers = _designFrame.PreviewLayers; if (!layers.IsEmpty()) { float scale = _context.Scale; FDxContext2d context = _context.Context; SIntPoint2 position = _designFrame.CalculateDisplayPosition(); int count = layers.Count; for (int n = count - 1; n >= 0; n--) { FUiControlLayer layer = layers[n]; if (layer.OptionVisible) { context.DrawBitmap(layer.Bitmap, position.X, position.Y, (int)(layer.Size.Width * scale), (int)(layer.Size.Height * scale), 1.0f); } } } }
//============================================================ // <T>绘制矩形。</T> // // @param brush 色刷 // @param location 位置 // @param size 大小 //============================================================ public void DrawRectangle(FDxBrush brush, SIntPoint2 location, SIntSize2 size) { _target.DrawRectangle(brush.Native, new Rectangle(location.X, location.Y, size.Width, size.Height)); }
//============================================================ // <T>指定复制位图的指定通道到目标位图。<T> // // @param source 来源位图 // @param sourceRectangle 来源矩形 // @param target 目标位图 // @param targetPosition 目标位置 //============================================================ public static void Copy(Bitmap source, SIntRectangle sourceRectangle, Bitmap target, SIntPoint2 targetPosition) { int lineSize = sourceRectangle.Width; int height = sourceRectangle.Height; int[] buffer = new int[lineSize]; // 获得来源内存 BitmapData sourceData = source.LockBits(new Rectangle(sourceRectangle.Left, sourceRectangle.Top, sourceRectangle.Width, sourceRectangle.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); long sourcePtr = sourceData.Scan0.ToInt64(); // 获得目标内存 BitmapData targetData = target.LockBits(new Rectangle(targetPosition.X, targetPosition.Y, sourceRectangle.Width, sourceRectangle.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); long targetPtr = targetData.Scan0.ToInt64(); // 复制数据 for (int row = 0; row < height; row++) { // 读取源信息 Marshal.Copy(new IntPtr(sourcePtr), buffer, 0, lineSize); sourcePtr += sourceData.Stride; // 读取目标源信息 Marshal.Copy(buffer, 0, new IntPtr(targetPtr), lineSize); targetPtr += targetData.Stride; } // 释放资源 source.UnlockBits(sourceData); target.UnlockBits(targetData); }
//============================================================ // <T>绘制辅助线。</T> //============================================================ public bool DrawAidLines() { // 检查状态 FUiControl focusControl = _selection.FocusControl; if (focusControl == null) { return(false); } FUiControl parent = focusControl.Parent as FUiControl; if (parent == null) { return(false); } // 获得环境 float scale = _context.Scale; FDxContext2d context = _context.Context; context.TransformIdentity(); // 绘制对齐线 SIntPoint2 location = focusControl.CalculateDisplayPosition(); SIntSize2 size = focusControl.CalculateDisplaySize(); foreach (FUiComponent component in parent.Components) { FUiControl control = component as FUiControl; // 检查变量 if (control == null) { continue; } if (control == focusControl) { continue; } // 计算坐标 SIntPoint2 findLocation = control.CalculateDisplayPosition(); SIntSize2 findSize = control.CalculateDisplaySize(); // 左辅助线 if (location.X == findLocation.X) { context.DrawLineLayer(location.X, 0, location.X, _size.Height, _lineBackBrush, _lineForeBrush, _lineWidth, _lineForeStrokeStyle); } // 上辅助线 if (location.Y == findLocation.Y) { context.DrawLineLayer(0, location.Y, _size.Width, location.Y, _lineBackBrush, _lineForeBrush, _lineWidth, _lineForeStrokeStyle); } // 右辅助线 int right = findLocation.X + findSize.Width; if (location.X + size.Width == right) { context.DrawLineLayer(right, 0, right, _size.Height, _lineBackBrush, _lineForeBrush, _lineWidth, _lineForeStrokeStyle); } // 下辅助线 int bottom = findLocation.Y + findSize.Height; if (location.Y + size.Height == bottom) { context.DrawLineLayer(0, bottom, _size.Width, bottom, _lineBackBrush, _lineForeBrush, _lineWidth, _lineForeStrokeStyle); } } return(true); }
//============================================================ // <T>打开资源。</T> //============================================================ public override void Open() { if (!_opened) { base.Open(); foreach (FRsResourceClip clip in _clips) { if (null != clip) { if (0 != clip.FrameCount) { clip.Open(); } } } // 中心点 SIntPoint2 center = new SIntPoint2(); foreach (FRsResourceClip clip in _clips) { if (null != clip) { center.X = clip.Frames[0].Size.Width / 2; center.Y = clip.Frames[0].Size.Height / 2; break; } } // 计算边界 int left = int.MaxValue; int top = int.MaxValue; int right = 0; int bottom = 0; foreach (FRsResourceClip clip in _clips) { if (null != clip && !clip.ValidRectangle.IsEmpty) { // 未反转过的边界 SIntRectangle rect = clip.ValidRectangle; if (rect.Left < left) { left = rect.Left; } if (rect.Top < top) { top = rect.Top; } if (rect.Right > right) { right = rect.Right; } if (rect.Bottom > bottom) { bottom = rect.Bottom; } } } int reverseLeft = center.X * 2 - right; int reverseRight = center.X * 2 - left; if (reverseLeft < left) { left = reverseLeft; } if (reverseRight > right) { right = reverseRight; } _size.Width = right - left; _size.Height = bottom - top; foreach (FRsResourceClip clip in _clips) { if (null != clip) { _validBarycenter.X = center.X - left; _validBarycenter.Y = center.Y - top; break; } } } _opened = true; }
//============================================================ // <T>填充矩形。</T> // // @param brush 色刷 // @param location 位置 // @param size 大小 //============================================================ public void FillRectangle(FDxBrush brush, SIntPoint2 location, SIntSize2 size) { _device.Target.FillRectangle(brush.Native, new Rectangle(location.X, location.Y, size.Width, size.Height)); }
//============================================================ // <T>绘制处理。</T> // // @param args 参数 //============================================================ public override void Draw(SUiDrawArgs args) { // 检查有效性 if (!ComponentResource.OptionValid) { return; } // 设置数据 bool visible = TestVisible(); SIntPoint2 position = CalculatePosition(); args.Position.Assign(position); // 计算数据 _designLocation.Assign(CalculateDisplayPosition()); _designSize.Assign(CalculateDisplaySize()); // 开始层处理 _deviceLayer.Begin(_designLocation.X, _designLocation.Y, _designSize.Width, _designSize.Height); // 检查可见性 if (visible) { OnDrawBegin(args); } //............................................................ // 子控件绘制 if (_components != null) { // 绘制分页 FUiScrollItem item = ActiveItem(); if (item != null) { ERcSpread spreadCd = ScrollViewResource.SpreadCd; // 绘制多个 int itemWidth = item.Size.Width + _horizontalSpace; int itemHeight = item.Size.Height + _verticalSpace; if ((spreadCd == ERcSpread.Horizontal) && (_verticalCount > 0)) { for (int n = 0; n < _designItemCount; n++) { int cx = n % _verticalCount; int cy = (int)(n / _verticalCount); item.Location.Set(itemWidth * cx, itemHeight * cy); item.Draw(args); } } else if ((spreadCd == ERcSpread.Vertical) && (_horizontalCount > 0)) { for (int n = 0; n < _designItemCount; n++) { int cx = n % _horizontalCount; int cy = (int)(n / _horizontalCount); item.Location.Set(itemWidth * cx, itemHeight * cy); item.Draw(args); } } // 恢复设置 item.Location.Set(0, 0); } // 绘制节点 foreach (FUiComponent componment in _components) { FUiControl control = componment as FUiControl; if (control == null) { continue; } if (control is FUiScrollItem) { continue; } control.Draw(args); } } //............................................................ // 结束绘制 if (visible) { _context.Context.TransformLocation(_designLocation.X, _designLocation.Y); OnDrawAfter(args); } // 结束层处理 _deviceLayer.End(); }