Test dialog to explore the different Color Mix Modes available for Graphic Targets in PB.
See discussion at http://www.powerbasic.com/support/pb...ad.php?t=40680
'
See discussion at http://www.powerbasic.com/support/pb...ad.php?t=40680
'
Code:
'#DEBUG DISPLAY ON #DIM ALL #REGISTER NONE #COMPILE EXE #INCLUDE "WIN32API.INC" #INCLUDE "COMDLG32.INC" %GFX_GRAPHIC1 = 1001 %GFX_Color1 = 1002 %GFX_Color2 = 1003 %GFX_MixRes = 1004 %LBL_Color1 = 1012 %LBL_Color2 = 1013 %LBL_MixRes = 1014 %CMB_MixModeSel = 1016 %LBL_Intro = 1018 %BTN_ColorPick1 = 1019 %BTN_ColorPick2 = 1020 %LBL_Description = 1021 '------------------/ FUNCTION PBMAIN() Dialog1 0 END FUNCTION CALLBACK FUNCTION Dialog1Proc() Static hBmp As Dword Local n As Long Local sTemp As String Static Color1, Color2 As Dword Static Mix_Mode As Long SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG Color1 = %WHITE : Color2 = %BLACK Mix_Mode = 13 Paint_Samples CbHndl, Color1, Color2, Mix_Mode Load_Combobox CbHndl, %CMB_MixModeSel ComboBox Select CbHndl, %CMB_MixModeSel, 13 Load_Label CbHndl, %LBL_Description, 13 Graphic Bitmap New 248, 248 To hBmp ' Create bitmap for background Graphic Attach hBmp, 0 Graphic Clear %Black Graphic Width 10 For n = 46 To 246 Step 50 Graphic Line (n,1) - (1,n), %White Graphic Line (250,n)- (n,250), %White Next Paint_Main CbHndl, hBmp, Color1, Color2, Mix_Mode CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CbWparam THEN hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_COMMAND SELECT CASE AS LONG CBCTL CASE %GFX_GRAPHIC1 CASE %GFX_Color1 CASE %BTN_ColorPick1 IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN Pick_Color CbHndl, Color1 Control Set Text CbHndl, %LBL_Color1, Hex$(Color1,6) Paint_Samples CbHndl, Color1, Color2, Mix_Mode Paint_Main CbHndl, hBmp, Color1, Color2, Mix_Mode END IF CASE %GFX_Color2 CASE %BTN_ColorPick2 IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN Pick_Color CbHndl, Color2 Control Set Text CbHndl, %LBL_Color2, Hex$(Color2,6) Paint_Samples CbHndl, Color1, Color2, Mix_Mode Paint_Main CbHndl, hBmp, Color1, Color2, Mix_Mode END IF CASE %GFX_MixRes CASE %CMB_MixModeSel If CbCtlMsg = %CBN_SELCHANGE Then ComboBox Get Text CbHndl, %CMB_MixModeSel To sTemp ComboBox Get Select CbHndl, %CMB_MixModeSel To n Load_Label CbHndl, %LBL_Description, n Mix_Mode = n Paint_Samples CbHndl, Color1, Color2, Mix_Mode Paint_Main CbHndl, hBmp, Color1, Color2, Mix_Mode End If END SELECT END SELECT END FUNCTION '------------------/DlgProc FUNCTION Dialog1(BYVAL hParent AS DWORD) AS LONG LOCAL hDlg, hFont1, hFont2 AS DWORD LOCAL sTemp AS STRING FONT NEW "ARIAL", 12 To hFont1 FONT NEW "COURIER NEW", 10 To hFont2 DIALOG NEW PIXELS, hParent, "Mix test", 200, 200, 600, 500, %WS_CAPTION OR %WS_SYSMENU TO hDlg CONTROL ADD GRAPHIC, hDlg, %GFX_GRAPHIC1, "", 38, 24, 250, 251, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER CONTROL ADD BUTTON, hDlg, %BTN_ColorPick1, "...", 48, 299, 30, 24 CONTROL ADD GRAPHIC, hDlg, %GFX_Color1, "", 93, 299, 79, 29, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR _ %SS_SUNKEN OR %SS_NOTIFY CONTROL ADD LABEL, hDlg, %LBL_Color1, "Pixel", 183, 307, 97, 20 CONTROL ADD BUTTON, hDlg, %BTN_ColorPick2, "...", 48, 340, 30, 24 CONTROL ADD GRAPHIC, hDlg, %GFX_Color2, "", 93, 340, 79, 29, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR _ %SS_SUNKEN OR %SS_NOTIFY CONTROL ADD LABEL, hDlg, %LBL_Color2, "Source", 183, 348, 97, 19 CONTROL ADD GRAPHIC, hDlg, %GFX_MixRes, "", 93, 379, 79, 31, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR _ %SS_SUNKEN OR %SS_NOTIFY CONTROL ADD LABEL, hDlg, %LBL_MixRes, "Result of Mix", 183, 388, 97, 20 sTemp = "There are 16 built-in mix modes available to use for mixing the drawing color with the color that already " + _ "exists at the drawing location." CONTROL ADD LABEL, hDlg, %LBL_Intro, sTemp , 330, 24, 233, 75 CONTROL ADD COMBOBOX, hDlg, %CMB_MixModeSel, , 330, 114, 214, 300, %WS_CHILD OR %WS_VISIBLE OR _ %WS_TABSTOP OR %CBS_SIMPLE CONTROL ADD LABEL, hDlg, %LBL_Description, "MixMode Description", 90, 431, 382, 57 CONTROL SET FONT hDlg, %LBL_Color1, hFont1 CONTROL SET FONT hDlg, %LBL_Color2, hFont1 CONTROL SET FONT hDlg, %LBL_MixRes, hFont1 CONTROL SET FONT hDlg, %LBL_Intro, hFont1 CONTROL SET FONT hDlg, %LBL_Description, hFont1 CONTROL SET FONT hDlg, %CMB_MixModeSel, hFont2 DIALOG SHOW MODAL hDlg, CALL Dialog1Proc END FUNCTION '------------------/Dialog1 Sub Load_ComboBox (hWnd As Dword, CtlID As long) Local n As Long For n = 1 To Datacount Combobox Add hWnd, CtlID, Read$(n) Next DATA " 1 %mix_Blackness " DATA " 2 %mix_NotMergeSrc " DATA " 3 %mix_MaskNotSrc " DATA " 4 %mix_NotCopySrc " DATA " 5 %mix_MaskSrcNot " DATA " 6 %mix_Not " DATA " 7 %mix_XorSrc " DATA " 8 %mix_NotMaskSrc " DATA " 9 %mix_MaskSrc " DATA " 10 %mix_NotXorSrc " DATA " 11 %mix_Nop " DATA " 12 %mix_MergeNotSrc " DATA " 13 %mix_CopySrc (def) " DATA " 14 %mix_MergeSrcNot " DATA " 15 %mix_MergeSrc " DATA " 16 %mix_Whiteness " DATA " 17 Average Colours" End Sub '------------------/Load_ComboBox Sub Load_Label (hWnd As Dword, CtlID As Long, Index As Long) Control Set Text hWnd, CtlID, "" Control Set Text hWnd, CtlID, Read$(Index) Data "Pixel is always 0 (black)." Data "Pixel is the inverse of the MergeSrc color." Data "Pixel is a combination of the colors common to both the pixel and the inverse of the source." Data "Pixel is the inverse of the pen color." Data "Pixel is a combination of the colors common to both the source and the inverse of the pixel." Data "Pixel is the inverse of the pixel color." Data "Pixel is a combination of the colors in the source and in the pixel, but not in both." Data "Pixel is the inverse of the MaskSrc color." Data "Pixel is a combination of the colors common to both the source and the pixel." Data "Pixel is the inverse of the XorSrc color." Data "Pixel remains unchanged." Data "Pixel is a combination of the source color and the inverse of the pixel color." Data "Pixel is the source color (default)." Data "Pixel is a combination of the source color and the inverse of the pixel color." Data "Pixel is a combination of the source color and the pixel color." Data "Pixel is always 1 (white)." Data "Result of Mix is average of combined colors. ('Custom' mix, not built-in TT Chis Boss)" End Sub '------------------/Load_Label SUB Pick_Color (ByVal hWnd As Dword, ColorRes AS DWORD) Dim cc As CHOOSECOLORAPI Dim cr (1 To 16) As RGBQUAD cc.lStructSize = SizeOf (CHOOSECOLORAPI) cc.flags = %CC_SOLIDCOLOR Or %CC_FULLOPEN Or %CC_RGBINIT cc.hwndowner = hWnd cc.lpcustcolors = VarPtr(cr()) cc.rgbResult = ColorRes ChooseColor (cc) ColorRes = cc.rgbResult End Sub '------------------/ColorPick Sub Paint_Samples (hWnd As Dword, Color1 As Dword, Color2 As Dword, Mix_Mode As Long) LOCAL B1 AS BYTE PTR, B2 AS BYTE PTR, B3 As BYTE PTR, Color3 As Long Graphic Attach hWnd, %GFX_Color1 : Graphic Clear Color1 Graphic Attach hWnd, %GFX_Color2 : Graphic Clear Color2 Select Case Mix_Mode Case 1 to 16 Graphic Attach hWnd, %GFX_MixRes : Graphic Clear Color1 Graphic Set Mix Mix_Mode Graphic Paint (0,0), Color2 Case 17 ' Average colours as per CB B1=VARPTR(Color1) B2=VARPTR(Color2) B3=Varptr(Color3) @B3=(@[email protected])/2 INCR B1 INCR B2 INCR B3 @B3=(@[email protected])/2 INCR B1 INCR B2 INCR B3 @B3=(@[email protected])/2 Graphic Attach hWnd, %GFX_MixRes : Graphic Set Mix 13 Graphic Paint (0,0), Color3 End Select Graphic Get Pixel (10,10) To Color3 Control Set Text hWnd, %LBL_MixRes, Hex$(Color3, 6) End Sub '------------------/Paint_Samples Sub Paint_Main (hWnd As dword, hBmp As Dword, Color1 As Dword, Color2 As Dword, Mix_Mode As Long) Graphic Attach hWnd, %GFX_GRAPHIC1 Graphic Set Mix Mix_Mode Graphic Copy hBmp, 0 Graphic Box (49,49)-(149,149), 10, %LTGRAY, Color1 Graphic Box (99,99)-(199,199), 10, %LTGRAY, Color2 End Sub '------------------/Paint_Main
Comment