Exemplo n.º 1
0
        public void AddImage(MNReferencedImage ri)
        {
            MNLazyImage li = new MNLazyImage(Document);

            li.Image = ri;
            Objects.Add(new StringItem(li));
        }
Exemplo n.º 2
0
        public object AcceptFile(string sFileName)
        {
            string extension = Path.GetExtension(sFileName);

            switch (extension)
            {
            case ".png":
            case ".jpg":
            case ".jpeg":
            {
                foreach (MNReferencedImage mri in DefaultLanguage.Images)
                {
                    if (mri.FilePath.Equals(sFileName))
                    {
                        return(mri);
                    }
                }

                Image             loadedImage = Image.FromFile(sFileName);
                MNReferencedImage ri          = CreateNewImage();
                ri.ImageData   = loadedImage;
                ri.Name        = Path.GetFileNameWithoutExtension(sFileName);
                ri.FilePath    = sFileName;
                ri.Description = string.Format("{0}x{1}", loadedImage.Width, loadedImage.Height);
                return(ri);
            }

            default:
                return(null);
            }
        }
Exemplo n.º 3
0
        public override bool OnDropFinished(PVDragContext dc)
        {
            HoverSpot = null;
            if (HasImmediateEvaluation)
            {
                if (Img != null && Img.Image != null)
                {
                    MNReferencedImage img  = Img.Image;
                    MNReferencedSpot  spot = img.FindSpot(showRect, sourceRect, dc.lastPoint);
                    if (spot != null && spot.ContentType == SMContentType.TaggedArea &&
                        dc.draggedItem.Tag.Equals(spot.Name, StringComparison.CurrentCultureIgnoreCase))
                    {
                        spot.UIStateHighlighted = true;
                        return(base.OnDropFinished(dc));
                    }
                }

                if (!Tag.Equals(dc.draggedItem.Tag, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(false);
                }
            }

            DroppedImage = dc.draggedItem.Image;
            DroppedTag   = dc.draggedItem.Tag;
            DroppedText  = dc.draggedItem.Text;

            return(base.OnDropFinished(dc));
        }
Exemplo n.º 4
0
        private void DrawCard(MNPageContext context, Rectangle rect, MNReferencedImage image)
        {
            Size imgSize = SMGraphics.GetMaximumSize(rect, image.ImageData.Size);

            context.g.DrawImage(image.ImageData, rect.X + rect.Width / 2 - imgSize.Width / 2,
                                rect.Y + rect.Height / 2 - imgSize.Height / 2, imgSize.Width, imgSize.Height);
        }
Exemplo n.º 5
0
        public override void OnTapEnd(PVDragContext dc)
        {
            base.OnTapEnd(dc);
            MNReferencedImage img = Img.Image;

            if (img == null)
            {
                return;
            }

            MNReferencedSpot spot = img.FindSpot(showRect, sourceRect, dc.lastPoint);

            if (spot != null)
            {
                if (spot.ContentType != SMContentType.TaggedArea)
                {
                    MNReferencedCore obj = Document.FindContentObject(spot.ContentType, spot.ContentId);

                    if (obj != null && (obj is MNReferencedSound) && Document.HasViewer)
                    {
                        Document.Viewer.OnEvent("OnPlaySound", obj as MNReferencedSound);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public override GSCore ExecuteMessage(string token, GSCoreCollection args)
        {
            if (token.Equals("addCard"))
            {
                string tag  = args.getSafe(0).getStringValue();
                string img1 = args.getSafe(1).getStringValue();

                MNReferencedImage i1 = Document.FindImage(img1);

                if (i1 != null)
                {
                    SMMemoryGameCard card = new SMMemoryGameCard(Document);
                    card.Tag         = tag;
                    card.Image.Image = i1;

                    cards.Add(card);
                }
            }
            else if (token.Equals("mixCards"))
            {
                MixCards();
            }
            else if (token.Equals("clearChanged"))
            {
                ClearChanged(args);
            }
            else if (token.Equals("restart"))
            {
                ResetStatus();
            }
            return(base.ExecuteMessage(token, args));
        }
Exemplo n.º 7
0
        public void AddCard(string tg, MNReferencedImage mri)
        {
            SMMemoryGameCard nc = new SMMemoryGameCard(Document);

            nc.Tag         = tg;
            nc.Image.Image = mri;
            cards.Add(nc);

            if (matrix != null)
            {
                for (int r = 0; r < matrix.GetLength(0); r++)
                {
                    for (int c = 0; c < matrix.GetLength(1); c++)
                    {
                        if (matrix[r, c] == null)
                        {
                            matrix[r, c] = nc;
                            // to stop loop
                            r = matrix.GetLength(0);
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
 public string GetFileNameFromImage(MNReferencedImage image)
 {
     if (image == null)
     {
         return(null);
     }
     return(string.Format("img/image{0}.png", image.Id));
 }
Exemplo n.º 9
0
        public MNReferencedImage CreateNewImage()
        {
            MNReferencedImage image = new MNReferencedImage();

            image.Id = Data.GetNextId();
            DefaultLanguage.Images.Add(image);
            DefaultLanguage.Modified = true;
            return(image);
        }
Exemplo n.º 10
0
        private System.Drawing.Image GetContentImage(out MNReferencedImage refImage)
        {
            if (DroppedImage != null)
            {
                refImage = null;
                return(DroppedImage);
            }

            if (BuiltInImage != null && Document != null)
            {
                if (BuiltInImage.Length > 0 && Document.HasViewer)
                {
                    refImage = null;
                    return(Document.Viewer.GetBuiltInImage(BuiltInImage));
                }
            }

            refImage = Img.Image;
            return(Img.ImageData);
        }
Exemplo n.º 11
0
        public bool Load(RSFileReader br, bool fullRead)
        {
            if (!br.ReadHeader(p_FileHeader))
            {
                return(false);
            }

            Clear();
            byte tag;

            while ((tag = br.ReadByte()) != 0)
            {
                switch (tag)
                {
                case 10:
                    string key   = br.ReadString();
                    string value = br.ReadString();
                    Properties.Add(key, value);
                    if (key.Equals("TotalWork"))
                    {
                        long la;
                        if (long.TryParse(value, out la))
                        {
                            WorkTime.SetTotalWorkTime(la);
                        }
                    }
                    break;

                case 100:
                    if (!fullRead)
                    {
                        return(true);
                    }
                    MNReferencedText rt = new MNReferencedText();
                    rt.Load(br);
                    Texts.Add(rt);
                    break;

                case 101:
                    if (!fullRead)
                    {
                        return(true);
                    }
                    MNReferencedImage ri = new MNReferencedImage();
                    ri.Load(br);
                    Images.Add(ri);
                    break;

                case 102:
                    if (!fullRead)
                    {
                        return(true);
                    }
                    MNReferencedSound rs = new MNReferencedSound();
                    rs.Load(br);
                    Sounds.Add(rs);
                    break;

                case 103:
                    if (!fullRead)
                    {
                        return(true);
                    }
                    MNReferencedAudioText ra = new MNReferencedAudioText();
                    ra.Load(br);
                    AudioTexts.Add(ra);
                    break;

                case 104:
                    if (!fullRead)
                    {
                        return(true);
                    }
                    MNReferencedStyle rsa = new MNReferencedStyle();
                    rsa.Load(br);
                    Styles.Add(rsa);
                    break;

                default:
                    LoadMessage = string.Format("Unknown tag {0} at position {1} in the file.", tag, br.Position);
                    return(false);
                }
            }

            Modified = false;
            return(true);
        }
Exemplo n.º 12
0
        public override void Paint(MNPageContext context)
        {
            Graphics  g    = context.g;
            SMImage   pi   = this;
            Rectangle rect = Area.GetBounds(context);

            SMConnection conn = context.CurrentPage.FindConnection(this);

            if (conn != null)
            {
                UIStateHover = true;
            }

            SMStatusLayout layout = PrepareBrushesAndPens();

            Debugger.Log(0, "", "State of " + Text + " Image is " + UIStateChecked.ToString() + "\n");
            Rectangle           bounds   = ContentPadding.ApplyPadding(rect);
            SMContentArangement argm     = this.ContentArangement;
            MNReferencedImage   refImage = null;
            Rectangle           imgRect  = bounds;

            Image image = GetContentImage(out refImage);

            if (image == null)
            {
                argm = SMContentArangement.TextOnly;
            }

            if (ExpectedChecked != Bool3.Undef)
            {
                DrawStyledBackground(context, layout, bounds);
            }

            if (argm == SMContentArangement.ImageOnly)
            {
                SMContentScaling scaling = ContentScaling;
                Rectangle        rc      = DrawImage(context, layout, bounds, image, scaling, SourceOffsetX, SourceOffsetY);
                if (ContentScaling == SMContentScaling.Fill)
                {
                    showRect   = bounds;
                    sourceRect = rc;
                }
                else
                {
                    showRect   = rc;
                    sourceRect = new Rectangle(0, 0, image.Width, image.Height);
                }
            }
            else
            {
                Size   textSize  = Size.Empty;
                Font   usedFont  = GetUsedFont();
                string plainText = Text.Length > 0 ? Text : DroppedText;
                if (plainText.IndexOf("_") >= 0 && DroppedTag.Length > 0)
                {
                    plainText = plainText.Replace("_", DroppedTag);
                }
                if (plainText.Length != 0)
                {
                    textSize = rt.MeasureString(context, plainText, bounds.Width);
                }

                Rectangle textRect = bounds;

                if (argm == SMContentArangement.ImageAbove)
                {
                    textRect.Height = textSize.Height;
                    textRect.Y      = bounds.Bottom - textRect.Height;
                    textRect.X      = (textRect.Left + textRect.Right) / 2 - textSize.Width / 2;
                    textRect.Width  = textSize.Width;
                    imgRect.Height  = bounds.Height - textRect.Height - ContentPadding.Top;
                }
                else if (argm == SMContentArangement.ImageBelow)
                {
                    textRect.Height = textSize.Height;
                    textRect.X      = (textRect.Left + textRect.Right) / 2 - textSize.Width / 2;
                    textRect.Width  = textSize.Width;
                    imgRect.Y       = textRect.Bottom + ContentPadding.Bottom;
                    imgRect.Height  = bounds.Height - textRect.Height - ContentPadding.Bottom;
                }
                else if (argm == SMContentArangement.ImageOnLeft)
                {
                    textRect.Width = textSize.Width;
                    textRect.X     = bounds.Right - textSize.Width;
                    imgRect.Width  = bounds.Width - textSize.Width - ContentPadding.Left;
                }
                else if (argm == SMContentArangement.ImageOnRight)
                {
                    textRect.Width = textSize.Width;
                    imgRect.X      = textRect.Right + ContentPadding.Right;
                    imgRect.Width  = bounds.Width - textSize.Width - ContentPadding.Right;
                }
                else if (argm == SMContentArangement.ImageOnly)
                {
                    textRect = Rectangle.Empty;
                }
                else if (argm == SMContentArangement.TextOnly)
                {
                    imgRect = Rectangle.Empty;
                }


                if (!imgRect.IsEmpty)
                {
                    Rectangle rc = DrawImage(context, layout, imgRect, image, ContentScaling, SourceOffsetX, SourceOffsetY);
                    if (ContentScaling == SMContentScaling.Fill)
                    {
                        showRect   = imgRect;
                        sourceRect = rc;
                    }
                    else
                    {
                        showRect   = rc;
                        sourceRect = new Rectangle(0, 0, image.Width, image.Height);
                    }
                }

                if (!textRect.IsEmpty)
                {
                    if (argm == SMContentArangement.TextOnly)
                    {
                        DrawStyledBorder(context, layout, bounds);
                    }
                    textRect.Inflate(2, 2);
                    rt.DrawString(context, layout, plainText, textRect);
                }
            }

            if (!imgRect.IsEmpty && refImage != null && refImage.HasSpots())
            {
                foreach (MNReferencedSpot rs in refImage.SafeSpots)
                {
                    if (rs.ContentType != SMContentType.TaggedArea)
                    {
                        continue;
                    }
                    if (rs.UIStateHighlighted || (HoverSpot == rs))
                    {
                        rs.Paint(context.g, showRect, false, context.SpotAreaBorderPen, null);
                    }
                }
            }

            if (UIStateError == MNEvaluationResult.Incorrect && UIStateChecked)
            {
                if (Document.HasViewer)
                {
                    Document.Viewer.ScheduleCall(MNNotificationCenter.RectifyDelay, this, "clearCheck");
                }
            }

            base.Paint(context);
        }
Exemplo n.º 13
0
        public override void ExportToHtml(MNExportContext ctx, int zorder, StringBuilder sbHtml, StringBuilder sbCss, StringBuilder sbJS)
        {
            SMImage   pi   = this;
            Rectangle rect = Area.RelativeArea;

            SMStatusLayout layout = PrepareBrushesAndPens();

            Rectangle           bounds   = ContentPadding.ApplyPadding(rect);
            SMContentArangement argm     = this.ContentArangement;
            MNReferencedImage   refImage = null;
            Rectangle           imgRect  = bounds;

            Image image = GetContentImage(out refImage);

            if (image == null)
            {
                argm = SMContentArangement.TextOnly;
            }


            /*if (argm == SMContentArangement.ImageOnly)
             * {
             *  SMContentScaling scaling = ContentScaling;
             *  Rectangle rc = DrawImage(context, layout, bounds, image, scaling, SourceOffsetX, SourceOffsetY);
             *  if (ContentScaling == SMContentScaling.Fill)
             *  {
             *      showRect = bounds;
             *      sourceRect = rc;
             *  }
             *  else
             *  {
             *      showRect = rc;
             *      sourceRect = new Rectangle(0, 0, image.Width, image.Height);
             *  }
             * }
             * else
             * {*/
            /*Size textSize = Size.Empty;
             * Font usedFont = GetUsedFont();*/
            string plainText = Text.Length > 0 ? Text : DroppedText;

            if (plainText.IndexOf("_") >= 0 && DroppedTag.Length > 0)
            {
                plainText = plainText.Replace("_", DroppedTag);
            }

            /*if (plainText.Length != 0)
             * {
             *  textSize = rt.MeasureString(context, plainText, bounds.Width);
             * }
             *
             * Rectangle textRect = bounds;
             *
             *
             *
             * if (argm == SMContentArangement.ImageAbove)
             * {
             *  textRect.Height = textSize.Height;
             *  textRect.Y = bounds.Bottom - textRect.Height;
             *  textRect.X = (textRect.Left + textRect.Right) / 2 - textSize.Width / 2;
             *  textRect.Width = textSize.Width;
             *  imgRect.Height = bounds.Height - textRect.Height - ContentPadding.Top;
             * }
             * else if (argm == SMContentArangement.ImageBelow)
             * {
             *  textRect.Height = textSize.Height;
             *  textRect.X = (textRect.Left + textRect.Right) / 2 - textSize.Width / 2;
             *  textRect.Width = textSize.Width;
             *  imgRect.Y = textRect.Bottom + ContentPadding.Bottom;
             *  imgRect.Height = bounds.Height - textRect.Height - ContentPadding.Bottom;
             * }
             * else if (argm == SMContentArangement.ImageOnLeft)
             * {
             *  textRect.Width = textSize.Width;
             *  textRect.X = bounds.Right - textSize.Width;
             *  imgRect.Width = bounds.Width - textSize.Width - ContentPadding.Left;
             * }
             * else if (argm == SMContentArangement.ImageOnRight)
             * {
             *  textRect.Width = textSize.Width;
             *  imgRect.X = textRect.Right + ContentPadding.Right;
             *  imgRect.Width = bounds.Width - textSize.Width - ContentPadding.Right;
             * }
             * else if (argm == SMContentArangement.ImageOnly)
             * {
             *  textRect = Rectangle.Empty;
             * }
             * else if (argm == SMContentArangement.TextOnly)
             * {
             *  imgRect = Rectangle.Empty;
             * }
             *
             *
             * if (!imgRect.IsEmpty)
             * {
             *  Rectangle rc = DrawImage(context, layout, imgRect, image, ContentScaling, SourceOffsetX, SourceOffsetY);
             *  if (ContentScaling == SMContentScaling.Fill)
             *  {
             *      showRect = imgRect;
             *      sourceRect = rc;
             *  }
             *  else
             *  {
             *      showRect = rc;
             *      sourceRect = new Rectangle(0, 0, image.Width, image.Height);
             *  }
             *
             * }
             *
             * if (!textRect.IsEmpty)
             * {
             *  if (argm == SMContentArangement.TextOnly)
             *  {
             *      DrawStyledBorder(context, layout, bounds);
             *  }
             *  textRect.Inflate(2, 2);
             *  rt.DrawString(context, layout, plainText, textRect);
             * }
             * }*/

            /*if (!imgRect.IsEmpty && refImage != null && refImage.HasSpots())
             * {
             *  foreach (MNReferencedSpot rs in refImage.SafeSpots)
             *  {
             *      if (rs.ContentType != SMContentType.TaggedArea) continue;
             *      if (rs.UIStateHighlighted || (HoverSpot == rs))
             *      {
             *          rs.Paint(context.g, showRect, false, context.SpotAreaBorderPen, null);
             *      }
             *  }
             * }*/

            string blockFormat = Font.HtmlString() + Paragraph.Html() + ContentPaddingHtml() + "position:absolute;" + Area.HtmlLTRB();

            sbCss.AppendFormat(".c{0}n {{ {1} {2} }}\n", Id, HtmlFormatColor(false), blockFormat);
            sbCss.AppendFormat(".c{0}h {{ {1} {2} }}\n", Id, HtmlFormatColor(true), blockFormat);
            string imgText = "", textText = "";



            if (argm != SMContentArangement.TextOnly)
            {
                imgText = string.Format("<td><img src=\"{1}\" style='object-fit:contain;width:100%;height:100%'></td>\n", Id, ctx.GetFileNameFromImage(refImage));
            }
            if (argm != SMContentArangement.ImageOnly)
            {
                // wrapping text into vertical/horizontal alignment DIV
                textText  = "<td>";
                textText += plainText;
                textText += "</td>\n";
            }

            switch (argm)
            {
            case SMContentArangement.ImageAbove:
                sbHtml.AppendFormat("  <table class=\"c{0}n\">\n", Id);
                sbHtml.Append("<tr>");
                sbHtml.Append(imgText);
                sbHtml.Append("<tr>");
                sbHtml.Append(textText);
                sbHtml.Append("</table>\n");
                break;

            case SMContentArangement.ImageBelow:
                sbHtml.AppendFormat("  <table class=\"c{0}n\">\n", Id);
                sbHtml.Append("<tr>");
                sbHtml.Append(textText);
                sbHtml.Append("<tr>");
                sbHtml.Append(imgText);
                sbHtml.Append("</table>\n");
                break;

            case SMContentArangement.ImageOnLeft:
                sbHtml.AppendFormat("  <table class=\"c{0}n\">\n", Id);
                sbHtml.Append("<tr>");
                sbHtml.Append(imgText);
                sbHtml.Append(textText);
                sbHtml.Append("</table>\n");
                break;

            case SMContentArangement.ImageOnRight:
                sbHtml.AppendFormat("  <table class=\"c{0}n\">\n", Id);
                sbHtml.Append("<tr>");
                sbHtml.Append(textText);
                sbHtml.Append(imgText);
                sbHtml.Append("</table>\n");
                break;

            case SMContentArangement.TextOnly:
                sbHtml.AppendFormat("  <table class=\"c{0}n\">\n", Id);
                sbHtml.Append("<tr>");
                sbHtml.Append(textText);
                sbHtml.Append("</table>\n");
                break;

            case SMContentArangement.ImageOnly:
                sbHtml.AppendFormat("  <div class=\"c{0}n\">\n", Id);
                sbHtml.Append(imgText);
                sbHtml.Append("</div>\n");
                break;
            }
        }
Exemplo n.º 14
0
        public void Load(RSFileReader br)
        {
            if (!br.ReadHeader(p_fileHeader))
            {
                throw new Exception("Invalid header for book file");
            }

            Version = 1;
            byte b;

            while ((b = br.ReadByte()) != 0)
            {
                switch (b)
                {
                case 5:
                    sizeOfInt = br.ReadByte();
                    break;

                case 10:
                    BookTitle = br.ReadString();
                    break;

                case 11:
                    BookCode = br.ReadString();
                    break;

                case 12:
                    BookAuthor = br.ReadString();
                    break;

                case 13:
                    BookPublisher = br.ReadString();
                    break;

                case 14:
                    BookCopyright = br.ReadString();
                    break;

                case 15:
                    BookCollection = br.ReadString();
                    break;

                case 16:
                    BookColor = br.ReadColor();
                    break;

                case 17:
                    StartPage = br.ReadString();
                    break;

                case 18:
                    BookImageRef = new MNReferencedImage();
                    BookImageRef.Load(br);
                    break;

                case 19:
                    Evaluation = (MNEvaluationType)br.ReadInt32();
                    break;

                case 20:
                    LastTimeSave = br.ReadString();
                    break;

                case 21:
                    WorkTime.SetTotalWorkTime(br.ReadInt64());
                    break;

                case 22:
                    BookPriority = br.ReadInt32();
                    break;

                case 23:
                    HomePage = br.ReadString();
                    break;

                case 24:
                    Version = br.ReadInt32();
                    break;

                case 25:
                    DefaultFontSize = br.ReadInt32();
                    break;

                case 26:
                    DefaultFontName = MNFontName.IntToString(br.ReadInt32());
                    break;

                case 27:
                    DefaultFontName = br.ReadString();
                    break;
                }
            }
        }