nomainwin global pickedColor, drawColor$, _ bmpHeight, bmpWidth, _ bitmap$, _ saveFile$, _ hBitmap, _ hWindow, _ buttonColor$, buttonClickColor$, buttonHovered, _ viewColor$, imageColor$, _ buttonWidth, buttonHeight global False, True call Init call InitButtons call MenuView sub Init bmpHeight = 0 'bitmap height bmpWidth = 0 'bitmap width bitmap$ = "" 'bitmap file name saveFile$ = "" 'save file name hBitmap = 0 'handle for loaded bitmap hWindow = 0 'window handle pickedColor = -1 'not yet a chosen color buttonColor$ = "200 167 36" buttonClickColor$ = "255 255 0" buttonHovered = 0 viewColor$ = "165 224 231" imageColor$ = "white" buttonWidth = 300 buttonHeight = 50 False = 0 True = 1 dim buttons(3, 1) 'BackMenu, SpriteMaskMaker, Help, ExitProgram dim pixels(0, 0) 'na sprite laden wordt de array bepaald end sub sub InitButtons buttons(0, 0) = WindowWidth - 400 'x positie voor BackMenu buttons(0, 1) = WindowHeight - 200 'y positie voor BackMenu for i = 1 to 3 buttons(i, 0) = 80 'x positie voor de menuknoppen buttons(i, 1) = 200 + i * 120 'y positie voor de menuknoppen next i end sub sub CenterView UpperLeftX = DisplayWidth / 2 - WindowWidth / 2 UpperLeftY = DisplayHeight / 2 - WindowHeight / 2 end sub sub MenuView WindowWidth = 1024 WindowHeight = 768 call CenterView stylebits #mv, 0, _WS_MINIMIZEBOX or _WS_MAXIMIZEBOX, 0, 0 open "Tronica Sprite Mask Maker" for graphics_nf_nsb as #mv #mv "trapclose CloseView" #mv "fill "; viewColor$ #mv "down" #mv "font arial 26 bold" call SetCenterText "#mv", "Tronica Sprite Mask Maker", 1 call SetCenterText "#mv", "Copyright 2024 Marco Kurvers", 2 #mv "font arial 20 bold" restore for i = 1 to 3 read title$ call ButtonTexture "#mv", title$, buttons(i, 0), buttons(i, 1), 0 next i #mv "font arial 18 bold" #mv "backcolor "; viewColor$ #mv "place "; 80 + buttonWidth + 40; " 330" #mv "|Kies de Sprite Mask Maker om zelf sprites" #mv "|te maken, zodat de sprites gereed zijn" #mv "|voor gebruik." #mv "|"; chr$(13); chr$(13); "Kies de Help voor instructies" #mv "when mouseMove MenuButtonsHover" #mv "when leftButtonUp MenuButtonsUp" #mv "flush" wait data "Sprite Mask Maker", "Help", "Programma stoppen" end sub sub SetCenterText handle$, caption$, y #handle$ "stringwidth? caption$ captionLen" #handle$ "backcolor "; viewColor$ #handle$ "place "; WindowWidth / 2 - captionLen / 2; " "; 50 + 60 * y #handle$ "|"; caption$ end sub sub MenuButtonsHover handle$, mx, my #mv "font arial 18 bold" if mx > buttons(1, 0) and mx < buttons(1, 0) + buttonWidth and _ my > buttons(1, 1) and my < buttons(1, 1) + buttonHeight then call ButtonTexture "#mv", "Sprite Mask Maker", buttons(1, 0), buttons(1, 1), 1 buttonHovered = 1 else if mx > buttons(2, 0) and mx < buttons(2, 0) + buttonWidth and _ my > buttons(2, 1) and my < buttons(2, 1) + buttonHeight then call ButtonTexture "#mv", "Help", buttons(2, 0), buttons(2, 1), 1 buttonHovered = 1 else if mx > buttons(3, 0) and mx < buttons(3, 0) + buttonWidth and _ my > buttons(3, 1) and my < buttons(3, 1) + buttonHeight then call ButtonTexture "#mv", "Programma stoppen", buttons(3, 0), buttons(3, 1), 1 buttonHovered = 1 else if buttonHovered then #mv "font arial 20 bold" call ButtonTexture "#mv", "Sprite Mask Maker", buttons(1, 0), buttons(1, 1), 0 call ButtonTexture "#mv", "Help", buttons(2, 0), buttons(2, 1), 0 call ButtonTexture "#mv", "Programma stoppen", buttons(3, 0), buttons(3, 1), 0 buttonHovered = 0 end if end if end if end if end sub sub MenuButtonsUp handle$, mx, my #mv "font arial 20 bold" if mx > buttons(1, 0) and mx < buttons(1, 0) + buttonWidth and _ my > buttons(1, 1) and my < buttons(1, 1) + buttonHeight then 'code voor de Sprite Mask Maker call MaskMakerView end if if mx > buttons(2, 0) and mx < buttons(2, 0) + buttonWidth and _ my > buttons(2, 1) and my < buttons(2, 1) + buttonHeight then 'code voor de Help call HelpView end if if mx > buttons(3, 0) and mx < buttons(3, 0) + buttonWidth and _ my > buttons(3, 1) and my < buttons(3, 1) + buttonHeight then #handle$ "discard" close #handle$ end end if call ButtonTexture "#mv", "Sprite Mask Maker", buttons(1, 0), buttons(1, 1), 0 call ButtonTexture "#mv", "Help", buttons(2, 0), buttons(2, 1), 0 call ButtonTexture "#mv", "Programma stoppen", buttons(3, 0), buttons(3, 1), 0 buttonHovered = 0 end sub sub CloseView handle$ 'Klik op de knop end sub sub MaskMakerView close #mv call CenterView hBitmap = 0 button #sm.btnOpenSprite, "&Open Sprite", btnOpenSpriteSM, UL, 20, 20, 150, 45 button #sm.btnSaveSprite, "&Sprite Opslaan", btnSaveSpriteSM, UL, 200, 20, 150, 45 button #sm.btnMakeMask, "&Masker Maken", btnMakeMask, UL, 380, 20, 150, 45 button #sm.btnCloseMask, "Mask Maker s&luiten", btnCloseMask, UL, 560, 20, 150, 45 button #sm.btnTranspColor, "&Transparantiekleur", btnTranspColorSM, UL, 840, 100, 150, 45 graphicbox #sm.gb, 10, 100, 800, 600 stylebits #sm, 0, _WS_MINIMIZEBOX or _WS_MAXIMIZEBOX, 0, 0 open "Sprite Mask Maker" for graphics_nf_nsb as #sm #sm "trapclose CloseView" hWindow = hwnd(#sm.gb) #sm "fill "; viewColor$ #sm "down" #sm "font arial 12 bold" #sm.gb "when leftButtonDown PickColorSM" call ClearSpriteBox "#sm.gb" #sm.btnSaveSprite "!disable" #sm.btnMakeMask "!disable" #sm.gb "flush" #sm "flush" wait end sub sub btnCloseMask handle$ #sm.gb "discard" #sm "discard" close #sm call MenuView end sub sub ClearSpriteBox handle$ #handle$ "backcolor "; imageColor$ #handle$ "cls" end sub sub TekenTransparantBox handle$, pickedColor if pickedColor = -1 then color$ = HexToColor$("FFFFFF") else 'color$ = HexToColor$(dechex$(pickedColor)) color$ = ColorToRGB$(pickedColor) end if #handle$ "backcolor "; color$ #handle$ "place 840 160" #handle$ "boxfilled 1000 200" end sub sub TekenKleurBox color$ #se "backcolor "; color$ #se "place 840 310" #se "boxfilled 1000 350" end sub sub PickColorSM handle$, mx, my hDC = GetDC(hWindow) pickedColor = GetPixel(hDC, mx, my) call ReleaseDC hWindow, hDC call TekenTransparantBox "#sm", pickedColor 'notice "Picked Color: "; pickedColor 'call MakeMask hWindow, bmpWidth, bmpHeight, pickedColor end sub sub btnTranspColorSM handle$ colordialog "white", pickedColor$ if pickedColor$ = "" then pickedColor = hexdec("FFFFFF") else pickedColor = hexdec(ColorToHex$(pickedColor$)) end if call TekenTransparantBox "#sm", pickedColor end sub sub btnDrawColor handle$ oldColor$ = drawColor$ colordialog oldColor$, drawColor$ if drawColor$ = "" then drawColor$ = oldColor$ end if call TekenKleurBox drawColor$ end sub sub btnOpenSpriteSM handle$ call OpenSpriteSM "#sm.gb" 'onderstaande alleen uitvoeren als er een geldig bestand is #sm.gb "drawbmp bm 0 ";bmpHeight #sm.btnMakeMask "!enable" end sub sub OpenSpriteSM handle$ filedialog "Open een sprite", "*.bmp", bitmap$ if bitmap$ = "" then notice "Geen bitmap bestand gekozen!" exit sub end if if hBitmap <> 0 then unloadbmp ("bm") call ClearSpriteBox handle$ loadbmp "bm", bitmap$ hBitmap = hbmp("bm") #handle$ "down;drawbmp bm 0 0" bmpHeight = HeightBitmap(bitmap$) bmpWidth = WidthBitmap(bitmap$) if bmpWidth > 800 or bmpHeight > 600 then redim pixels(bmpWidth, bmpHeight) end sub sub btnSaveSpriteSM handle$ if pickedColor = -1 then notice "Info"; chr$(13); "Open eerst een sprite bestand en kies dan een transparantiekleur!" exit sub end if #sm.gb, "getbmp SpriteMask 0 0 "; bmpWidth;" "; 2 * bmpHeight filedialog "Opslaan als... "; chr$(0); "save", "*.bmp", saveFile$ if saveFile$ = "" then notice "Geen bestandsnaam opgegeven!" exit sub end if bmpsave "SpriteMask", saveFile$ notice "Info"; chr$(13); "Sprite en masker opgeslagen als "; saveFile$ end sub sub btnMakeMask handle$ 'maak transparante kleur zwart if pickedColor > -1 then call MakeMask hWindow, bmpWidth, bmpHeight, pickedColor #sm.btnSaveSprite "!enable" end if end sub sub SetSprite hWnd hDC = GetDC(hWnd) for y = 0 to bmpHeight - 1 for x = 0 to bmpWidth - 1 call SetPixel hDC, x, y, pixels(x, y) next x next y call ReleaseDC hWnd, hDC end sub sub HelpView close #mv call CenterView hBitmap = 0 button #hv.btnCloseHelp, "Helpvenster s&luiten", btnCloseHelp, UL, 560, 20, 150, 45 graphicbox #hv.gb, 10, 100, WindowWidth - 28, 600 stylebits #hv, 0, _WS_MINIMIZEBOX or _WS_MAXIMIZEBOX, 0, 0 open "Help" for graphics_nf_nsb as #hv #hv "trapclose CloseView" #hv "fill "; viewColor$ #hv "down" #hv.gb "font arial 22 bold" #hv.gb "|"; chr$(13); chr$(13); #hv.gb "|Open eerst een bitmapbestand dat je als sprite wilt gebruiken." #hv.gb "|Klik op de kleur die je als transparantiekleur wilt hebben of" #hv.gb "|klik op de knop Transparantiekleur om een kleur te kiezen." #hv.gb "|In beide mogelijkheden zal de gekozen kleur onder de Transparantie-" #hv.gb "|kleur knop als een rechthoek verschijnen. Deze kleur zal bewaard" #hv.gb "|blijven, zodat je niet telkens een kleur hoeft te kiezen bij elk" #hv.gb "|bestand die je opent." #hv.gb "|Dit werkt alleen als toevallig de afbeelding dezelfde transparantie-" #hv.gb "|kleur heeft." #hv.gb "|Als je klaar bent, bewaar dan de sprite onder een geldige bestands-" #hv.gb "|naam. De extensie zal altijd *.bmp zijn." #hv.gb "flush" #hv "flush" wait end sub sub btnCloseHelp handle$ #hv.gb "discard" #hv "discard" close #hv call MenuView end sub '************FUNCTIONS****************** function WidthBitmap(name$) open name$ for input as #pic pic$=input$(#pic,29) close #pic WidthBitmap = asc(mid$(pic$,19,1)) + _ (asc(mid$(pic$,20,1)) * 256) end function function HeightBitmap(name$) open name$ for input as #pic pic$=input$(#pic,29) close #pic HeightBitmap = asc(mid$(pic$,23,1)) + _ (asc(mid$(pic$,24,1)) * 256) end function sub MakeMask hWnd, wide, high, clickedColor cursor hourglass white=(255*256*256)+(255*256)+255 black=0 hDC = GetDC(hWnd) for i = 0 to wide - 1 for j = 0 to high - 1 pColor = GetPixel(hDC, i, j + high) if pColor = clickedColor then newColor = black call SetPixel hDC, i, j + high, newColor end if next j next i for i = 0 to wide-1 for j = 0 to high-1 pColor = GetPixel(hDC, i, j) if pColor = clickedColor then newColor = white else newColor = black end if call SetPixel hDC, i, j, newColor next j next i call ReleaseDC hWnd, hDC cursor normal end sub function GetDC(hWnd) calldll #user32, "GetDC",_ hWnd as long,_ hDC as long GetDC = hDC end function function GetPixel(hDC, x, y) calldll #gdi32, "GetPixel",_ hDC as long,_ x as long,_ y as long,_ pColor as long GetPixel = pColor end function sub SetPixel hDC, x, y, pColor calldll #gdi32, "SetPixel",_ hDC as long,_ x as long, _ y as long, _ pColor as long, _ r as long end sub sub ReleaseDC hWnd, hDC calldll #user32, "ReleaseDC",_ hWnd as long,_ hDC as long,_ r as long end sub sub ButtonTexture handle$, title$, x, y, clicked if clicked then #handle$ "backcolor "; buttonClickColor$ else #handle$ "backcolor "; buttonColor$ end if #handle$ "color black" #handle$ "place "; x; " "; y #handle$ "boxfilled "; x + buttonWidth; " "; y + buttonHeight #handle$ "stringwidth? title$ titleLen" #handle$ "place "; x + (buttonWidth / 2 - titleLen / 2); " "; y + 32 #handle$ "|"; title$ end sub function ColorToHex$(color$) '255 02 32 h1$ = dechex$(val(word$(color$, 3))) h2$ = dechex$(val(word$(color$, 2))) h3$ = dechex$(val(word$(color$, 1))) if len(h1$) = 1 then h1$ = "0" + h1$ if len(h2$) = 1 then h2$ = "0" + h2$ if len(h3$) = 1 then h3$ = "0" + h3$ 'ColorToHex$ = dechex$(val(word$(color$, 1))) + dechex$(val(word$(color$, 2))) + dechex$(val(word$(color$, 3))) ColorToHex$ = h1$ + h2$ + h3$ end function function HexToColor$(colorHex$) c3 = hexdec(left$(colorHex$, 2)) c2 = hexdec(mid$(colorHex$, 3, 2)) c1 = hexdec(right$(colorHex$, 2)) HexToColor$ = c1; " "; c2; " "; c3 end function function ColorToRGB$(colorCode) 'blue = colorCode mod 256 red = colorCode mod 256 green = int(colorCode / 256) mod 256 'red = int(colorCode / (256 * 256)) blue = int(colorCode / (256 * 256)) ColorToRGB$ = red; " "; green; " "; blue end function function RGBToColor(colorRGB$) red = val(word$(colorRGB$, 1)) green = val(word$(colorRGB$, 2)) blue = val(word$(colorRGB$, 3)) RGBToColor = red * 256 * 256 + green * 256 + blue end function