private void MouseOnRect(RectInfo rectInfo, ref Pen pen, int i) { int x = rectInfo.x + formX; int y = rectInfo.y + formY; int w = rectInfo.w; mouseX = Cursor.Position.X; mouseY = Cursor.Position.Y; if (mouseX >= x && mouseX <= x + w && mouseY >= y && mouseY <= y + w) { pen = new Pen(Color.FromArgb(115, 55, 55, 255), 3); if (Control.MouseButtons == MouseButtons.Left) { String name; FSDK.GetAllNames(tracker, IDs[i], out name, 65536); if (name != "") { friendcognition.Profile profile = new friendcognition.Profile(Convert.ToInt32(name)); profile.Show(); } else { MessageBox.Show("User not registered", "", MessageBoxButtons.OK); } } } }
public void OnDrag(Vector2 delta, Vector2 mousePos) { if (RectInfo.Contains(mousePos)) { // _cursorOffsetX += (int) delta.x; } if (_cursorOffsetX > RectInfo.width) { _cursorOffsetX = (int)RectInfo.width; // _minOffsetX += (int) delta.x; _autoMove = _autoMoveSpeed; } else if (_cursorOffsetX < 0) { _cursorOffsetX = 0; _autoMove = -_autoMoveSpeed; } else { _autoMove = 0; _cursorOffsetX = (int)(mousePos.x - RectInfo.xMin + _timeInvert * 0.5f); } }
public RectInfo GetClone() { RectInfo dest = new RectInfo(); dest.XPos = this.XPos; dest.YPos = this.YPos; dest.WinW = this.WinW; dest.WinH = this.WinH; dest.WinColorR = this.WinColorR; dest.WinColorG = this.WinColorG; dest.WinColorB = this.WinColorB; dest.MostTop = this.MostTop; dest.MovableFlag = this.MovableFlag; dest.ImageFile = this.ImageFile; dest.ImageStretchFlag = this.ImageStretchFlag; dest.Text = this.Text; dest.TextAlign = this.TextAlign; dest.TextFont = this.TextFont; dest.TextSize = this.TextSize; dest.TextColorR = this.TextColorR; dest.TextColorG = this.TextColorG; dest.TextColorB = this.TextColorB; dest.透明度Pct = this.透明度Pct; // RectInfo.* return(dest); }
public object Create(object parent, object configContext, XmlNode section) { try { XmlNodeList rectNodes = section.SelectNodes("rect"); if (rectNodes != null) { foreach (XmlNode rectNode in rectNodes) { RectInfo rectInfo = new RectInfo(); string colorStr = rectNode.Attributes["color"].Value; if (!colorStr.StartsWith("#")) { colorStr = "#" + colorStr; } rectInfo.Color = (Color)ColorConverter.ConvertFromString(colorStr); string pos = rectNode.Attributes["pos"].Value; string[] posParts = pos.Split(',', ';'); rectInfo.X = int.Parse(posParts[0].Trim()); rectInfo.Y = int.Parse(posParts[1].Trim()); rectInfo.Width = int.Parse(posParts[2].Trim()); rectInfo.Height = int.Parse(posParts[3].Trim()); Rects.Add(rectInfo); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } return(null); }
public bool GetSFRValue(Bitmap bmp, ref SFRValue SFRValue, ref RectInfo rectInfo, Rectangle[] rectangles, ref LightValue lightValue, bool TestLight = false) { if (!bLoad) { return(false); } AlgorithmBase tempModuleBase = GetAlgByIndexID(); if (tempModuleBase != null) { bool result = tempModuleBase.GetSFRValue(bmp, ref SFRValue, ref rectInfo, rectangles, ref lightValue, TestLight); if (SFRValue != null) { for (int i = 0; i < SFRValue.block.Length; i++) { if (SFRValue.block[i].dValue > ParamSetMgr.GetInstance().GetDoubleParam("SFR最大值")) { SFRValue.block[i].dValue = -1; } } } return(result); } else { return(false); } }
public static RectInfo Collimator_Info2Rect(SFR_C_Info info) { int x = info.block.Count(); RectInfo result = new RectInfo(); result.Points = new Point[x][]; result.Points[0] = new Point[1] { new Point { X = (int)info.block[4].dX, Y = (int)info.block[4].dY } }; result.Points[1] = new Point[1] { new Point { X = (int)info.block[0].dX, Y = (int)info.block[0].dY } }; result.Points[2] = new Point[1] { new Point { X = (int)info.block[2].dX, Y = (int)info.block[2].dY } }; result.Points[3] = new Point[1] { new Point { X = (int)info.block[6].dX, Y = (int)info.block[6].dY } }; result.Points[4] = new Point[1] { new Point { X = (int)info.block[8].dX, Y = (int)info.block[8].dY } }; result.Points[5] = new Point[1] { new Point { X = (int)info.block[1].dX, Y = (int)info.block[1].dY } }; result.Points[6] = new Point[1] { new Point { X = (int)info.block[3].dX, Y = (int)info.block[3].dY } }; result.Points[7] = new Point[1] { new Point { X = (int)info.block[5].dX, Y = (int)info.block[5].dY } }; result.Points[8] = new Point[1] { new Point { X = (int)info.block[7].dX, Y = (int)info.block[7].dY } }; return(result); }
public void Update(FSDK.CImage image, Image frameImage, bool recogniseFacialFeatures) { FSDK.FeedFrame(tracker, 0, image.ImageHandle, ref faceCount, out IDs, sizeof(long) * 256); Array.Resize(ref IDs, (int)faceCount); Graphics graphics = Graphics.FromImage(frameImage); for (int i = 0; i < IDs.Length; ++i) { if (recogniseFacialFeatures == true) { FSDK.TPoint[] facialFeatures; FSDK.GetTrackerFacialFeatures(tracker, 0, IDs[i], out facialFeatures); foreach (FSDK.TPoint point in facialFeatures) { graphics.FillEllipse(Brushes.Blue, point.x, point.y, 5, 5); } } else { FSDK.TFacePosition facePosition = new FSDK.TFacePosition(); FSDK.GetTrackerFacePosition(tracker, 0, IDs[i], ref facePosition); int x = facePosition.xc - (int)(facePosition.w * 0.6); int y = facePosition.yc - (int)(facePosition.w * 0.6); int w = (int)(facePosition.w * 1.2); Pen pen = new Pen(Color.FromArgb(115, 115, 115, 115), 3); RectInfo currentRectInfo = new RectInfo(x, y, w); currentRectInfo = ProccessRectInfo(currentRectInfo, IDs[i]); /*String name; * int res = FSDK.GetAllNames(tracker, IDs[i], out name, 65536); * * if (FSDK.FSDKE_OK == res && name.Length > 0) * { * StringFormat format = new StringFormat(); * format.Alignment = StringAlignment.Center; * * graphics.DrawString(name, new System.Drawing.Font("Arial", 16), * new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen), * currentRectInfo.x + currentRectInfo.w / 2, currentRectInfo.y + currentRectInfo.w + 5, format); * }*/ pen = new Pen(Color.FromArgb(115, 115, 115, 115), 3); if (!CheckIfOpen()) { MouseOnRect(currentRectInfo, ref pen, i); } graphics.DrawRectangle(pen, currentRectInfo.x, currentRectInfo.y, currentRectInfo.w, currentRectInfo.w); } } }
public FlameData GetFlameData() { try { var data = GetData <FlameData>(); if (data == null) { data = new FlameData();//客户端靠这个判断,就算解析错了也不能是空 } else if (data.flameInfo == null) { var data1 = GetData <FlameNewData>(); if (data1 == null) { Log.Error("GetFlameData", "data1(FlameNewData) == null:" + data); } else { data.alertFlag = data1.alert_flag; data.numOfFlameRects = 1; data.message = ""; List <RectInfo> list = new List <RectInfo>(); List <RectOneInfo> newList = data1.alert_info; if (newList != null && newList.Count > 0) { for (int i = 0; i < newList.Count; i++) { RectOneInfo info1 = newList[i]; if (info1 == null) { continue; } RectInfo info2 = new RectInfo(); info2.x = info1.x; info2.y = info1.y; info2.width = info1.width; info2.height = info1.width; list.Add(info2); } data.flameInfo = list; } else { } } } return(data); } catch (Exception ex) { Log.Error("GetFlameData", ex.ToString()); return(new FlameData()); } }
public override bool GetSFRValue(Bitmap bmp, ref SFRValue SFRValue, ref RectInfo rectInfo, Rectangle[] rectangles, ref LightValue lightValue, bool TestLight = false) { SFRInfo info = new SFRInfo(); // Rectangle[] rectangles = new Rectangle[13]; SFR_C_Info sFR_C_Info = new SFR_C_Info(); SFR_C_Info YData = new SFR_C_Info(); double frequency = ParamSetMgr.GetInstance().GetDoubleParam("[SFR] dSFR_Parameter"); bool bRet = false; try { if (bmp == null) { return(false); } Bitmap temp = (Bitmap)bmp.Clone(); int nWidth = temp.Width; int nHeight = temp.Height; byte[] byBuffer = ImageChangeHelper.Instance.Rgb2Gray(bmp); unsafe { fixed(byte *byBufferptr = byBuffer) { bRet = ActiveAlignment.CalibrationMode_Collimators(byBufferptr, nWidth, nHeight, ref sFR_C_Info, ref YData); } } temp.Dispose(); //sfr 转换 SFRValue = AlgChangeHelper.Collimator_Info2Value(sFR_C_Info); rectInfo = AlgChangeHelper.Collimator_Info2Rect(sFR_C_Info); } catch { } double[] value = new double[5]; try { value[0] = YData.block[0].dValue; value[1] = YData.block[1].dValue; value[2] = YData.block[2].dValue; value[3] = YData.block[3].dValue; value[4] = YData.block[4].dValue; } catch (Exception ex) { value[0] = -1; value[1] = -1; value[2] = -1; value[3] = -1; value[4] = -1; //return false; } lightValue.blockValue = value; return(bRet); }
//private bool FillRoomByAnchor() //{ // int width; // int height; // do // { // width = Random.Range(minRoomWidth, maxRoomWidth); // height = Random.Range(minRoomHeight, maxRoomHeight); // } while (CheckFillRoomByAnchor(width,height)); // return true; //} private bool CheckFillRoomByAnchor(int width, int height) { int posX = -1; int posY = -1; switch (curDirection) { case Direction.up: posX = Random.Range(anchorPosX - width + 1, anchorPosX); posY = anchorPosY - 1; break; case Direction.down: posX = Random.Range(anchorPosX - width + 1, anchorPosX); posY = anchorPosY - height + 1; break; case Direction.left: posX = anchorPosX - width + 1; posY = Random.Range(anchorPosY - height + 1, anchorPosY); break; case Direction.right: posX = anchorPosX - 1; posY = Random.Range(anchorPosY - height + 1, anchorPosY); break; } if (posX + width > cols - 2 || posY + height > rows - 2 || posX < 2 || posY < 2) { return(false); } if (CheckFillRect(posX, posY, width, height)) { FillRect(posX, posY, width, height, Tile.Floor); RectInfo roomInfo = new RectInfo(posX, posY, width, height); roomInfos.Add(roomInfo); roomIndex++; return(true); } else { return(false); } }
public static bool HandleDragging_Prefix(object __instance, bool mouseOver, bool ____available) { ResearchProjectDef Research = (ResearchProjectDef)ResearchInfo.GetValue(__instance); Rect rect = (Rect)RectInfo.GetValue(__instance); Research.DrawExtras(rect, mouseOver || HighlightedProxy(__instance)); if (mouseOver && Event.current.type == EventType.MouseDown && Event.current.button == 0) { bool completed = Research.IsFinished; if (Event.current.button == 0) { Research.SelectMenu(completed); } if (DebugSettings.godMode && Prefs.DevMode && Event.current.button == 1 && !completed) { Find.ResearchManager.FinishProject(Research); Research.WipeAssignments(); } } return(false); }
// // copied the source file by https://github.com/stackprobe/Factory/blob/master/SubTools/CopyLib.c // public static void DrawRect_LTRB(DDPicture picture, double l, double t, double r, double b) { if ( l < -(double)IntTools.IMAX || (double)IntTools.IMAX - 1.0 < l || t < -(double)IntTools.IMAX || (double)IntTools.IMAX - 1.0 < t || r < l + 1.0 || (double)IntTools.IMAX < r || b < t + 1.0 || (double)IntTools.IMAX < b ) { throw new DDError(); } RectInfo layout = new RectInfo() { L = l, T = t, R = r, B = b, }; DrawPic(picture, layout); }
bool InRect(Matrix4x4 m, RectInfo r, Vector3 posi) { #if UNITY_EDITOR Vector3 leftdown = new Vector3(r.x - r.width / 2f, 0, r.z); Vector3 rightdown = new Vector3(r.x + r.width / 2f, 0, r.z); Vector3 leftup = new Vector3(r.x - r.width / 2f, 0, r.z + r.height); Vector3 rightup = new Vector3(r.x + r.width / 2f, 0, r.z + r.height); leftdown = m.MultiplyPoint(leftdown); leftup = m.MultiplyPoint(leftup); rightdown = m.MultiplyPoint(rightdown); rightup = m.MultiplyPoint(rightup); Debug.DrawLine(leftdown, leftup, Color.green); Debug.DrawLine(rightup, leftup, Color.green); Debug.DrawLine(rightdown, rightup, Color.green); Debug.DrawLine(leftdown, rightdown, Color.green); #endif Vector3 p = m.inverse.MultiplyPoint(posi); if (p.x > r.x + r.width / 2f || p.x < r.x - r.width / 2f || p.z > r.z + r.height || p.z < r.z) { return(false); } return(true); }
private void FillRoom() { //随机产生一个坐标,并且随机房间的大小,生成房间 int posX; int posY; int width; int height; do { posX = Random.Range(1, cols); posY = Random.Range(1, rows); width = Random.Range(minRoomWidth, maxRoomWidth); height = Random.Range(minRoomHeight, maxRoomHeight); }while (posX + width > cols - 2 || posY + height > rows - 2 || map[posX, posY] != Tile.Wall || !CheckFillRect(posX, posY, width, height)); RectInfo roomInfo = new RectInfo(posX, posY, width, height); FillRect(posX, posY, width, height, Tile.Floor); roomInfos.Add(roomInfo); }
private RectInfo ProccessRectInfo(RectInfo currentRectInfo, long ID) { if (!rectInfoDictionary.ContainsKey(ID)) { rectInfoDictionary.Add(ID, new Queue <RectInfo>()); } rectInfoDictionary[ID].Enqueue(currentRectInfo); int length = rectInfoDictionary[ID].Count; int x = 0; int y = 0; int w = 0; foreach (RectInfo rectInfo in rectInfoDictionary[ID]) { x += rectInfo.x; y += rectInfo.y; w += rectInfo.w; } x /= length; y /= length; w /= length; RectInfo newRectInfo = new RectInfo(x, y, w); if (length >= framesToSave) { rectInfoDictionary[ID].Dequeue(); } return(newRectInfo); }
public static RectInfo Chart_Info2Value(ObjectInfo info) { int x = info.SFR.Count(); RectInfo result = new RectInfo(); result.Points = new Point[x][]; int i = 0; for (i = 0; i < info.SFR.Count(); i++) { result.Points[i] = info.SFR[i]; } //result.Points //for (int i = 0; i < info.SFR.Length; i++) //{ // // result.block[i].aryValue = new double[info.block[i].aryValue.Length]; // result.block[i].aryValue = info.block[i].aryValue; // result.block[i].dValue = info.block[i].dValue; // result.block[i].dX = info.block[i].dX; // result.block[i].dY = info.block[i].dY; //} return(result); }
public void LoadData() { this.RectInfoList.Clear(); this.DefRect = null; try { string[] lines = File.ReadAllLines(this.DATA_FILE, Encoding.GetEncoding(932)); int i = 0; // CommonSetting { this.RightClickOff = Tools.ParseInt(lines[i++], 0, 1, 0) == 1; this.DoubleClickOff = Tools.ParseInt(lines[i++], 0, 1, 0) == 1; this.TaskIconDoubleClickAndAddRect = Tools.ParseInt(lines[i++], 0, 1, 0) == 1; this.Reserved_0001 = Tools.ParseInt(lines[i++], 0, 1, 0) == 1; // } while (i < lines.Length) { if (lines[i++] != Gnd.I.RECT_STARTER) { break; } RectInfo ri = new RectInfo(); ri.XPos = Tools.ParseInt(lines[i++], this.RI_MINPOS, this.RI_MAXPOS, 0); ri.YPos = Tools.ParseInt(lines[i++], this.RI_MINPOS, this.RI_MAXPOS, 0); ri.WinW = Tools.ParseInt(lines[i++], 1, this.RI_MAXPOS, 300); ri.WinH = Tools.ParseInt(lines[i++], 1, this.RI_MAXPOS, 300); ri.WinColorR = Tools.ParseInt(lines[i++], 0, 255, 0); ri.WinColorG = Tools.ParseInt(lines[i++], 0, 255, 0); ri.WinColorB = Tools.ParseInt(lines[i++], 0, 255, 0); ri.MostTop = Tools.ParseInt(lines[i++], 0, 1, 0) == 1; ri.MovableFlag = Tools.ParseInt(lines[i++], 0, 1, 0) == 1; ri.ImageFile = Tools.EraseDq(lines[i++]); ri.ImageStretchFlag = Tools.ParseInt(lines[i++], 0, 1, 0) == 1; ri.Text = Tools.EraseDq(lines[i++]); ri.TextAlign = (TextAlign_e)int.Parse(lines[i++]); ri.TextFont = Tools.FontFilter(lines[i++]); ri.TextSize = Tools.ParseInt(lines[i++], 1, 300, 10); ri.TextColorR = Tools.ParseInt(lines[i++], 0, 255, 0); ri.TextColorG = Tools.ParseInt(lines[i++], 0, 255, 0); ri.TextColorB = Tools.ParseInt(lines[i++], 0, 255, 0); ri.透明度Pct = Tools.ParseInt(lines[i++], 0, 95, 0); // RectInfo.* this.RectInfoList.Add(ri); } if (Tools.ParseInt(lines[i++], 0, 1, 0) == 1) { int li = this.RectInfoList.Count - 1; this.DefRect = this.RectInfoList[li]; this.RectInfoList.RemoveAt(li); } // CommonSetting_2 { this.BootDelaySecond = Tools.ParseInt(lines[i++], 0, 600, 0); this.TaskIconClickAndShowAllRectOff = Tools.ParseInt(lines[i++], 0, 1, 0) == 1; this.QuickEditTextFocusOutEditEnd = Tools.ParseInt(lines[i++], 0, 1, 0) == 1; // } } catch { //this.RectInfoList.Clear(); } }
// // copied the source file by https://github.com/stackprobe/Factory/blob/master/SubTools/CopyLib.c // private static void DrawPic_Main(DDPicture picture, ILayoutInfo layout) { // app > @ enter DrawPic // < app if (Extra.A != -1) { SetBlend(DX.DX_BLENDMODE_ALPHA, Extra.A); } else if (Extra.BlendAdd != -1) { SetBlend(DX.DX_BLENDMODE_ADD, Extra.BlendAdd); } else if (Extra.BlendInv) { SetBlend(DX.DX_BLENDMODE_INVSRC, 255); } if (Extra.Mosaic) { DX.SetDrawMode(DX.DX_DRAWMODE_NEAREST); } if (Extra.Bright.R != -1) { SetBright(Extra.Bright.R, Extra.Bright.G, Extra.Bright.B); } { FreeInfo u = layout as FreeInfo; if (u != null) { // ? 失敗 if ( Extra.IntPos ? DX.DrawModiGraph( DoubleTools.ToInt(u.LTX), DoubleTools.ToInt(u.LTY), DoubleTools.ToInt(u.RTX), DoubleTools.ToInt(u.RTY), DoubleTools.ToInt(u.RBX), DoubleTools.ToInt(u.RBY), DoubleTools.ToInt(u.LBX), DoubleTools.ToInt(u.LBY), picture.GetHandle(), 1 ) != 0 : DX.DrawModiGraphF( (float)u.LTX, (float)u.LTY, (float)u.RTX, (float)u.RTY, (float)u.RBX, (float)u.RBY, (float)u.LBX, (float)u.LBY, picture.GetHandle(), 1 ) != 0 ) { if (Extra.IgnoreError == false) { throw new DDError(); } } goto endDraw; } } { RectInfo u = layout as RectInfo; if (u != null) { // ? 失敗 if ( Extra.IntPos ? DX.DrawExtendGraph( DoubleTools.ToInt(u.L), DoubleTools.ToInt(u.T), DoubleTools.ToInt(u.R), DoubleTools.ToInt(u.B), picture.GetHandle(), 1 ) != 0 : DX.DrawExtendGraphF( (float)u.L, (float)u.T, (float)u.R, (float)u.B, picture.GetHandle(), 1 ) != 0 ) { if (Extra.IgnoreError == false) { throw new DDError(); } } goto endDraw; } } { SimpleInfo u = layout as SimpleInfo; if (u != null) { // ? 失敗 if ( Extra.IntPos ? DX.DrawGraph( DoubleTools.ToInt(u.X), DoubleTools.ToInt(u.Y), picture.GetHandle(), 1 ) != 0 : DX.DrawGraphF( (float)u.X, (float)u.Y, picture.GetHandle(), 1 ) != 0 ) { if (Extra.IgnoreError == false) { throw new DDError(); } } goto endDraw; } } throw new DDError(); // ? 不明なレイアウト endDraw: if (Extra.A != -1 || Extra.BlendAdd != -1 || Extra.BlendInv) { ResetBlend(); } if (Extra.Mosaic) { DX.SetDrawMode(DX.DX_DRAWMODE_BILINEAR); } if (Extra.Bright.R != -1) { ResetBright(); } // app > @ leave DrawPic // < app }
public abstract bool GetSFRValue(Bitmap bmp, ref SFRValue SFRValue, ref RectInfo rectInfo, Rectangle[] rectangles, ref LightValue lightValue, bool TestLight = false);
public override bool GetSFRValue(Bitmap bmp, ref SFRValue SFRValue, ref RectInfo rectInfo, Rectangle[] rectangles, ref LightValue lightValue, bool TestLight = false) { SFRInfo info = new SFRInfo(); ObjectInfo objectInfo = new ObjectInfo(); // Rectangle[] rectangles = new Rectangle[13]; if (bmp == null) { return(false); } Bitmap temp = (Bitmap)bmp.Clone(); bool bRet = false; int nWidth = temp.Width; int nHeight = temp.Height; byte[] byBuffer = ImageChangeHelper.Instance.Rgb2Gray(bmp); unsafe { fixed(byte *byBufferptr = byBuffer) { bRet = ActiveAlignment.GetSFRValue_Sector(byBufferptr, nWidth, nHeight, ref info, ref objectInfo, rectangles); } } temp.Dispose(); //sfr 转换 if (TestLight) { double[] value = new double[5]; HObject ho_Image = null, ho_GrayImage = null; try { HObject ho_SelectedRegions0 = null; HObject ho_SelectedRegions1 = null; HObject ho_SelectedRegions2 = null; HObject ho_SelectedRegions3 = null; HObject ho_SelectedRegions4 = null; HTuple hv_XField = null, hv_YField = null; HTuple hv_CenterROIR = null, hv_CenterROIC = null, hv_CenterMinArea = null, hv_CenterSFRThreshold = null, hv_CenterClosing = null; HTuple hv_Corner1ROIR = null, hv_Corner1ROIC = null, hv_Corner1MinArea = null, hv_Corner1SFRThreshold = null, hv_Corner1Closing = null; HTuple CenterMean = null, CenterDeviation = null; HTuple Corner1Mean = null, Corner1Deviation = null; HTuple Corner2Mean = null, Corner2Deviation = null; HTuple Corner3Mean = null, Corner3Deviation = null; HTuple Corner4Mean = null, Corner4Deviation = null; hv_CenterROIR = ParamSetMgr.GetInstance().GetIntParam("[SFR] nCenterROIW"); hv_CenterROIC = ParamSetMgr.GetInstance().GetIntParam("[SFR] nCenterROIH"); hv_CenterMinArea = ParamSetMgr.GetInstance().GetDoubleParam("MF中心对心最小面积"); hv_CenterSFRThreshold = ParamSetMgr.GetInstance().GetDoubleParam("MF中心对心阈值设置"); hv_CenterClosing = ParamSetMgr.GetInstance().GetDoubleParam("MF中心对心膨胀系数"); hv_XField = ParamSetMgr.GetInstance().GetDoubleParam("[SFR] dCorner1XField"); hv_YField = ParamSetMgr.GetInstance().GetDoubleParam("[SFR] dCorner1YField"); hv_Corner1ROIR = ParamSetMgr.GetInstance().GetIntParam("[SFR] nCorner1ROIW"); hv_Corner1ROIC = ParamSetMgr.GetInstance().GetIntParam("[SFR] nCorner1ROIH"); hv_Corner1MinArea = ParamSetMgr.GetInstance().GetDoubleParam("MF_Corner1最小面积"); hv_Corner1SFRThreshold = ParamSetMgr.GetInstance().GetDoubleParam("MF_Corner1阈值设置"); hv_Corner1Closing = ParamSetMgr.GetInstance().GetDoubleParam("MF_Corner1膨胀系数"); ImageChangeHelper.Instance.Bitmap2HObject((Bitmap)bmp.Clone(), ref ho_Image); FindCenterRegions(ho_Image, hv_CenterROIR, hv_CenterROIC, 0, 0, hv_CenterMinArea, hv_CenterSFRThreshold, hv_CenterClosing, ref ho_SelectedRegions0); FindCenterRegions(ho_Image, hv_Corner1ROIR, hv_Corner1ROIC, -hv_XField, -hv_YField, hv_Corner1MinArea, hv_Corner1SFRThreshold, hv_Corner1Closing, ref ho_SelectedRegions1); FindCenterRegions(ho_Image, hv_Corner1ROIR, hv_Corner1ROIC, hv_XField, -hv_YField, hv_Corner1MinArea, hv_Corner1SFRThreshold, hv_Corner1Closing, ref ho_SelectedRegions2); FindCenterRegions(ho_Image, hv_Corner1ROIR, hv_Corner1ROIC, -hv_XField, hv_YField, hv_Corner1MinArea, hv_Corner1SFRThreshold, hv_Corner1Closing, ref ho_SelectedRegions3); FindCenterRegions(ho_Image, hv_Corner1ROIR, hv_Corner1ROIC, hv_XField, hv_YField, hv_Corner1MinArea, hv_Corner1SFRThreshold, hv_Corner1Closing, ref ho_SelectedRegions4); HOperatorSet.Intensity(ho_SelectedRegions0, ho_Image, out CenterMean, out CenterDeviation); HOperatorSet.Intensity(ho_SelectedRegions1, ho_Image, out Corner1Mean, out Corner1Deviation); HOperatorSet.Intensity(ho_SelectedRegions2, ho_Image, out Corner2Mean, out Corner2Deviation); HOperatorSet.Intensity(ho_SelectedRegions3, ho_Image, out Corner3Mean, out Corner3Deviation); HOperatorSet.Intensity(ho_SelectedRegions4, ho_Image, out Corner4Mean, out Corner4Deviation); value[0] = CenterMean.D; value[1] = Corner1Mean.D; value[2] = Corner2Mean.D; value[3] = Corner3Mean.D; value[4] = Corner4Mean.D; } catch (Exception ex) { value[0] = -1; value[1] = -1; value[2] = -1; value[3] = -1; value[4] = -1; //return false; } lightValue.blockValue = value; } SFRValue = AlgChangeHelper.Sector_Info2Value(info); rectInfo = AlgChangeHelper.Sector_Info2Value(objectInfo); return(bRet); }
public static extern int IFR_GetRectInfo(IntPtr intPtr, ref RectInfo lineInfo);
// // copied the source file by https://github.com/stackprobe/Factory/blob/master/SubTools/CopyLib.c // private static void DrawPic_Main(DDPicture picture, ILayoutInfo layout) { // app > @ enter DrawPic // < app if (Extra.A != -1) { SetBlend(DX.DX_BLENDMODE_ALPHA, Extra.A); } else if (Extra.BlendAdd != -1) { SetBlend(DX.DX_BLENDMODE_ADD, Extra.BlendAdd); } else if (Extra.BlendInv) { SetBlend(DX.DX_BLENDMODE_INVSRC, 255); } if (Extra.Mosaic) { DX.SetDrawMode(DX.DX_DRAWMODE_NEAREST); } if (Extra.Bright.R != -1) { SetBright(Extra.Bright.R, Extra.Bright.G, Extra.Bright.B); } { FreeInfo u = layout as FreeInfo; if (u != null) { // ? 失敗 if ( Extra.IntPos ? DX.DrawModiGraph( DoubleTools.ToInt(u.LTX), DoubleTools.ToInt(u.LTY), DoubleTools.ToInt(u.RTX), DoubleTools.ToInt(u.RTY), DoubleTools.ToInt(u.RBX), DoubleTools.ToInt(u.RBY), DoubleTools.ToInt(u.LBX), DoubleTools.ToInt(u.LBY), picture.GetHandle(), 1 ) != 0 : DX.DrawModiGraphF( (float)u.LTX, (float)u.LTY, (float)u.RTX, (float)u.RTY, (float)u.RBX, (float)u.RBY, (float)u.LBX, (float)u.LBY, picture.GetHandle(), 1 ) != 0 ) { if (Extra.IgnoreError == false) { throw new DDError(); } } goto endDraw; } } { RectInfo u = layout as RectInfo; if (u != null) { // ? 失敗 if ( Extra.IntPos ? DX.DrawExtendGraph( DoubleTools.ToInt(u.L), DoubleTools.ToInt(u.T), DoubleTools.ToInt(u.R), DoubleTools.ToInt(u.B), picture.GetHandle(), 1 ) != 0 : DX.DrawExtendGraphF( (float)u.L, (float)u.T, (float)u.R, (float)u.B, picture.GetHandle(), 1 ) != 0 ) { if (Extra.IgnoreError == false) { throw new DDError(); } } goto endDraw; } } { SimpleInfo u = layout as SimpleInfo; if (u != null) { // ? 失敗 if ( Extra.IntPos ? DX.DrawGraph( DoubleTools.ToInt(u.X), DoubleTools.ToInt(u.Y), picture.GetHandle(), 1 ) != 0 : DX.DrawGraphF( (float)u.X, (float)u.Y, picture.GetHandle(), 1 ) != 0 ) { if (Extra.IgnoreError == false) { throw new DDError(); } } goto endDraw; } } throw new DDError(); // ? 不明なレイアウト endDraw: if (Extra.A != -1 || Extra.BlendAdd != -1 || Extra.BlendInv) { ResetBlend(); } if (Extra.Mosaic) { DX.SetDrawMode(DX.DX_DRAWMODE_BILINEAR); } if (Extra.Bright.R != -1) { ResetBright(); } // app > @ leave DrawPic { FreeInfo u = layout as FreeInfo; if (u != null) { double l = u.LTX; double t = u.LTY; double r = u.LTX; double b = u.LTY; l = Math.Min(l, u.RTX); l = Math.Min(l, u.RBX); l = Math.Min(l, u.LBX); t = Math.Min(t, u.RTY); t = Math.Min(t, u.RBY); t = Math.Min(t, u.LBY); r = Math.Max(r, u.RTX); r = Math.Max(r, u.RBX); r = Math.Max(r, u.LBX); b = Math.Max(b, u.RTY); b = Math.Max(b, u.RBY); b = Math.Max(b, u.LBY); Charlotte.Games.NamedCrashMgr.LastDrawedCrash = Charlotte.Common.Options.DDCrashUtils.Rect(new D4Rect( l, t, r - l, b - t )); goto endPostDraw; } } { RectInfo u = layout as RectInfo; if (u != null) { double l = u.L; double t = u.T; double r = u.R; double b = u.B; Charlotte.Games.NamedCrashMgr.LastDrawedCrash = Charlotte.Common.Options.DDCrashUtils.Rect(new D4Rect( l, t, r - l, b - t )); goto endPostDraw; } } { SimpleInfo u = layout as SimpleInfo; if (u != null) { Charlotte.Games.NamedCrashMgr.LastDrawedCrash = Charlotte.Common.Options.DDCrashUtils.Rect(new D4Rect( u.X, u.Y, picture.Get_W(), picture.Get_H() )); goto endPostDraw; } } throw new DDError(); // ? 不明なレイアウト endPostDraw: ; // < app }
public virtual bool OverlapPoint(Vector2 point, Event curEvt) { return(IsVisibility && RectInfo.Contains(point) && !IsPenetrate); }
public static bool ResearchNode_Draw_Prefix(object __instance, Rect visibleRect, bool forceDetailedMode = false) { //Reflected objects Rect rect = (Rect)RectInfo.GetValue(__instance); ResearchProjectDef Research = (ResearchProjectDef)ResearchInfo.GetValue(__instance); bool available = (bool)AvailableInfo.GetValue(__instance); bool completed = Research.IsFinished; //simplified // if (!(bool)IsVisibleInfo.Invoke(__instance, new object[] { visibleRect })) { HighlightedProxy(__instance, false); return(false); } bool detailedMode = forceDetailedMode || (float)ZoomLevelInfo.GetValue(InstanceInfo.GetValue(__instance)) < DetailedModeZoomLevelCutoff; bool mouseOver = Mouse.IsOver(rect); bool highlighted = HighlightedProxy(__instance); if (Event.current.type == EventType.Repaint) { //researches that are completed or could be started immediately, and that have the required building(s) available GUI.color = mouseOver ? BrightColor : (Color)ColorInfo.GetValue(__instance); if (mouseOver || highlighted) { GUI.DrawTexture(rect, ResearchTree_Assets.ButtonActive); } else { GUI.DrawTexture(rect, ResearchTree_Assets.Button); } //grey out center to create a progress bar effect, completely greying out research not started. if (available) { var progressBarRect = rect.ContractedBy(3f); GUI.color = ResearchTree_Assets.ColorAvailable[Research.techLevel]; progressBarRect.xMin += Research.ProgressPercent * progressBarRect.width; GUI.DrawTexture(progressBarRect, BaseContent.WhiteTex); } HighlightedProxy(__instance, interest == Research); //draw the research label if (!completed && !available) { GUI.color = Color.grey; } else { GUI.color = Color.white; } if (detailedMode) { Text.Anchor = TextAnchor.UpperLeft; Text.WordWrap = false; Text.Font = (bool)largeLabelInfo.GetValue(__instance) ? GameFont.Tiny : GameFont.Small; Widgets.Label((Rect)LabelRectInfo.GetValue(__instance), Research.LabelCap); } else { Text.Anchor = TextAnchor.MiddleCenter; Text.WordWrap = false; Text.Font = GameFont.Medium; Widgets.Label(rect, Research.LabelCap); } //draw research cost and icon if (detailedMode) { Text.Anchor = TextAnchor.UpperRight; Text.Font = Research.CostApparent > 1000000 ? GameFont.Tiny : GameFont.Small; Widgets.Label((Rect)CostLabelRectInfo.GetValue(__instance), Research.CostApparent.ToStringByStyle(ToStringStyle.Integer)); GUI.DrawTexture((Rect)CostIconRectInfo.GetValue(__instance), !completed && !available ? ResearchTree_Assets.Lock : ResearchTree_Assets.ResearchIcon, ScaleMode.ScaleToFit); } Text.WordWrap = true; //attach description and further info to a tooltip string root = HarmonyPatches.ResearchPal ? "ResearchPal" : "Fluffy.ResearchTree"; TooltipHandler.TipRegion(rect, new Func <string>(() => (string)GetResearchTooltipStringInfo.Invoke(__instance, new object[] { })), Research.GetHashCode()); if (!BuildingPresentProxy(Research)) { string languageKey = root + ".MissingFacilities"; TooltipHandler.TipRegion(rect, languageKey.Translate(string.Join(", ", MissingFacilities(Research).Select(td => td.LabelCap).ToArray()))); } else if (!TechprintAvailable(Research)) { string languageKey = root + ".MissingTechprints"; TooltipHandler.TipRegion(rect, languageKey.Translate(Research.TechprintsApplied, Research.techprintCount)); } //draw unlock icons if (detailedMode) { Rect IconsRect = (Rect)IconsRectInfo.GetValue(__instance); var unlocks = GetUnlockDefsAndDescs(Research); for (var i = 0; i < unlocks.Count; i++) { var iconRect = new Rect( IconsRect.xMax - (i + 1) * (IconSize.x + 4f), IconsRect.yMin + (IconsRect.height - IconSize.y) / 2f, IconSize.x, IconSize.y); if (iconRect.xMin - IconSize.x < IconsRect.xMin && i + 1 < unlocks.Count) { //stop the loop if we're about to overflow and have 2 or more unlocks yet to print. iconRect.x = IconsRect.x + 4f; GUI.DrawTexture(iconRect, ResearchTree_Assets.MoreIcon, ScaleMode.ScaleToFit); var tip = string.Join("\n", unlocks.GetRange(i, unlocks.Count - i).Select(p => p.Second).ToArray()); TooltipHandler.TipRegion(iconRect, tip); //new TipSignal(tip, Settings.TipID, TooltipPriority.Pawn) ); break; } //draw icon unlocks[i].First.DrawColouredIcon(iconRect); //tooltip TooltipHandler.TipRegion(iconRect, unlocks[i].Second); } } if (mouseOver) { if (interest != null && interest != Research) { DeInterest(); } //highlight prerequisites if research available if (available) { HighlightedProxy(__instance, true); foreach (var prerequisite in (IEnumerable <object>)GetMissingRequiredRecursiveInfo.Invoke(__instance, new object[] { })) { HighlightedProxy(Convert.ChangeType(prerequisite, ResearchNodeType()), true); } } //highlight children if completed else if (completed) { foreach (var child in (IEnumerable <object>)ChildrenInfo.GetValue(__instance)) { HighlightedProxy(Convert.ChangeType(child, ResearchNodeType()), true); } } } } //CUSTOM: a bunch of things on top Research.DrawExtras(rect, mouseOver || highlighted); if (Widgets.ButtonInvisible(rect)) { //CUSTOM: replaced queue operations for assignment menu if (Event.current.button == 0) { Research.SelectMenu(completed); } if (DebugSettings.godMode && Prefs.DevMode && Event.current.button == 1 && !Research.IsFinished) { Find.ResearchManager.FinishProject(Research); Research.WipeAssignments(); } } return(false); }
public void Remove(RectInfo ri) { this.RectInfoList.Remove(ri); }
static void CreateTexbinFile(string pathname, bool generateRectSection = true, bool compressedData = true) { var filelist = Directory.GetFiles(pathname).Where(x => !x.ToLower().EndsWith(".xml")).ToArray(); var filelist_unique = filelist.Select(Path.GetFileNameWithoutExtension).Distinct().Where(x => !x.ToLower().EndsWith(".xml")).ToList(); filelist_unique = filelist_unique.Select(x => x.ToUpper()).ToList(); if (filelist_unique.Count != filelist.Length) { Console.WriteLine("Folder has more files than expected. Are there multiple files with the same name (not including extension)?"); Environment.Exit(1); } var formatMetadata = new FormatMetadata(); if (File.Exists(Path.Combine(pathname, "_metadata-format.xml"))) { formatMetadata = DeserializeFormatMetadata(Path.Combine(pathname, "_metadata-format.xml")); } else { foreach (var filename in filelist_unique) { var data = new FormatInfo { Filename = filename, FormatType = 0, }; formatMetadata.FormatInfo.Add(data); } } var nameSection = CreateNameSection(filelist_unique); var dataSection = new List <byte>(); var fileinfoSection = new List <byte>(); var imageRectInfo = new Dictionary <string, Tuple <ushort, ushort> >(); for (int i = 0; i < filelist_unique.Count; i++) { var data = File.ReadAllBytes(filelist[i]); Console.WriteLine("Adding {0}...", filelist[i]); if (!data.Take(4).SequenceEqual(new byte[] { 0x54, 0x58, 0x44, 0x54 }) && !data.Take(4).SequenceEqual(new byte[] { 0x54, 0x44, 0x58, 0x54 })) { data = gitadora_textool.Program.CreateImageCore(data, true); } var formatTypeList = formatMetadata.FormatInfo.Where(x => String.CompareOrdinal(Path.GetFileNameWithoutExtension(filelist_unique[i]), x.Filename) == 0).ToList(); data[0x2c] = formatTypeList.Count > 0 ? formatTypeList[0].FormatType : data[0x2c]; fileinfoSection.AddRange(BitConverter.GetBytes(0)); fileinfoSection.AddRange(BitConverter.GetBytes(data.Length + 0x08)); fileinfoSection.AddRange(BitConverter.GetBytes(0x40 + nameSection.Count + (filelist_unique.Count * 0x0c) + dataSection.Count)); if (compressedData) { dataSection.AddRange(Compress(data)); } else { dataSection.AddRange(BitConverter.GetBytes(data.Length).Reverse()); dataSection.AddRange(BitConverter.GetBytes(0)); dataSection.AddRange(data); } imageRectInfo[filelist_unique[i]] = new Tuple <ushort, ushort>((ushort)((data[0x11] << 8) | data[0x10]), (ushort)((data[0x13] << 8) | data[0x12])); } if ((dataSection.Count % 4) != 0) { var padding = 4 - (dataSection.Count % 4); while (padding > 0) { dataSection.Add(0); padding--; } } var rectSection = new List <byte>(); if (generateRectSection) { var rectInfo = new TexInfo(); if (File.Exists(Path.Combine(pathname, "_metadata.xml"))) { rectInfo = Deserialize(Path.Combine(pathname, "_metadata.xml")); } else { foreach (var filename in filelist_unique) { var data = new RectInfo { ExternalFilename = filename, Filename = filename, X = 0, Y = 0, W = imageRectInfo[filename].Item1, H = imageRectInfo[filename].Item2 }; rectInfo.RectInfo.Add(data); } } var rectNameFilelist = rectInfo.RectInfo.Select(x => x.Filename) .Select(Path.GetFileNameWithoutExtension).Distinct() .Where(x => !x.ToLower().EndsWith(".xml")).ToList(); var rectinfoSection = new List <byte>(); var rectNameSection = CreateNameSection(rectNameFilelist); foreach (var data in rectInfo.RectInfo) { rectinfoSection.AddRange(BitConverter.GetBytes(filelist_unique.IndexOf(Path.GetFileNameWithoutExtension(data.ExternalFilename)))); rectinfoSection.AddRange(BitConverter.GetBytes(data.X)); rectinfoSection.AddRange(BitConverter.GetBytes(data.W)); rectinfoSection.AddRange(BitConverter.GetBytes(data.Y)); rectinfoSection.AddRange(BitConverter.GetBytes(data.H)); } rectSection.AddRange( new byte[] { 0x54, 0x43, 0x45, 0x52, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00 }); rectSection.AddRange(BitConverter.GetBytes(0x1c + rectNameSection.Count + rectinfoSection.Count)); rectSection.AddRange(BitConverter.GetBytes(rectNameFilelist.Count)); rectSection.AddRange(BitConverter.GetBytes(0x1c)); rectSection.AddRange(BitConverter.GetBytes(0x1c + rectNameSection.Count)); rectSection.AddRange(rectNameSection); rectSection.AddRange(rectinfoSection); } var outputData = new List <byte>(); outputData.AddRange(new byte[] { 0x50, 0x58, 0x45, 0x54, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00 }); outputData.AddRange(BitConverter.GetBytes(0x40 + nameSection.Count + fileinfoSection.Count + dataSection.Count + rectSection.Count)); // Archive size outputData.AddRange(BitConverter.GetBytes(1)); outputData.AddRange(BitConverter.GetBytes(filelist_unique.Count)); outputData.AddRange(BitConverter.GetBytes(0)); outputData.AddRange(BitConverter.GetBytes(0x40 + nameSection.Count + fileinfoSection.Count)); outputData.AddRange(BitConverter.GetBytes(rectSection.Count > 0 ? 0x40 + nameSection.Count + fileinfoSection.Count + dataSection.Count : 0)); outputData.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); outputData.AddRange(BitConverter.GetBytes(0x40)); // PMAN section offset outputData.AddRange(BitConverter.GetBytes(0)); outputData.AddRange(BitConverter.GetBytes(0x40 + nameSection.Count)); outputData.AddRange(nameSection); outputData.AddRange(fileinfoSection); outputData.AddRange(dataSection); outputData.AddRange(rectSection); var basePath = Path.GetFileName(pathname); if (String.IsNullOrWhiteSpace(basePath)) { basePath = pathname.Replace(".\\", "").Replace("\\", ""); } var outputFilename = Path.Combine(Path.GetDirectoryName(pathname), String.Format("{0}.bin", basePath)); File.WriteAllBytes(outputFilename, outputData.ToArray()); }
static void ParseTexbinFile(string filename, bool splitImages = true) { var outputPath = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)); Directory.CreateDirectory(outputPath); using (BinaryReader reader = new BinaryReader(File.Open(filename, FileMode.Open))) { var texpMagic = Encoding.ASCII.GetString(reader.ReadBytes(4)); if (texpMagic != "PXET") { Console.WriteLine("Not a valid texbin file"); Environment.Exit(1); } var unk1 = reader.ReadInt32(); var unk2 = reader.ReadInt32(); var archiveSize = reader.ReadInt32(); var unk3 = reader.ReadInt32(); var fileCount = reader.ReadInt64(); var dataOffset = reader.ReadInt32(); var rectOffset = reader.ReadInt32(); var unk4 = reader.ReadBytes(0x10); var nameOffset = reader.ReadInt32(); var unk5 = reader.ReadInt32(); var dataEntryOffset = reader.ReadInt32(); if (fileCount == 0) { Console.WriteLine("This file doesn't contain any image data."); return; } var entries = ReadNameSection(reader, nameOffset); ReadDataEntrySection(reader, dataEntryOffset, fileCount, entries); var texInfo = new TexInfo(); if (rectOffset != 0) { var rectInfo = ReadRectEntrySection(reader, rectOffset); foreach (var rect in rectInfo) { var e = new RectInfo { ExternalFilename = entries[rect.ImageId].Filename, Filename = rect.Entry.Filename, X = rect.X, Y = rect.Y, W = rect.W, H = rect.H }; texInfo.RectInfo.Add(e); } // Add code to optionally not split texture files and save a metadata file instead if (!splitImages) { Serialize <TexInfo>(texInfo, Path.Combine(outputPath, "_metadata.xml")); } } var formatMetadata = new FormatMetadata(); foreach (var entry in entries) { reader.BaseStream.Seek(entry.DataOffset, SeekOrigin.Begin); var data = Decompress(reader); if (Encoding.ASCII.GetString(data, 0, 4) == "TXDT" || Encoding.ASCII.GetString(data, 0, 4) == "TDXT") { var rectInfoList = texInfo.RectInfo.Where(x => String.CompareOrdinal(Path.GetFileNameWithoutExtension(entry.Filename), x.ExternalFilename) == 0).ToList(); if (!splitImages) { rectInfoList.Clear(); } if (rectInfoList.Count == 0) { var rectInfo = new RectInfo { ExternalFilename = entry.Filename, Filename = entry.Filename, X = 0, Y = 0, W = 0, H = 0 }; rectInfoList.Add(rectInfo); } if (!splitImages) { formatMetadata.FormatInfo.Add(new FormatInfo { Filename = entry.Filename, FormatType = data[0x2c] }); } foreach (var rectInfo in rectInfoList) { try { using (var stream = new MemoryStream(data)) { using (var dataReader = new BinaryReader(stream)) { byte[] extractedData; if (!splitImages || rectInfoList.Count == 0 || rectInfo.W == 0 || rectInfo.H == 0) { extractedData = gitadora_textool.Program.ExtractImageCore(dataReader, null); } else { extractedData = gitadora_textool.Program.ExtractImageCore(dataReader, rectInfo); } var ext = ".png"; if (extractedData[0] == 'D' && extractedData[1] == 'D' && extractedData[2] == 'S' && extractedData[3] == ' ') { ext = ".dds"; } var outputFilename = Path.Combine(outputPath, rectInfo.Filename); outputFilename += ext; Console.WriteLine("Saving {0}...", outputFilename); File.WriteAllBytes(outputFilename, extractedData); // File.WriteAllBytes(outputFilename.Replace(ext, ".bin"), data); if (splitImages) { formatMetadata.FormatInfo.Add(new FormatInfo { Filename = rectInfo.Filename, FormatType = data[0x2c] }); } } } } catch (Exception e) { Console.WriteLine("Couldn't convert image: {0}", e.Message); File.WriteAllBytes(Path.Combine(outputPath, entry.Filename), data); } } } } Serialize <FormatMetadata>(formatMetadata, Path.Combine(outputPath, "_metadata-format.xml")); } }