Attribute VB_Name = "Bas_Main"
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Declare Function GetKeyState Lib "user32" (ByVal KeyCode As Long) As Long
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Declare Function StretchBlt Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Public Const SRCAND = &H8800C6
Public Const SRCCOPY = &HCC0020
Public Const SRCERASE = &H440328
Public Const SRCINVERT = &H660046
Public Const SRCPAINT = &HEE0086

Public CurrentMap(0 To 15, 0 To 500) As Integer
Public Warp(1 To 5) As AWarp
Public Selected(0 To 15, 0 To 500) As Boolean

Public PosX As Integer
Public PosY As Integer


'for the scroll bar
Public Scroll As Integer
Public ScrollY As Integer
Public LeftDown As Boolean
Public RightDown As Boolean
Public UpDown As Boolean
Public DownDown As Boolean
Public TabDown As Boolean
Public TabDownVert As Boolean
Public TheX As Integer
Public TheY As Integer

Public PX As Integer
Public PY As Integer

Public Zoom As Integer
Public Mode As Integer

Public Const mode_Build = 0
Public Const mode_Edit = 1

Public ConversionTable(0 To 200) As Integer

Public PathF As String
Public FileSaved As Boolean
Public FileEdit As Boolean
Public MapName As String
Public ScrollingH As Boolean
Public ScrollingV As Boolean


'TYPES
Public Type AWarp
  'the position you warp to
  WarpToX As Integer
  WarpToY As Integer
  
  'the type of the way
  Type As Integer
  
  'the transisition type
  Trans As Integer
  
  'the new map color / type
  NewBG As Integer
  NewType As Integer
  
  'the tile positions & width & height of the warp
  PosX As Integer
  PosY As Integer
  Width As Integer
  Height As Integer
  
  'in use
  Active As Boolean
End Type

Public Type RGBVals
  Red As Long
  Green As Long
  Blue As Long
End Type

'SAVE A STRING TO AN ASCII FILE
Public Sub SaveF(Path As String, ToWrite As String)
  Open Path For Output As 1
    Write #1, (ToWrite)
  Close 1
End Sub

'RETURN A STRING FROM OPENING AN ASCII FILE
Public Function OpenF(Path As String)
  Open Path For Input As 1
    OpenF = Input(LOF(1), 1)
  Close 1
End Function

'RETURNS A TYPE RGB FOR THE COLOR THAT WAS PASSED..
Public Function GetRGB(RGBVal As Long) As RGBVals 'this sub gets the rgb vals from a rgb long
  Dim R As Long
  Dim G As Long
  Dim B As Long
  Dim Dbl As Double
  
  Dim TempRGBVal As Long
  
  TempRGBVal = RGBVal
  Dbl = (TempRGBVal / 256) / 256
  B = RoundDown(Dbl)
  Dbl = (TempRGBVal - (B * 256 * 256)) / 256
  'If G > 255 Then G = 255
  G = RoundDown(Dbl)
  Dbl = (TempRGBVal - (B * 256 * 256) - G * 256)
  R = RoundDown(Dbl)
  'MsgBox "Your RGB Values Are: R = " & R & "; G = " & G & "; B = " & B & ".", vbOKOnly, "RGB Values": Exit Function
  
  GetRGB.Red = R
  GetRGB.Green = G
  GetRGB.Blue = B

End Function

'ROUNDS A DECIMAL DOWN TO THE LOWEST INT
Function RoundDown(ToRound As Double) As Long 'this funcion rounds down, no matter what ie 1.9 = 1
  Dim Temp As Double

  Temp = Round(ToRound) 'rounds the float passed and stores it to another var.
  If Temp > ToRound Then Temp = Temp - 1 'if the rounded version is greater than the original (ie: 1.9-->2 and 2>1.9) then it rounded up.. so it subtracts one to go back down
  RoundDown = Temp 'returns the rounded down var

End Function

'MAKES ANYTHIGN LESS THAN 0, ZERO, ELSE JUST RETURNTS IT
Public Function Zero(Number As Long) As Long
  
  'return 0 if less than 0..
  If Number < 0 Then
    Zero = 0
  Else
    Zero = Number
  End If
  
End Function
