12-08-2005, 09:09 AM
Here's something to mess with. At the very least, it will show you how to use a Sub, and how to use the mouse in FreeBASIC. Don't bother trying it under QB though.
Code:
#INCLUDE "FBGFX.BI"
Screen 13,,,1
Declare Sub Draw_Palette( MouseX, MouseY, Button, Paint_Color )
Declare Sub Draw_Big_Grid( MouseX, MouseY, Button, Paint_Color, Img_Data() )
Declare Sub Copy_Pixel_Data( Img_Data() )
Declare Sub Paste_Pixel_Data( Img_Data() )
Dim Img_Data(15, 15)
Do
Getmouse( MouseX, MouseY,,Button )
Draw_Palette( MouseX, MouseY, Button, Paint_Color )
Copy_Pixel_Data( Img_Data() )
Draw_Big_Grid( MouseX, MouseY, Button, Paint_Color, Img_Data() )
Paste_Pixel_Data( Img_Data() )
Line(0,0)-(17,17),31,B
Line(1,109)-(7, 116),31,B
Line(2,110)-(6, 115),Paint_Color,BF
Loop Until Multikey(SC_ESCAPE)
Sub Draw_Palette( MouseX, MouseY, Button, Paint_Color )
For Y = 0 To 15
For X = 0 To 15
Line(X*5,(Y*5)+120)-Step(4,4),Col,BF
If MouseX>=(X*5) And MouseX<=(X*5)+4 And MouseY>=(Y*5)+120 And MouseY<=(Y*5)+124 Then
Line(X*5,(Y*5)+120)-Step(4,4),31,B
If Button = 1 Then
Paint_Color = Col
End If
End If
Col+=1
If MouseX>=1 And MouseX<=16 And MouseY>=1 And MouseY<=16 Then
Select Case Button
Case 1
Pset(MouseX, MouseY), Paint_Color
Case 2
Paint_Color = Point(MouseX, MouseY)
End Select
End If
Next
Next
End Sub
Sub Draw_Big_Grid( MouseX, MouseY, Button, Paint_Color, Img_Data() )
For Y = 0 To 15
For X = 0 To 15
If MouseX>=(X*12)+100 And MouseX<=(X*12)+111 And MouseY>=(Y*12) And MouseY<=(Y*12)+11 Then
If Button = 1 Then
Img_Data(X,Y) = Paint_Color
Elseif Button = 2 Then
Paint_Color = Img_Data(X,Y)
End If
End If
Line((X*12)+100,Y*12)-Step(11,11),31,B
Line((X*12)+101,(Y*12)+1)-Step(9,9), Img_Data(X,Y),BF
Img_Data(X,Y) = Point((X*12)+101,(Y*12)+1)
Next
Next
End Sub
Sub Copy_Pixel_Data( Img_Data() )
For Y=0 To 15
For X = 0 To 15
Img_Data(X,Y) = Point(X+1,Y+1)
Next
Next
End Sub
Sub Paste_Pixel_Data( Img_Data() )
For Y=0 To 15
For X = 0 To 15
Pset(X+1,Y+1),Img_Data(X,Y)
Next
Next
End Sub