Hi, it's been awhile since i have used vb 6.0 so please be patient with me. ty
basically i am trying to make a tileset helper kinda thing...
so on the left i want to have the png tileset loaded with vertical scrollbar - each tile has to be clickable
on the right i want a result a result in say a textbox...
IE:
IMG xxxoxxxo
to better get an example:
i use RPG MAKER XP, and the project i am trying to accomplish is making tilesets mapable (right side as mentioned above) so other people can map out their tilesets. because people create tilesets but do not give mapouts - (the X's and O's and such).
the project must have a way to find a PNG image, the image must be vertically scrollable - the image is 8x32=256 wide
i really don't know how to explain the project any better/clearer - but if you have any questions feel free to ask.
basically i am trying to make a tileset helper kinda thing...
so it's a vb thing...
i wanna make a tileset helper thing with vb.. i need to know how to have a vertical scrolling image thing as shown.. and the image be clickable to be able to put a O or X or back to blank.. as you click each tile it will also put out to the right in a listbox or text the same info.. O, X, BLANK...
i showed the rpg maker pic so people would get the exact idea of what i'm trying to make..
you should post some code showing what you've tried, and explaining your exact problems.
so far all you've done is outline a generic app, without any specifics except what format the input file is, and that it needs a vertical scroll bar.
Part of the solution depends on how a user would provide "mapouts".
Is there some standard structure being used to define "mapouts" for a tile set?
As for scrolling the tileset, you would just load the image in a picturebox. The scrollbar would move the location of the picturebox up and down.
You would use the position of where the mouse was clicked in the picturebox and a bit of math to determine which tile was clicked on.
Is the tile set coordinates specified as two dimensions, or a linear index? Likewise, the mapout structure being two dimension or linear.
Assuming you have a "mapout" structure, what enumeration is used for "clear", "0" and "X"?
across is 8 (32x32) = 256
vertically it's unlimited - but you need a scrollbar obviously..
picturebox does not have vscroll or hscroll for that matter.. i just want the same exact thing as shown above.. minus those buttons for now..
as far as coding, i haven't done any cause first i need the image to be scrollable which picturebox does not have.
as for "standard" structure.. again, each 32x32 tile is to be clickable and that would place a "O" or "X" or back to nothing over each tile = and to the right there would be a listbox or whatever everytime you click it would put that indicator in there..
IE:
PICTURE AS SHOWN IN POST 1 LISTBOX OR WHATEVER
o, blank, o, x, x, blank, blank, x o, blank, o, x, x, blank, blank, x
o, blank, o, x, x, blank, blank, x o, blank, o, x, x, blank, blank, x
o, blank, o, x, x, blank, blank, x o, blank, o, x, x, blank, blank, x
and so on.. if you make a change on a tile, then it will also reflect in the listbox
so i dunno how to any of this, i would appreciate it if somebody would help me out to accomplish this project.
that's exactly what i'm looking for.. however, there won't be a pic already there.. end user will have to find/open their own image.. but the image will have O's on every tile by default... and i was wrong about X,O, BLANK it's X, O and a SQUARE..
can you be able to make the x's,o's and squares also appear over the image tiles too?
but yeah you nailed the right side for sure! is the left side always going to match the length of the image regardless what image they open?
Code:
Private Const TileWidth As Long = 40 ' According to the map picture used in this project
Private Const TileHeight As Long = 40
Private Const ColumnsCount As Long = 8
apparently not.. can that be self-calculating based on image opened?
Last edited by elRuffsta; Dec 8th, 2017 at 08:13 PM.
too bad it doesn't make a square in the textbox - it's either x, o, .
that's all i can say - i just wanna change the way end user gets the image.. so i'll try to do dir1, filelist, drive - in a separate form so when i click file in the menu but place the picture in this form in picMap.. although i was trying that earlier and it wasn't working for me.. i must be doing something silly wrong too..
it won't let me rate yer post so i gave a big bow gif lol and ty for your help.. much appreciated!
Last edited by elRuffsta; Dec 9th, 2017 at 12:44 AM.
sorry.. wrote something but then changed my mind.. can't delete post so.. lol
anyways.. i'm having an issue:
Code:
Private Sub mnuOpen_Click()
CommonDialog1.Filter = "Png Files (*.png)|*.png"
CommonDialog1.ShowOpen
Form1.picMap.Picture = LoadPicture(CommonDialog1.FileName) ' error, line gets highlighted yellow after i select a picture..
End Sub
i even tried this:
Code:
Private Sub mnuOpen_Click()
With picMap
CommonDialog1.Filter = "Png Files (*.png)|*.png"
CommonDialog1.ShowOpen
Form1.picMap.Picture = LoadPicture(CommonDialog1.FileName) 'same error
End With
End Sub
and this:
Code:
Private Sub mnuOpen_Click()
With picMap
CommonDialog1.Filter = "Png Files (*.png)|*.png"
CommonDialog1.ShowOpen
.Picture = LoadPicture(CommonDialog1.FileName) 'same error
End With
End Sub
Run-time error '481:'
Invalid picture
Last edited by elRuffsta; Dec 10th, 2017 at 08:47 PM.
There are hundreds of errors, what is the error you are talking about? I can guess it is "Invalid picture" because PNG format is not supported by VB6 Picture control, try JPG or GIF instead.
but you may wanna look at this: since you coded it...
and download this pic to use.. but use the app to find and open it to see.. png
it loads the png, however.. things just don't line up correctly (x,o, square)... and umm.. yeah the scrolling works backwards lol - i didn't touch yer code at all.. so best you look at it to see exactly what i'm talking about..
Last edited by elRuffsta; Dec 10th, 2017 at 09:50 PM.
Of course you must update TileWidth, TileHeight and aMap each time you load new picture, all you need is:
1- Replace mnuOpen_Click sub with
Code:
Private Sub mnuOpen_Click()
Dim token As Long
token = InitGDIPlus
CommonDialog1.Filter = "Graphic Files (*.png)|*.png"
CommonDialog1.ShowOpen
Form1.picMap.Picture = LoadPictureGDIPlus(CommonDialog1.FileName)
FreeGDIPlus token
' Update TileWidth, TileHeight and aMap array size
TileWidth = picMap.Width \ ColumnsCount
TileHeight = TileWidth
Erase aMap
ReDim aMap(ColumnsCount * (picMap.Height \ TileHeight))
DrawData
ShowData
End Sub
2- Replace ScrollPicture sub with
Code:
Private Sub ScrollPicture()
If picMap.Height > picClient.Height Then
picMap.top = -((picMap.Height - picClient.Height) * VScroll1.Value) / VScroll1.Max
Else
picMap.top = ((picMap.Height - picClient.Height) * VScroll1.Value) / VScroll1.Max
End If
End Sub
i have the image scrolled all the way down and marked the very last tile and the right side scrolled down.. does not match the.. the scrollbar also goes goes back to the top - i guess after refreshing? should really only change when i click on another tile - matching at all times
like there's more dots on the right than the image?? or the image isn't being scrolled all the way down, but the scrollbar stops..
and you have to max the form to see all the image with scroll and i still don't think it's scrolling all the way down.. scroll only goes so far down, then you have to max the form to finish scrolling lol
NOTE:
yeah, i believe it's the scrollbar itself is not scrolling all the way down.. form maxed, scrollbar all the way down.. but not scrolling the full image.
Last edited by elRuffsta; Dec 10th, 2017 at 10:51 PM.
Apparently there is a bug trying to move the picturebox with really tall pictures in them.
Your image is 17152 pixels in height.
When you change the .Top property of the picturebox to move its location, the picturebox's height is truncated to 16383 pixels (looking suspiciously like a size related to 16384, which is 2^14).
This seems to happen regardless of whether AutoSize is set to True or False, and regardless of whether the picture is a .png file or a .bmp file.
You may have to resort to loading the picture in a bitmap (could be in a hidden picturebox) and using PaintPicture or bitblt to implement scrolling rather than moving a picturebox.
As an example, I've modified your existing code a little bit to use PaintPicture to implement the scrolling.
The code is changed to set picMap.Visible to False since we no longer need to see it. We will still load the picture into it and draw on it using the existing code.
We'll use picClient to show a portion of the image from picMap, so we set picClient.AutoRedraw to True.
The ScrollPicture sub is changed to paint a portion of picMap into picClient rather than move the picturebox.
Code:
Private Sub ScrollPicture()
picTop = ((17152 - picClient.Height) * VScroll1.Value) / VScroll1.Max
picClient.Cls
picClient.PaintPicture picMap.Image, 0, 0, picClient.Width, picClient.Height, 0, picTop, picClient.Width, picClient.Height
picClient.Refresh
End Sub
I went ahead and set Scroll1.Max to 10000 to give us smoother scrolling.
I changed the DrawData sub to call ScrollChange at the end of the sub to refresh the drawing when you make a change.
I changed the MouseUp sub to be for picClient since picMap is no longer visible, just adding the Y offset to the Y click position so the position is relative to the portion of picMap being shown.
I think that's about it for the important changes. Here's the full form code so you can just paste it in to replace your existing form code to try it out.
You will see that you can scroll down to the bottom of the full tall image now. Probably something you would want to change is to set the scroll max based on the size of the image, and have no scrolling if the map was smaller than your client window.
Code:
Option Explicit
Private TileWidth As Long
Private TileHeight As Long
Private Const ColumnsCount As Long = 8 'try with different values e.g. 6, 10, 11 or according to column in your image
Private picTop As Integer
Private aMap() As Integer
Private Sub Form_Load()
Me.ScaleMode = vbPixels
picClient.ScaleMode = vbPixels
picClient.AutoRedraw = True
picMap.Visible = False
With picMap
.ScaleMode = vbPixels
.AutoSize = True
.AutoRedraw = True
.BorderStyle = 0
.Picture = LoadPicture(App.Path & "\sample.jpg") ' try with different images
.Move 0, 0
TileWidth = .Width \ ColumnsCount
TileHeight = TileWidth
' TileHeight = .Height \ ColumnsCount ' uncomment if you don't want square tiles
End With
With picClient
.BorderStyle = 0
.Width = picMap.Width
.Height = 600
End With
VScroll1.Min = 0
VScroll1.Max = 10000
VScroll1.LargeChange = 32
VScroll1.Move picClient.left + picClient.Width, picClient.top, 17, picClient.Height
Text1.Move VScroll1.left + VScroll1.Width, picClient.top, picClient.Width, picClient.Height
ReDim aMap(ColumnsCount * (picMap.Height \ TileHeight))
DrawData
ShowData
End Sub
Private Sub mnuOpen_Click()
Dim Token As Long
Token = InitGDIPlus
CommonDialog1.Filter = "Graphic Files (*.png)|*.png"
CommonDialog1.ShowOpen
picMap.AutoSize = True
picMap.top = -1
Form1.picMap.Picture = LoadPictureGDIPlus(CommonDialog1.FileName)
FreeGDIPlus Token
' Update TileWidth, TileHeight and aMap array size
TileWidth = picMap.Width \ ColumnsCount
TileHeight = TileWidth
Erase aMap
ReDim aMap(ColumnsCount * (picMap.Height \ TileHeight))
DrawData
ShowData
picMap.AutoSize = False
End Sub
Private Sub picClient_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim tx As Long
Dim ty As Long
tx = x \ TileWidth
ty = (y + picTop) \ TileHeight
Me.Caption = tx & ", " & ty & " has been clicked"
aMap(tx + (ty * ColumnsCount)) = (aMap(tx + (ty * ColumnsCount)) + 1) Mod 3
DrawData
ShowData
End Sub
Private Sub VScroll1_Change()
ScrollPicture
End Sub
Private Sub VScroll1_Scroll()
ScrollPicture
End Sub
Private Sub ScrollPicture()
picTop = ((17152 - picClient.Height) * VScroll1.Value) / VScroll1.Max
picClient.Cls
picClient.PaintPicture picMap.Image, 0, 0, picClient.Width, picClient.Height, 0, picTop, picClient.Width, picClient.Height
picClient.Refresh
End Sub
Private Sub ShowData()
Dim t As String
Dim j As Long
Dim k As Long
For j = 0 To UBound(aMap) - ColumnsCount Step ColumnsCount
For k = 0 To ColumnsCount - 1
If aMap(j + k) = 0 Then
t = t & ". "
ElseIf aMap(j + k) = 1 Then
t = t & "O "
Else
t = t & "X "
End If
Next
t = t & vbNewLine
Next
Text1.Text = t
End Sub
Private Sub DrawData()
Dim j As Long
Dim k As Long
Dim x As Long
Dim y As Long
picMap.Cls
picMap.DrawWidth = 3
For j = 0 To UBound(aMap) - ColumnsCount Step ColumnsCount
For k = 0 To ColumnsCount - 1
If aMap(j + k) = 0 Then
picMap.Line (x + (TileWidth \ 4), y + (TileHeight \ 4))-Step(TileWidth \ 2, TileHeight \ 2), vbBlack, B
ElseIf aMap(j + k) = 1 Then
picMap.Circle (x + (TileWidth \ 2), y + (TileHeight \ 2)), TileWidth \ 4, vbBlack
Else
picMap.Line (x + (TileWidth \ 4), y + (TileHeight \ 4))-Step(TileWidth \ 2, TileHeight \ 2), vbBlack
picMap.Line (x + (TileWidth \ 4) + (TileWidth \ 2), y + (TileHeight \ 4))-Step(-(TileWidth \ 2), TileHeight \ 2), vbBlack
End If
x = x + TileWidth
Next
x = 0
y = y + TileHeight
Next
ScrollPicture
End Sub
p.s. As for the textbox issue, a quick patch that would keep the textbox "in the neighborhood" of where you're scrolling the image would be to add a line like this at the bottom of the picClient_MouseUp sub:
But a better solution might be to use a picturebox and draw the characters for the current scroll window in that picturebox so you can easily space them and keep them in sync with the image while scrolling.
Another option, depending on what the text is actually suppose to look like, is to not have all the characters in the string in the textbox, but just show the substring that corresponds to the portion of the image that is showing. In that case you wouldn't have a scrollbar on the textbox, you would just update the textbox with the relevant part of the string (the rows) currently showing from the image.
As an example, of just printing a subset of the characters to the textbox for portion of the image showing, you can try these updated subs.
Code:
Private Sub ScrollPicture()
picTop = ((17152 - picClient.Height) * VScroll1.Value) / VScroll1.Max
picClient.Cls
picClient.PaintPicture picMap.Image, 0, 0, picClient.Width, picClient.Height, 0, picTop, picClient.Width, picClient.Height
picClient.Refresh
ShowData
End Sub
Private Sub ShowData()
Dim t As String
Dim j As Long
Dim k As Long
Dim firstRow As Long
Dim firstChar As Long
Dim lastChar As Long
firstRow = picTop \ TileHeight
firstChar = firstRow * ColumnsCount
lastChar = firstChar + 19 * ColumnsCount '19 is max number of rows shown (assuming 32 pixels)
If lastChar > UBound(aMap) Then lastChar = UBound(aMap)
' For j = 0 To UBound(aMap) - ColumnsCount Step ColumnsCount
For j = firstChar To lastChar - ColumnsCount Step ColumnsCount
For k = 0 To ColumnsCount - 1
If aMap(j + k) = 0 Then
t = t & ". "
ElseIf aMap(j + k) = 1 Then
t = t & "O "
Else
t = t & "X "
End If
Next
t = t & vbNewLine
Next
Text1.Text = t
End Sub
Last edited by passel; Dec 11th, 2017 at 10:42 PM.