Ejemplo n.º 1
0
 private void MapEditor_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.ControlKey)
     {
         Bitmap curs = new Bitmap(selection_Obj.Image);
         if (!isNoItmObj(selection_Obj.Name) && selection_Itm.Image != null)
         {
             using (Graphics g = Graphics.FromImage(curs))
             {
                 Rectangle r = new Rectangle(0, curs.Height - 16, 16, 16);
                 g.DrawImage((Bitmap)selection_Itm.Image, r);
             }
         }
         pnMapViewer.Cursor = CustomCursor.CreateCursor(curs, 16, selection_Obj.Image.Height - 16);
         if (pb_background != null)
         {
             pb_background.Invalidate();
         }
     }
     else if (e.KeyCode == Keys.ShiftKey)
     {
         Bitmap bm = (Bitmap)global::MapEditor.Properties.Resources.eraser;
         pnMapViewer.Cursor = CustomCursor.CreateCursor(bm, 16, bm.Height - 16);
         if (pb_background != null)
         {
             pb_background.Invalidate();
         }
     }
 }
Ejemplo n.º 2
0
        public static Cursor CreateCursorFromFile(string folder, string filename, int cursorWidth, int cursorHeight)
        {
            Image image = null;

            try
            {
                image = Image.FromFile(folder + "\\Images\\Cursor\\" + filename);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Hum. Maybe some thing error, i will fix it later!");
            }

            Bitmap   bitmap = new Bitmap(cursorWidth, cursorHeight);
            Graphics g      = Graphics.FromImage((Image)bitmap);

            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.DrawImage(image, 0, 0, cursorWidth, cursorHeight);
            g.Dispose();
            int    spotX = bitmap.Width / 2;
            int    spotY = bitmap.Height / 2;
            Cursor c     = CustomCursor.CreateCursor(bitmap, spotX, spotY);

            return(c);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Change mouse image when enter map's area
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void picbMap_MouseEnter(object sender, EventArgs e)
 {
     //Cursor is inside map area
     isInside = true;
     if (picSelected != null && currMode == CursorMode.draw)
     {
         //Change cursor to current selected object's image
         Bitmap bitmap = new Bitmap(picSelected.Image);
         curCursor   = CustomCursor.CreateCursor(bitmap, 1, 1);
         this.Cursor = curCursor;
         bitmap.Dispose();
     }
 }
Ejemplo n.º 4
0
        private void worldMap_Click(object sender, EventArgs e)
        {
            try
            {
                MouseEventArgs eM = e as MouseEventArgs;
                if (eM.Button == MouseButtons.Left)
                {
                    Point ip = new Point(eM.X, eM.Y);

                    if (Control.ModifierKeys == Keys.Control)
                    {
                        if (selection_Obj != null)
                        {
                            if (cbAutoAlign.Checked)
                            {
                                ip.X = ip.X / 32 * 32;
                                ip.Y = (ip.Y / 32 + 1) * 32;
                                if (selection_Obj.Image.Height < 32)
                                {
                                    ip.Y -= 32 - selection_Obj.Image.Height;
                                }
                            }
                            else
                            {
                                ip.X -= 16;
                                ip.Y += 16;
                            }
                            ip.Y = y_Axis - ip.Y;

                            Objects tmpObj = getObjectsAtPos(ip.X, ip.Y);
                            if (tmpObj != null)
                            {
                                if (tmpObj.getTypeNameById() == selection_Obj.Name && tmpObj.Point == ip)
                                {
                                    return;
                                }
                            }
                            add(ip);
                            if (cbRandomItm.Checked)
                            {
                                Random rnd = new Random();
                                int    r   = rnd.Next(listItm.Count);
                                change_Itm(listItm[r].Name);

                                Bitmap curs = new Bitmap(selection_Obj.Image);
                                if (!isNoItmObj(selection_Obj.Name) && selection_Itm.Image != null)
                                {
                                    using (Graphics g = Graphics.FromImage(curs))
                                    {
                                        Rectangle re = new Rectangle(0, curs.Height - 16, 16, 16);
                                        g.DrawImage((Bitmap)selection_Itm.Image, re);
                                    }
                                }
                                pnMapViewer.Cursor = CustomCursor.CreateCursor(curs, 16, selection_Obj.Image.Height - 16);
                            }
                        }
                    }
                    else if (Control.ModifierKeys == Keys.Shift)
                    {
                        Objects tmpObj = getObjectsAtPos(eM.X, y_Axis - eM.Y);
                        if (tmpObj == null)
                        {
                            return;
                        }
                        worldmap.ListObject.Remove(tmpObj);
                    }
                    else
                    {
                        Objects tmpObj = getObjectsAtPos(eM.X, y_Axis - eM.Y);
                        if (tmpObj == null)
                        {
                            return;
                        }
                        if (currentObj != tmpObj)
                        {
                            currentObj       = tmpObj;
                            this.tbPosX.Text = currentObj.Point.X.ToString();
                            this.tbPosY.Text = currentObj.Point.Y.ToString();
                            this.tbVar1.Text = currentObj.Value_1.ToString();
                            this.tbVar2.Text = currentObj.Value_2.ToString();
                            this.tbVar3.Text = currentObj.Value_3.ToString();
                            change_Obj(currentObj.getTypeNameById());
                            change_Itm(currentObj.getItemNameById());

                            rect.X      = currentObj.Point.X;
                            rect.Y      = y_Axis - currentObj.Point.Y - currentObj.Size.Height;
                            rect.Width  = currentObj.Size.Width;
                            rect.Height = currentObj.Size.Height;
                        }
                    }

                    pb_background.Invalidate();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Nhập số hợp lệ cho các textbox!\n");
            }
        }