Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Jackieryder

Pages: [1]
1
DotNet / (Help) User draw/paint pixels by pixels?
« on: March 30, 2015, 09:19:18 am »
Hi, I'm trying to create a paint software of sort. I was able to do it with the following code, however it proved to be super slow and seem to be very very inefficient; do you guys have any suggestion on how to improve it or to make it faster?

In Constructor:
 
imagePixels = new byte[1612900]; // 1612900 = 635 * 635 * 4

drawn = new SFML.Graphics.Image(635, 635, imagePixels);
drawnImage = new Texture(drawn);



In drawing loop: (toDraw is a sprite)

 
DrawWindow.DispatchEvents();
DrawWindow.Clear(SFML.Graphics.Color.Black);
ToDraw.Texture = drawnImage;
DrawWindow.Draw(ToDraw);
DrawWindow.Display();
 


In MouseMove:

 
private void OnMouseMove(object sender, MouseMoveEventArgs e)
        {
            RenderWindow window = (RenderWindow)sender;
            if (Mouse.IsButtonPressed(Mouse.Button.Left))
            {
                if (Mouse.GetPosition(DrawWindow).X >= 0 && Mouse.GetPosition(DrawWindow).Y > 0 && Mouse.GetPosition(DrawWindow).X < 635 && Mouse.GetPosition(DrawWindow).Y < 635)
                {
                    imagePixels[(Mouse.GetPosition(DrawWindow).Y * 635 + Mouse.GetPosition(DrawWindow).X) * 4] = MainViewer.Instance.PickedColor[0].R; // R?
                    imagePixels[(Mouse.GetPosition(DrawWindow).Y * 635 + Mouse.GetPosition(DrawWindow).X) * 4 + 1] = MainViewer.Instance.PickedColor[0].G; // G?
                    imagePixels[(Mouse.GetPosition(DrawWindow).Y * 635 + Mouse.GetPosition(DrawWindow).X) * 4 + 2] = MainViewer.Instance.PickedColor[0].B; // B?
                    imagePixels[(Mouse.GetPosition(DrawWindow).Y * 635 + Mouse.GetPosition(DrawWindow).X) * 4 + 3] = MainViewer.Instance.PickedColor[0].A; // A?
                    drawn = new SFML.Graphics.Image(635, 635, imagePixels);
                    drawnImage = new Texture(drawn);
                }
            }
        }
 

2
General / Scrollable chatbox/log box
« on: April 23, 2014, 05:52:24 am »
I'm trying to code a scrollable chatbox which include the up arrow, down arrow, and obviously a scroll inbetween the 2 to scroll the chat. Let put the detail of how I'm going to set up it aside, I'm running into a few problem on how to render the text and doing text wrap to new line.

So far I have in mind is that:

Pseudo code:

class LogMessage
public LogMessage(string msg)
{
CutMessageIntoABunchOfListBasedOnMaximumLength() // this will cut the log message into individual smaller string which is just long enough to fit in a text of the same width.
}

Draw(); // draw all the string in the list of string

I'm not so sure how to code the CutMessageIntoABunchOfListBasedOnMaximumLength at all

is there a specific way to get the amount of character in a string given a font and charactersize and the width?

THis is the first time I ever tried to recreate a scroll chatbox so my structure might be terribly bad, if you have any suggestion on how to code this, please do so

Thank you

3
DotNet / Handling event in c#
« on: July 28, 2013, 05:28:00 am »
As the title said, hwo do I handle event in c#? The C# pollevent is inaccessible due to its protection level, and the only thing available is DispatchEvent, which i dont know what to do

4
General / Draw speed
« on: July 24, 2013, 09:46:36 am »
Hi guy, I am making a RPG with SFML and window forms + C#'s picturebox toolbox. So umh, at the moment all my code run properly, they work as intended, but they are really slow;

Im not sure if it because of the way I code it, but my Tile Engine's Tile placement is extremely slow. Sometime it take up to 3 sec of unresponsive before the tile is actually placed. Sometime the program even crash from "not enough memory" and also crash my facebook messager skype and chrome. I am not an expert programmer, just a hobbyist so I do not have any knowledge on code optimization and such, so dont judge me on that. Here is the 2 functions that I think should have something to deal with the speed issue:


//The MapViewer class (which is abbreviated mv)

public void Render()
        {
            _mapWindow.Clear();

            foreach (TileLayer tl in _map.myLayer)
            {
                foreach (Tile t in tl.myTile)
                {                

                    Texture tx = new Texture(Editor.Instance.curGame.GM.myResource[Editor.Instance.curGame.TM.myTileset[t.TS].ID].myTexture);
                    Sprite sp = new Sprite(tx, new IntRect(t.srcX * Editor.Instance.curGame.TileX, t.srcY * Editor.Instance.curGame.TileY, t.Width, t.Height));
                    sp.Position = new Vector2f(t.plcX * Editor.Instance.curGame.TileX, t.plcY * Editor.Instance.curGame.TileY);
                    _mapWindow.Draw(sp);


                }
            }

            _mapWindow.Display();
        }



//In the actual form:

private void picMapViewer_Click(object sender, EventArgs e)
        {
            if (Map.myLayer.Count <= 0)
                return;

            //Editor.Instance.tilesetPick
            int pickedX = mv.getMouseLoc.X + mv.xOffSet;
            int pickedY = mv.getMouseLoc.Y + mv.yOffSet;
            if (pickedX >= Map.maxX * 32)
                pickedX = Map.maxX * 32 - 1;
            if (pickedY >= Map.maxY * 32)
                pickedY = Map.maxX * 32 - 1;

            pickedX /= 32;
            pickedY /= 32;

            Tile _newTile = new Tile(Editor.Instance.tilesetPick.PickedX, Editor.Instance.tilesetPick.PickedY, pickedX, pickedY, Editor.Instance.tilesetPick.CurTS, Editor.Instance.curGame.TileX, Editor.Instance.curGame.TileY, 100);
           
            if ((int)available[lstLayer.SelectedIndex].GetValue(pickedX, pickedY) < 0)
                Map.myLayer[lstLayer.SelectedIndex].addTile(_newTile);
            else
                Map.myLayer[lstLayer.SelectedIndex].addTile(_newTile, (int)available[lstLayer.SelectedIndex].GetValue(pickedX, pickedY));

            available[lstLayer.SelectedIndex].SetValue(Map.myLayer[lstLayer.SelectedIndex].myTile.Count - 1, pickedX, pickedY);

            mv.Render();

        }


 

Here is the program without the source code, try it and see it for yourself:

https://www.dropbox.com/s/3zw1jv7kag59ztq/Debug.rar

Thank you all

Pages: [1]