Author Topic: Paint Pixels 8 With Right-Click Menu  (Read 4820 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Paint Pixels 8 With Right-Click Menu
« on: July 01, 2020, 04:08:55 am »
Here is an early version of Paint Pixels 8. I stayed up until 1 am tonight putting this together. Thank you Dav for the menu code! Now you can paint away with the mouse and not having to mess with the keyboard while painting. You just right click the paint screen and it brings up a menu for everything! If any of you find bugs, please tell me, thanks. All of the required files are in the zip folder.
This version also has everything version 7 had except for less instructions. I figured that nobody would want to use the keys to change modes now but I kept them in the code just in case. The boxes and circles are only made one at a time and are made where you first click to turn the menu on. The lines also start there but keep going, as before, to keep making attached lines until you right click and use the menu again. Using the version 7 Undo feature in the menu, you can always undo something you just made, including one continuous drawing or erasing. Same with erasing anything else you just did like a box, a circle, lines, and fill-ins. I hope you all enjoy this. If you have any suggestions, feel free to tell me. I may or may not be able to do a lot other things though.

Update: This post's zip file has been removed to fix problems and update many things. Scroll down to the post with the next zip file to get it.
« Last Edit: July 02, 2020, 06:17:55 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #1 on: July 01, 2020, 08:17:29 pm »
I'm almost ready to release another update, which has much better line, box, and circle control with the mouse, but I ran into a bug that I can't seem to find. Can you guys help me? What's happening is after you paint a tiny bit and Save it, then paint some more, and then right click on the screen to open the menu again, it automatically goes to either Save or Open or anything without me choosing something (or even seeing the menu). Then for some strange reason, it's like the mouse left button is stuck down and wherever I move the mouse on the screen, it paints white, which isn't even the paint or erase color that's set on. I don't know if this is a memory leak or what's going on. I know the menu code uses _MEMCOPY and _MEMFREE down at the very bottom of my program. I appreciate the help.


Update: Huge memory issue found, please delete this version if you have it. Code has been removed.
« Last Edit: July 04, 2020, 05:18:03 pm by SierraKen »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #2 on: July 02, 2020, 01:52:37 pm »
There does appear to be some weirdness going on - it happens to me sometimes, not all the time.    Maybe there's some some variable or mousebutton hangovers that need to be cleared.  I'll play around with it and see what I can find.

- Dav
« Last Edit: July 02, 2020, 01:54:29 pm by Dav »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #3 on: July 02, 2020, 01:56:51 pm »
Thanks Dav! I hope we can find out what's going on.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #4 on: July 02, 2020, 02:35:47 pm »
I added something in the menu function that seems to have cleared it up for me.  In the code I added ### in the comments so you can search & find it quick.  Basically I just made sure both mouse buttons are up before exiting the popup menu.  I also played with clearing the a% variable, but I think the mouse thing was causing it, ast lease the error isn't happening for me now.  See if it happens to you with the change.

Something I noticed before in the program, the circles and box routine will sometimes cause the program to crash when moving the mouse pointer a lot.  May want to look into that too.

- Dav 

Code: QB64: [Select]
  1. 'Paint Pixels 8
  2. 'by Sierraken and B+
  3. 'Made on June 30, 2020
  4. 'Technical Notes:
  5. 'First I want to thank all of the people that have helped me so far in this program:
  6. 'B+ for the color picker and help with the circles, boxes and rays and other help.
  7. 'Petr for help with the file opening and saving dialog and saveimage libraries.
  8. 'SpriggySpriggs for his file opening and saving examples that inspired me to keep going.
  9. 'Dav for the Right Click Menu.
  10. 'Thank you also to everyone else who has used and helped me with this!
  11. 'New Additions for Version 8:
  12. 'Right Click Menu to select everything you need to draw with.
  13. 'Fixed Lines, Circles, and Boxes so that you can put them anywhere using the mouse by
  14. 'dragging their sizes with the left mouse button. Also lets you place as many as you want.
  15. 'Made boxes not fill-in anymore because there is already a fill-in option.
  16. '-----------------------------------------------------------------------------------------------
  17. '$include:'saveimage.bi'
  18. '$include:'opensave.bi'
  19. '=== =============DEFINES FOR RIGHT CLICK MENU - CHANGE TO SUIT ==========================
  20. DECLARE FUNCTION RightClickMenu% ()
  21.  
  22. DIM SHARED RightClickItems: RightClickItems = 22 '    <----- Number of items in your menu
  23. DIM SHARED RightClickList$(1 TO RightClickItems)
  24.  
  25. RightClickList$(1) = "New" '     <------------ List all your menu items here
  26. RightClickList$(2) = "Open..."
  27. RightClickList$(3) = "Save As..."
  28. RightClickList$(4) = "---" '   <------------ This means it's a separator (---)
  29. RightClickList$(5) = "Draw"
  30. RightClickList$(6) = "---"
  31. RightClickList$(7) = "Erase"
  32. RightClickList$(8) = "---"
  33. RightClickList$(9) = "Color"
  34. RightClickList$(10) = "Straight Lines"
  35. RightClickList$(11) = "Circles"
  36. RightClickList$(12) = "Boxes"
  37. RightClickList$(13) = "Fill-In"
  38. RightClickList$(14) = "---"
  39. RightClickList$(15) = "Undo"
  40. RightClickList$(16) = "---" '     <------------ (another separator)
  41. RightClickList$(17) = "Print"
  42. RightClickList$(18) = "---"
  43. RightClickList$(19) = "Help"
  44. RightClickList$(20) = "Exit Menu"
  45. RightClickList$(21) = "---"
  46. RightClickList$(22) = "Exit Paint Pixels"
  47.  
  48. '========================================================================================
  49.  
  50.  
  51. _LIMIT 1000
  52. start:
  53. _TITLE "Paint Pixels 8"
  54. WIDTH 40, 43
  55. COLOR 15, 0
  56. PRINT "          Paint Pixels 8"
  57. PRINT "         By Ken G. and B+"
  58. PRINT "          Instructions"
  59. PRINT "  Right-Click on the drawing screen"
  60. PRINT "  with your mouse to see the Menu."
  61. PRINT "  Supports: JPG, PNG, GIF, BMP"
  62. PRINT "Use mouse to paint and also to plot and"
  63. PRINT "change sizes of lines, circles, and"
  64. PRINT "squares holding down the left mouse"
  65. PRINT "button. Release button to keep them."
  66. PRINT "  Press the Space Bar to begin."
  67. PRINT "        Or Esc to quit."
  68. paintpixelsinst:
  69. ecc$ = INKEY$
  70. IF ecc$ = " " THEN GOTO start2:
  71. IF ecc$ = CHR$(27) THEN END
  72. IF ecc$ = "" THEN GOTO paintpixelsinst:
  73. GOTO paintpixelsinst:
  74. start2:
  75. IF ist = 1 THEN ist = 0: GOTO start4:
  76. _TITLE "Paint Pixels 8"
  77. WIDTH 40, 43
  78. COLOR 15, 0
  79. PRINT "            Screen Size"
  80. PRINT "         (1) 640 x 480"
  81. PRINT "         (2) 800 x 600"
  82. PRINT "         (3) 1024 x 768"
  83. PRINT "         (4) 1536 x 1024"
  84. PRINT "         (5) Other"
  85. PRINT "Type number (1-5) here:"
  86. screensize:
  87. screensz = VAL(INKEY$)
  88. IF screensz = 1 THEN screenx = 640: screeny = 480: GOTO nextsc:
  89. IF screensz = 2 THEN screenx = 800: screeny = 600: GOTO nextsc:
  90. IF screensz = 3 THEN screenx = 1024: screeny = 768: GOTO nextsc:
  91. IF screensz = 4 THEN screenx = 1536: screeny = 1024: GOTO nextsc:
  92. IF screensz = 5 THEN
  93.     morescreensz:
  94.     PRINT
  95.     INPUT "Horizontal X (640-1920): ", screenx
  96.     IF screenx < 640 OR screenx > 1920 THEN PRINT "Try again.": GOTO morescreensz:
  97.     INPUT "Vertical   Y (480-1024): ", screeny
  98.     IF screeny < 480 OR screeny > 1024 THEN PRINT "Try again.": GOTO morescreensz:
  99.     GOTO nextsc:
  100. GOTO screensize:
  101.  
  102. 'Choose Background Color.
  103. nextsc:
  104. background& = _NEWIMAGE(800, 600, 32)
  105. begin = 1
  106. bcol = 0
  107. background& = _LOADIMAGE("colorwheelpage.png", 32)
  108. SCREEN background&
  109. mouseLeftButton = 0
  110. colorwheel:
  111. _LIMIT 1000
  112.     mousex = _MOUSEX
  113.     mousey = _MOUSEY
  114.     mouseLeftButton = _MOUSEBUTTON(1)
  115. IF mouseLeftButton = -1 THEN
  116.     back& = POINT(mousex, mousey)
  117.     IF back& = _RGB32(0, 0, 0) THEN bcol = 1
  118.     mouseLeftButton = 0
  119.     mousex = 0: mousey = 0
  120.     GOTO start3:
  121. GOTO colorwheel:
  122. start3:
  123. _LIMIT 1000
  124. undo& = _NEWIMAGE(screenx, screeny, 32)
  125. s& = _NEWIMAGE(screenx, screeny, 32)
  126. picture& = _NEWIMAGE(screenx, screeny, 32)
  127. LINE (0, 0)-(screenx, screeny), back&, BF
  128. _PUTIMAGE , s&, picture&
  129. begin = 1
  130. _TITLE "Choose Your Paint Color Here By Using The 4 Sliders With Your Mouse."
  131. GOSUB chosencolor:
  132. start4:
  133. m = 1
  134. _TITLE "Right Click Mouse To See Menu."
  135. '---------------------------------------------------
  136. 'Here is the main loop of the program when painting.
  137. '---------------------------------------------------
  138.  
  139.     'a% = 0 '### making sure a% is cleared (used by Dav for testing)
  140.  
  141.     _LIMIT 1000
  142.     _PUTIMAGE , picture&, s&
  143.     SCREEN s&
  144.         mousex = _MOUSEX
  145.         mousey = _MOUSEY
  146.         mouseLeftButton = _MOUSEBUTTON(1)
  147.         mouseRightButton = _MOUSEBUTTON(2)
  148.     LOOP
  149.     IF mouseLeftButton = 0 THEN button = 1
  150.     a$ = INKEY$
  151.     a% = RightClickMenu% ' <----- Check for rightclick menu
  152.  
  153.     '=== what did you select?
  154.     IF a% > 0 THEN
  155.         IF a% = 1 THEN a$ = "1"
  156.         IF a% = 2 THEN a$ = "l"
  157.         IF a% = 3 THEN a$ = "s"
  158.         IF a% = 5 THEN a$ = "d"
  159.         IF a% = 7 THEN a$ = "e"
  160.         IF a% = 9 THEN a$ = "c"
  161.         IF a% = 10 THEN a$ = "r": lastx = 0: lasty = 0
  162.         IF a% = 11 THEN a$ = "o": lastx = 0: lasty = 0
  163.         IF a% = 12 THEN a$ = "b": lastx = 0: lasty = 0
  164.         IF a% = 13 THEN a$ = "f"
  165.         IF a% = 15 THEN a$ = "u"
  166.         IF a% = 17 THEN a$ = "p"
  167.         IF a% = 19 THEN a$ = "i"
  168.         IF a% = 20 THEN a% = 0
  169.         IF a% = 22 THEN END
  170.         mouseLeftButton = 0
  171.         a% = 0
  172.     END IF
  173.     'Here is when someone whipes the screen blank with the space bar.
  174.     IF a$ = "1" THEN a$ = "": GOTO start2:
  175.     IF a$ = "s" OR a$ = "S" THEN
  176.         a$ = ""
  177.         GOSUB saving:
  178.     END IF
  179.     IF a$ = "l" OR a$ = "L" THEN
  180.         a$ = ""
  181.         GOSUB loading:
  182.     END IF
  183.     IF a$ = "i" OR a$ = "I" OR a$ = CHR$(27) THEN m = 0: ist = 1: a$ = "": GOTO start:
  184.     'Here is code needed to call up the Windows Color Picker.
  185.     'It also uses the code on top of this program and the Function at the end
  186.     'of this program.
  187.     IF a$ = "c" OR a$ = "C" THEN
  188.         a$ = ""
  189.         chosencolor:
  190.         check$ = colorDialog$
  191.         IF check$ <> "" THEN clr~& = VAL(check$) 'ELSE <<< don't change drawing color
  192.         IF begin = 1 THEN begin = 0: RETURN
  193.     END IF
  194.     IF a$ = "d" OR a$ = "D" THEN
  195.         a$ = ""
  196.         a& = 0
  197.         m = 1
  198.         mm = 1
  199.     END IF
  200.     IF m = 1 THEN
  201.         IF mouseLeftButton THEN
  202.             IF button = 1 THEN lastx = mousex: lasty = mousey: undo& = _COPYIMAGE(0)
  203.             FOR sz = .25 TO 2 STEP .25
  204.                 LINE (mousex, mousey)-(lastx + sz, lasty + sz), clr~&
  205.                 LINE (mousex + sz, mousey + sz)-(lastx + sz, lasty + sz), clr~&
  206.                 LINE (mousex + sz, mousey)-(lastx + sz, lasty), clr~&
  207.                 LINE (mousex, mousey + sz)-(lastx, lasty + sz), clr~&
  208.             NEXT sz
  209.             button = 0
  210.             mm = 0
  211.             lastx = mousex: lasty = mousey
  212.             _PUTIMAGE , s&, picture&
  213.         END IF
  214.     END IF
  215.     IF a$ = "e" OR a$ = "E" THEN
  216.         a$ = ""
  217.         a& = 0
  218.         m = 2
  219.         mm = 2
  220.     END IF
  221.     IF mouseLeftButton = 0 AND mm = 2 THEN undo& = _COPYIMAGE(0)
  222.     IF m = 2 THEN
  223.         IF mouseLeftButton THEN
  224.             IF button = 1 THEN lastx = mousex: lasty = mousey: undo& = _COPYIMAGE(0)
  225.             FOR sz = .25 TO 2 STEP .25
  226.                 LINE (mousex, mousey)-(lastx + sz, lasty + sz), back&
  227.                 LINE (mousex + sz, mousey + sz)-(lastx + sz, lasty + sz), back&
  228.                 LINE (mousex + sz, mousey)-(lastx + sz, lasty), back&
  229.                 LINE (mousex, mousey + sz)-(lastx, lasty + sz), back&
  230.             NEXT sz
  231.             button = 0
  232.             mm = 0
  233.             lastx = mousex: lasty = mousey
  234.             _PUTIMAGE , s&, picture&
  235.         END IF
  236.     END IF
  237.     'Here is the Ray Lines code.
  238.     IF a$ = "r" OR a$ = "R" THEN
  239.         a$ = ""
  240.         a% = 0
  241.         m = 3
  242.         IF mouseLeftButton = 0 THEN undo& = _COPYIMAGE(0)
  243.     END IF
  244.     IF m = 3 THEN
  245.         IF mouseLeftButton THEN
  246.             IF mm = 3 THEN undo& = _COPYIMAGE(0)
  247.             IF mm = 0 THEN lastx = mousex: lasty = mousey
  248.             FOR sz = .25 TO 2 STEP .25
  249.                 LINE (lastx, lasty)-(mousex, mousey), clr~&
  250.                 LINE (lastx + sz, lasty)-(mousex + sz, mousey), clr~&
  251.                 LINE (lastx, lasty + sz)-(mousex, mousey + sz), clr~&
  252.                 LINE (lastx, lasty + sz)-(mousex + sz, mousey), clr~&
  253.             NEXT sz
  254.             mm = 3
  255.         END IF
  256.         IF mouseLeftButton = 0 AND mm = 3 THEN
  257.             FOR sz = .25 TO 2 STEP .25
  258.                 LINE (lastx, lasty)-(mousex, mousey), clr~&
  259.                 LINE (lastx + sz, lasty)-(mousex + sz, mousey), clr~&
  260.                 LINE (lastx, lasty + sz)-(mousex, mousey + sz), clr~&
  261.                 LINE (lastx, lasty + sz)-(mousex + sz, mousey), clr~&
  262.             NEXT sz
  263.             _PUTIMAGE , s&, picture&
  264.             lastx = mousex: lasty = mousey
  265.             mm = 0
  266.         END IF
  267.     END IF
  268.     'Here is the Orbit Circles code.
  269.     IF a$ = "o" OR a$ = "O" THEN
  270.         a$ = ""
  271.         a% = 0
  272.         m = 4
  273.         IF mouseLeftButton = 0 THEN undo& = _COPYIMAGE(0)
  274.     END IF
  275.     IF m = 4 THEN
  276.         IF mouseLeftButton THEN
  277.             IF mm = 4 THEN undo& = _COPYIMAGE(0)
  278.             IF mm = 0 THEN lastx = mousex: lasty = mousey
  279.             IF mousex < lastx THEN size = lastx - mousex
  280.             IF mousex > lastx THEN size = mousex - lastx
  281.             IF mousey < lasty THEN size2 = lasty - mousey
  282.             IF mousey > lasty THEN size2 = mousey - lasty
  283.             one:
  284.             seconds = seconds + .01
  285.             s = (60 - seconds) * 6 + size
  286.             x = INT(SIN(s / 180 * 3.141592) * size) + lastx
  287.             y = INT(COS(s / 180 * 3.141592) * size2) + lasty
  288.             CIRCLE (x, y), 1, clr~&
  289.             IF seconds > 60 THEN
  290.                 seconds = 0
  291.                 GOTO two:
  292.             END IF
  293.             GOTO one:
  294.             two:
  295.             mm = 4
  296.         END IF
  297.         IF mouseLeftButton = 0 AND mm = 4 THEN
  298.             three:
  299.             seconds = seconds + .01
  300.             s = (60 - seconds) * 6 + size
  301.             x = INT(SIN(s / 180 * 3.141592) * size) + lastx
  302.             y = INT(COS(s / 180 * 3.141592) * size2) + lasty
  303.             CIRCLE (x, y), 1, clr~&
  304.             IF seconds > 60 THEN
  305.                 seconds = 0
  306.                 GOTO four:
  307.             END IF
  308.             GOTO three:
  309.             four:
  310.             _PUTIMAGE , s&, picture&
  311.             lastx = mousex: lasty = mousey
  312.             mm = 0
  313.             size = 0: size2 = 0
  314.         END IF
  315.     END IF
  316.     'Here is the Boxes code.
  317.     IF a$ = "b" OR a$ = "B" THEN
  318.         a$ = ""
  319.         a% = 0
  320.         m = 5
  321.         lastx = mousex: lasty = mousey
  322.         IF mouseLeftButton = 0 THEN undo& = _COPYIMAGE(0)
  323.     END IF
  324.     IF m = 5 THEN
  325.         IF mouseLeftButton THEN
  326.             IF mm = 5 THEN undo& = _COPYIMAGE(0)
  327.             IF mm = 0 THEN lastx = mousex: lasty = mousey
  328.             FOR sz = .25 TO 2 STEP .25
  329.                 LINE (lastx - sz, lasty - sz)-(mousex + sz, mousey + sz), clr~&, B
  330.             NEXT sz
  331.             mm = 5
  332.         END IF
  333.         IF mouseLeftButton = 0 AND mm = 5 THEN
  334.             FOR sz = .25 TO 2 STEP .25
  335.                 LINE (lastx - sz, lasty - sz)-(mousex + sz, mousey + sz), clr~&, B
  336.             NEXT sz
  337.             _PUTIMAGE , s&, picture&
  338.             lastx = mousex: lasty = mousey
  339.             mm = 0
  340.         END IF
  341.     END IF
  342.     'Here is Fill-In
  343.     IF a$ = "f" OR a$ = "F" THEN
  344.         a$ = ""
  345.         m = 6
  346.         mouseLeftButton = 0
  347.     END IF
  348.     IF m = 6 THEN
  349.         IF mouseLeftButton THEN undo& = _COPYIMAGE(0)
  350.         IF mouseLeftButton THEN paint3 mousex, mousey, clr~&
  351.         IF mouseLeftButton THEN mouseLeftButton = 0
  352.         _PUTIMAGE , s&, picture&
  353.     END IF
  354.     IF a$ = "u" OR a$ = "U" THEN
  355.         a$ = ""
  356.         SCREEN undo&
  357.         s& = undo&
  358.         _PUTIMAGE , s&, picture&
  359.         mouseLeftButton = 0
  360.     END IF
  361.     'Here is the Printing of the picture.
  362.     IF a$ = "p" OR a$ = "P" THEN
  363.         a$ = ""
  364.         m = 0
  365.         IF bcol <> 1 THEN
  366.             j& = _COPYIMAGE(0)
  367.             _DELAY .25
  368.             INPUT "Print on printer (Y/N)?", i$ 'print screen page on printer
  369.             CLS
  370.             SCREEN j&
  371.             _DELAY .25
  372.             IF LEFT$(i$, 1) = "y" OR LEFT$(i$, 1) = "Y" THEN
  373.                 'printer prep (code copied and pasted from bplus Free Calendar Program)
  374.                 YMAX = _HEIGHT: XMAX = _WIDTH
  375.                 landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  376.                 _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  377.                 _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  378.                 _PRINTIMAGE landscape&
  379.                 _DELAY 2
  380.                 landscape& = 0
  381.                 s& = j&
  382.             END IF
  383.         END IF
  384.     END IF
  385.  
  386. 'Saving Section
  387. saving:
  388. nm$ = GetSaveFileName("Save Image", ".\", "JPG Image (.jpg)|*.jpg|PNG Image (.png)|*.png|GIF Image (.gif)|*.gif|BMP Image (.bmp)|*.bmp", 1, OFN_OVERWRITEPROMPT + OFN_NOCHANGEDIR, _WINDOWHANDLE)
  389. IF nm$ = "" THEN GOTO skipsave:
  390. Result = SaveImage(nm$, 0, 0, 0, _WIDTH(img), _HEIGHT(img)) 'first zero is your screen, second zero is X start, 3th zero is y start
  391. nm$ = ""
  392. skipsave:
  393. m = 0
  394. a% = 0
  395. a$ = ""
  396. mouseLeftButton = 0
  397. button = 1
  398.  
  399. 'Loading Section
  400. loading:
  401. nm$ = GetOpenFileName$("Open Image", ".\", "JPG Image (.jpg)|*.jpg|PNG Image (.png)|*.png|GIF Image (.gif)|*.gif|BMP Image (.bmp)|*.bmp", 1, OFN_FILEMUSTEXIST + OFN_NOCHANGEDIR + OFN_READONLY, _WINDOWHANDLE)
  402. IF nm$ = "" THEN GOTO skipopen:
  403. l = 0
  404. i& = _LOADIMAGE(nm$, 32)
  405. s& = i&
  406. i& = 0
  407. screenx = _WIDTH
  408. screeny = _HEIGHT
  409. picture& = _NEWIMAGE(screenx, screeny, 32)
  410. back& = _RGB32(255, 255, 255)
  411. nm$ = ""
  412. skipopen:
  413. m = 0
  414. a% = 0
  415. a$ = ""
  416. mouseLeftButton = 0
  417. button = 1
  418.  
  419.  
  420. FUNCTION colorDialog$
  421.  
  422.     'first screen dimensions items to restore at exit
  423.     DIM curRow AS INTEGER, curCol AS INTEGER, autoDisplay AS INTEGER
  424.     DIM curScrn AS LONG, backScrn AS LONG 'some handles
  425.  
  426.     DIM cd AS LONG
  427.     DIM makeConst$, k$
  428.     DIM f AS SINGLE
  429.  
  430.     'save old settings to restore at end ofsub
  431.     curRow = CSRLIN
  432.     curCol = POS(0)
  433.     autoDisplay = _AUTODISPLAY
  434.     sw = _WIDTH
  435.     sh = _HEIGHT
  436.     fg = _DEFAULTCOLOR
  437.     bg = _BACKGROUNDCOLOR
  438.     _KEYCLEAR
  439.     'screen snapshot
  440.     curScrn = _DEST
  441.     backScrn = _NEWIMAGE(sw, sh, 32)
  442.     _PUTIMAGE , curScrn, backScrn
  443.  
  444.     cd = _NEWIMAGE(800, 600, 32)
  445.     SCREEN cd
  446.     r = 128: g = 128: b = 128: a = 128
  447.     COLOR &HFFDDDDDD, 0
  448.     DO
  449.         CLS
  450.         makeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  451.         slider 16, 10, r, "Red"
  452.         slider 16, 60, g, "Green"
  453.         slider 16, 110, b, "Blue"
  454.         slider 16, 160, a, "Alpha"
  455.         _PRINTSTRING (150, 260), "Press Enter or Spacebar, if you want to use the color: " + makeConst$
  456.         _PRINTSTRING (210, 280), "Press Escape or Q to not use any color, returns 0."
  457.         LINE (90, 300)-(710, 590), , B
  458.         FOR i = 100 TO 700
  459.             f = 255 * (i - 100) / 600
  460.             LINE (i, 310)-STEP(0, 30), _RGB32(f, 0, 0): LINE (i, 310)-STEP(0, 20), VAL(makeConst$)
  461.             LINE (i, 340)-STEP(0, 30), _RGB32(0, f, 0): LINE (i, 340)-STEP(0, 20), VAL(makeConst$)
  462.             LINE (i, 370)-STEP(0, 30), _RGB32(0, 0, f): LINE (i, 370)-STEP(0, 20), VAL(makeConst$)
  463.             LINE (i, 400)-STEP(0, 30), _RGB32(f, f, 0): LINE (i, 400)-STEP(0, 20), VAL(makeConst$)
  464.             LINE (i, 430)-STEP(0, 30), _RGB32(0, f, f): LINE (i, 430)-STEP(0, 20), VAL(makeConst$)
  465.             LINE (i, 460)-STEP(0, 30), _RGB32(f, 0, f): LINE (i, 460)-STEP(0, 20), VAL(makeConst$)
  466.             LINE (i, 490)-STEP(0, 30), _RGB32(f, f, f): LINE (i, 490)-STEP(0, 20), VAL(makeConst$)
  467.             LINE (i, 520)-STEP(0, 30), _RGB32(0, 0, 0): LINE (i, 520)-STEP(0, 20), VAL(makeConst$)
  468.             LINE (i, 550)-STEP(0, 30), _RGB32(255, 255, 255): LINE (i, 550)-STEP(0, 20), VAL(makeConst$)
  469.         NEXT
  470.         WHILE _MOUSEINPUT: WEND
  471.         mb = _MOUSEBUTTON(1)
  472.         IF mb THEN 'clear it
  473.             mx = _MOUSEX: my = _MOUSEY
  474.             IF mx >= 16 AND mx <= 781 THEN
  475.                 IF my >= 10 AND my <= 50 THEN
  476.                     r = INT((mx - 16) / 3)
  477.                 ELSEIF my >= 60 AND my <= 100 THEN
  478.                     g = INT((mx - 16) / 3)
  479.                 ELSEIF my >= 110 AND my <= 150 THEN
  480.                     b = INT((mx - 16) / 3)
  481.                 ELSEIF my >= 160 AND my <= 200 THEN
  482.                     a = INT((mx - 16) / 3)
  483.                 END IF
  484.             END IF
  485.         END IF
  486.         k$ = INKEY$
  487.         IF LEN(k$) THEN
  488.             IF ASC(k$) = 27 OR k$ = "q" THEN EXIT DO
  489.             IF ASC(k$) = 13 OR k$ = " " THEN colorDialog$ = makeConst$: EXIT DO
  490.         END IF
  491.         _DISPLAY
  492.         _LIMIT 60
  493.     LOOP
  494.  
  495.     'put things back
  496.     SCREEN curScrn
  497.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  498.     _PUTIMAGE , backScrn
  499.     _DISPLAY
  500.     COLOR fg, bg
  501.     _FREEIMAGE backScrn
  502.     _FREEIMAGE cd
  503.     IF autoDisplay THEN _AUTODISPLAY
  504.     'clear key presses
  505.     _KEYCLEAR
  506.     'clear mouse clicks
  507.     mb = _MOUSEBUTTON(1)
  508.     IF mb THEN 'clear it
  509.         WHILE mb 'OK!
  510.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  511.             _LIMIT 10
  512.         WEND
  513.     END IF
  514.     LOCATE curRow, curCol
  515.  
  516.  
  517. SUB slider (x, y, value, label$)
  518.     DIM c~&, s$
  519.     SELECT CASE label$
  520.         CASE "Red": c~& = &HFFFF0000
  521.         CASE "Green": c~& = &HFF008800
  522.         CASE "Blue": c~& = &HFF0000FF
  523.         CASE "Alpha": c~& = &H88FFFFFF
  524.     END SELECT
  525.     LINE (x, y)-STEP(765, 40), c~&, B
  526.     LINE (x, y)-STEP(3 * value, 40), c~&, BF
  527.     s2$ = STR$(value)
  528.     s3$ = LTRIM$(RTRIM$(s2$))
  529.     s$ = label$ + " = " + s3$
  530.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  531.  
  532. SUB paint3 (x0, y0, fill AS _UNSIGNED LONG) ' needs max, min functions
  533.     DIM fillColor AS _UNSIGNED LONG, W, H, parentF, tick, ystart, ystop, xstart, xstop, x, y
  534.     fillColor = POINT(x0, y0)
  535.     'PRINT fillColor
  536.     W = _WIDTH - 1: H = _HEIGHT - 1
  537.     DIM temp(W, H)
  538.     temp(x0, y0) = 1: parentF = 1
  539.     PSET (x0, y0), fill
  540.     WHILE parentF = 1
  541.         parentF = 0: tick = tick + 1
  542.         ystart = max(y0 - tick, 0): ystop = min(y0 + tick, H)
  543.         y = ystart
  544.         WHILE y <= ystop
  545.             xstart = max(x0 - tick, 0): xstop = min(x0 + tick, W)
  546.             x = xstart
  547.             WHILE x <= xstop
  548.                 IF POINT(x, y) = fillColor AND temp(x, y) = 0 THEN
  549.                     IF temp(max(0, x - 1), y) THEN
  550.                         temp(x, y) = 1: parentF = 1: PSET (x, y), fill
  551.                     ELSEIF temp(min(x + 1, W), y) THEN
  552.                         temp(x, y) = 1: parentF = 1: PSET (x, y), fill
  553.                     ELSEIF temp(x, max(y - 1, 0)) THEN
  554.                         temp(x, y) = 1: parentF = 1: PSET (x, y), fill
  555.                     ELSEIF temp(x, min(y + 1, H)) THEN
  556.                         temp(x, y) = 1: parentF = 1: PSET (x, y), fill
  557.                     END IF
  558.                 END IF
  559.                 x = x + 1
  560.             WEND
  561.             y = y + 1
  562.         WEND
  563.     WEND
  564.  
  565.  
  566. FUNCTION min (n1, n2)
  567.     IF n1 > n2 THEN min = n2 ELSE min = n1
  568.  
  569. FUNCTION max (n1, n2)
  570.     IF n1 < n2 THEN max = n2 ELSE max = n1
  571.  
  572. '================================================================================
  573. '================================================================================
  574. '================================================================================
  575. FUNCTION RightClickMenu% ()
  576.  
  577.     'Returns 0 if nothing selected, else return number of item selected.
  578.     'Requires RightClickList$ array defined.
  579.  
  580.     Cheese = _MOUSEINPUT
  581.  
  582.  
  583.         Row = FIX(_MOUSEY / 16): Col = FIX(_MOUSEX / 8)
  584.  
  585.         x = Col * 8 - 8: y = Row * 16 - 16
  586.  
  587.         '=== Compute BoxWidth based on longest menu item string length
  588.         BoxWidth = 0
  589.         FOR t = 1 TO RightClickItems
  590.             temp = LEN(RightClickList$(t))
  591.             IF LEFT$(RightClickList$(t), 1) = "-" THEN temp = temp - 1
  592.             IF temp > BoxWidth THEN BoxWidth = temp
  593.         NEXT: BoxWidth = BoxWidth * 8
  594.  
  595.         '=== Compute BoxHeight based on num of menu items
  596.         BoxHeight = RightClickItems * 16
  597.  
  598.         '===== Make sure Mouse not too close to edge of screen
  599.         '===== If it is, Adjust x & y position here, move in closer...
  600.         IF _MOUSEX < 20 THEN
  601.             Col = 3: x = Col * 8 - 8:
  602.         END IF
  603.         IF _MOUSEX + BoxWidth + 20 > _WIDTH THEN
  604.             xm = _WIDTH - (BoxWidth + 10)
  605.             Col = FIX(xm / 8): x = Col * 8 - 8:
  606.         END IF
  607.         IF _MOUSEY < 20 THEN
  608.             Row = 2: y = Row * 16 - 16
  609.         END IF
  610.         IF _MOUSEY + BoxHeight + 20 > _HEIGHT THEN
  611.             xy = _HEIGHT - (BoxHeight + 10)
  612.             Row = FIX(xy / 16): y = Row * 16 - 16
  613.         END IF
  614.  
  615.         FirstRow = Row - 1
  616.  
  617.         '=== copy screen using _mem (thanks Steve!)
  618.         DIM m AS _MEM, n AS _MEM
  619.         m = _MEMIMAGE(0)
  620.         n = _MEMNEW(m.SIZE)
  621.         _MEMCOPY m, m.OFFSET, m.SIZE TO n, n.OFFSET
  622.  
  623.         '=== trap until buttons up
  624.         DO
  625.             nibble = _MOUSEINPUT
  626.         LOOP UNTIL NOT _MOUSEBUTTON(2)
  627.  
  628.         '=== Draw Box (10 pix padding)
  629.         LINE (x - 10, y - 10)-(x + 10 + BoxWidth, y + 10 + BoxHeight), _RGB(214, 211, 206), BF
  630.         LINE (x + 10 + BoxWidth, y - 10)-(x + 10 + BoxWidth, y + 10 + BoxHeight), _RGB(66, 65, 66), B
  631.         LINE (x - 10, y + 10 + BoxHeight)-(x + 10 + BoxWidth, y + 10 + BoxHeight), _RGB(66, 65, 66), B
  632.         LINE (x - 9, y - 9)-(x + 9 + BoxWidth, y + 9 + BoxHeight), _RGB(255, 255, 255), B
  633.         LINE (x - 9, y - 9)-(x + 9 + BoxWidth, y + 9 + BoxHeight), _RGB(255, 255, 255), B
  634.         LINE (x + 9 + BoxWidth, y - 9)-(x + 9 + BoxWidth, y + 9 + BoxHeight), _RGB(127, 127, 127), B
  635.         LINE (x - 9, y + 9 + BoxHeight)-(x + 9 + BoxWidth, y + 9 + BoxHeight), _RGB(127, 127, 127), B
  636.  
  637.         DO
  638.             Cheese = _MOUSEINPUT
  639.  
  640.             '=== if in bounds of menu space
  641.             IF _MOUSEX > x AND _MOUSEX < x + BoxWidth AND _MOUSEY > y AND _MOUSEY < y + BoxHeight THEN
  642.  
  643.                 '=== Draw items
  644.                 IF CurRow <> FIX(_MOUSEY / 16) THEN
  645.                     COLOR _RGB(0, 0, 0), _RGB(214, 211, 206)
  646.                     FOR t = 0 TO RightClickItems - 1
  647.                         IF Row + t - FirstRow = FIX(_MOUSEY / 16) - FirstRow + 1 THEN
  648.                             'Draw highlight box...
  649.                             COLOR _RGB(255, 255, 255), _RGB(8, 36, 107)
  650.                         ELSE
  651.                             IF LEFT$(RightClickList$(t + 1), 1) = "-" THEN
  652.                                 COLOR _RGB(130, 130, 130), _RGB(214, 211, 206)
  653.                             ELSE
  654.                                 COLOR _RGB(0, 0, 0), _RGB(214, 211, 206)
  655.                             END IF
  656.                         END IF
  657.                         padme = BoxWidth / 8 - LEN(RightClickList$(t + 1))
  658.                         IF LEFT$(RightClickList$(t + 1), 1) = "-" THEN padme = padme - 1
  659.                         IF padme > 0 THEN pad$ = SPACE$(padme) ELSE pad$ = ""
  660.                         LOCATE Row + t, Col - 1
  661.                         IF RightClickList$(t + 1) = "---" THEN
  662.                             COLOR _RGB(127, 127, 127), _RGB(214, 211, 206)
  663.                             PRINT STRING$((BoxWidth / 8) + 2, 196);
  664.                         ELSE
  665.                             IF LEFT$(RightClickList$(t + 1), 1) = "-" THEN
  666.                                 PRINT " "; RIGHT$(RightClickList$(t + 1), LEN(RightClickList$(t + 1)) - 1); pad$; " ";
  667.                             ELSE
  668.                                 PRINT " "; RightClickList$(t + 1); pad$; " ";
  669.                             END IF
  670.                         END IF
  671.                     NEXT
  672.                 END IF
  673.  
  674.                 IF _MOUSEBUTTON(1) THEN
  675.                     sel = FIX(_MOUSEY / 16) - FirstRow + 1
  676.                     'only select if not a seperator and not disabled
  677.                     IF RightClickList$(sel) <> "---" THEN
  678.                         IF LEFT$(RightClickList$(sel), 1) <> "-" THEN
  679.                             RightClickMenu% = sel: EXIT DO
  680.                         END IF
  681.                     END IF
  682.                 END IF
  683.  
  684.                 IF _MOUSEBUTTON(2) THEN EXIT DO
  685.  
  686.             ELSE
  687.  
  688.                 '=== Draw items
  689.                 IF FIX(_MOUSEY / 16) <> CurRow THEN
  690.                     FOR t = 0 TO RightClickItems - 1
  691.                         padme = BoxWidth / 8 - LEN(RightClickList$(t + 1))
  692.                         IF LEFT$(RightClickList$(t + 1), 1) = "-" THEN padme = padme - 1
  693.                         IF padme > 0 THEN pad$ = SPACE$(padme) ELSE pad$ = ""
  694.                         LOCATE Row + t, Col - 1
  695.                         IF RightClickList$(t + 1) = "---" THEN
  696.                             COLOR _RGB(127, 127, 127), _RGB(214, 211, 206)
  697.                             PRINT STRING$((BoxWidth / 8) + 2, 196);
  698.                         ELSE
  699.  
  700.                             IF LEFT$(RightClickList$(t + 1), 1) = "-" THEN
  701.                                 COLOR _RGB(127, 127, 127), _RGB(214, 211, 206)
  702.                                 PRINT " "; RIGHT$(RightClickList$(t + 1), LEN(RightClickList$(t + 1)) - 1); pad$; " ";
  703.                             ELSE
  704.                                 COLOR _RGB(0, 0, 0), _RGB(214, 211, 206)
  705.                                 PRINT " "; RightClickList$(t + 1); pad$; " ";
  706.                             END IF
  707.  
  708.                         END IF
  709.                     NEXT
  710.                 END IF
  711.  
  712.                 IF _MOUSEBUTTON(1) OR _MOUSEBUTTON(2) THEN EXIT DO
  713.  
  714.             END IF
  715.  
  716.             '=== Mark current row mouse is in
  717.             CurRow = FIX(_MOUSEY / 16)
  718.  
  719.         LOOP
  720.  
  721.         '### Make sure both buttons are up before leaving
  722.         '### Added by Dav for bug testing...
  723.         DO
  724.             nibble = _MOUSEINPUT
  725.             IF _MOUSEBUTTON(1) = 0 AND _MOUSEBUTTON(2) = 0 THEN EXIT DO
  726.         LOOP
  727.  
  728.         '=== restore screen
  729.         _MEMCOPY n, n.OFFSET, n.SIZE TO m, m.OFFSET
  730.         _MEMFREE m: _MEMFREE n
  731.  
  732.     END IF
  733.  
  734. '================================================================================
  735. '================================================================================
  736. '================================================================================
  737.  
  738.  
  739. '$include:'saveimage.bm'
  740. '$include:'opensave.bm'
  741.  
  742.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #5 on: July 02, 2020, 06:16:53 pm »
Thanks Dav, that did the job perfectly. I also fixed the freeze-ups like you were talking about. I added some _WAIT commands and sped up the _LIMIT command to 1500. I also decided to DIM all of the variables and strings I use (but not anyone else's code that's in the program since they may already be dimmed and I don't know anything about Functions). That seems to do the job. I've ran many tests on it and I guess if someone went totally nuts and used their mouse faster than I could possibly go, there COULD be a chance it freezes up still, but even then maybe not. Of course almost all apps on a Windows computer can freeze up if you totally went crazy with it. LOL Oh, I also found out that both you and I are using the same m variable for 2 different things, so I changed mine to mo (which stands for mode). I know you were using yours for memory.

For everyone: Here is the updated ZIP file with all of the files needed to run. I will remove the zip file above so nobody can run into the errors I've fixed. I have decided to removed the paint screen keyboard commands completely (except Esc to go back to the front page). This updated version also has new ways to use Straight Lines, Circles, and Boxes. After selecting what you want to draw with, you click on where you want it to be and then hold down the left mouse button to make the right size and shape. When you release the left mouse button, it puts it there on your picture. You will notice that often it's hard to see the lines, circles, and boxes as you resize them, but it's as good as I can do I believe. I tried them with _DISPLAY but that didn't work. So here it is, this might be the final version for awhile. I've worked so hard on this little program off and on since last August or so. I still remember the first version using X and Y data text files to store the images LOL. Tell me what you think, it's been a labor of love.

Supports: JPG, PNG, GIF, BMP files.

Update: I have deleted this zip file again to make lines, circles, and boxes show up TONS better. Scroll down to the next zip please.
« Last Edit: July 02, 2020, 09:33:49 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #6 on: July 02, 2020, 09:36:16 pm »
I figured out how to make the lines, circles, and boxes show up perfectly when you reshape and resize them with the mouse. _DISPLAY does work, I just had to add it to the right locations and also put _AUTODISPLAY at the end of the modes. :))) Here is the zip file, hopefully the last one for version 8. I hope you enjoy it. And I apologize for so many zip files on this thread, the older ones have been deleted.

Update: Another fixed .zip file is below. Sorry guys!
« Last Edit: July 02, 2020, 10:37:47 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #7 on: July 02, 2020, 10:05:00 pm »
Man!

@SierraKen you've come a long way! That pop-up is great addition along with background selector, you fixed the box and circle drawing, very impressive!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #8 on: July 02, 2020, 10:09:16 pm »
Good job.  It's working better for me too - no crashes yet.  For some reason though the fill-in stopped working right in the middle of creating my happy little world.  I was planning a hideaway cabin by the lake, but thats ok, as Bob Ross said - we don't make mistakes - we have happy little accidents.

- Dav

 
PixelPaint8Test.jpg



Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #9 on: July 02, 2020, 10:25:12 pm »
Thanks B+ and Dav! :)))

Dav, I just fixed it. You had to click twice the first time for Fill to work but it was because I accidentally had 2 different places to make the mouse button 0. So here is the zip file all fixed up and as good as new. :)

"Woops I did it again!"... I removed the zip file again to fix it. Dav is helping me test it out. The fix should be on the next zip.

« Last Edit: July 02, 2020, 11:39:31 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #10 on: July 02, 2020, 10:38:34 pm »
By the way, that's a great pic you made Dav!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #11 on: July 02, 2020, 11:21:31 pm »
Thanks!  The fill-in is working good now.  However, I still get an occasional crash when drawing circles, and also erasing.  I was going to draw a fly buzzing on the right side of this frog for it to eat, but it crashed out (I saved it first).  Poor Kermit has to go hungry now.  It's not easy being green.

(I kind of copied this character from another frog picture I was looking at, so I didn't invent this frog character)

- Dav

 
frog.jpg


« Last Edit: July 02, 2020, 11:26:15 pm by Dav »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #12 on: July 02, 2020, 11:41:27 pm »
LOL GREAT Frog!

I think I fixed it. I upped the _DELAY on the circles a little bit and I found an unnecessary line in the Eraser section that copied the screen one too many times. Please try this one for me. Thanks.

Update: Zip removed again because of newer bug. It is fixed on this forum thread's page 2 (The next one with the zip file).
« Last Edit: July 03, 2020, 02:53:39 pm by SierraKen »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #13 on: July 03, 2020, 11:23:31 am »
Yes - it's much more stable for me now. The erasing crashes haven't happened again, but circle did only once while making this next image.

There is a problem using boxes & circles after opening an image. Try selecting drawing a box or circle after opening a BMP, it's not working for me after opening something.  However, if you first select draw and then do a box/circle they will work again.   

I have a color picking suggestion - It would be helpful when picking a new color that the currently selected color is set in the selection boxes, instead of going back to default.

- Dav

 
swirls.jpg

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Paint Pixels 8 With Right-Click Menu
« Reply #14 on: July 03, 2020, 12:19:02 pm »
Cool drawing!
That's really bizarre about your not being able to use boxes or circles without drawing first because it doesn't happen on my computer. Plus it's automatically set on drawing mode when you start the program. So since I can't duplicate the problem, I can't fix it. I did overlook it briefly to see if anything stood out but I can't see anything. I am wondering though, are you using an older computer? I use the 64 bit QB64. If that makes any difference I have no idea. I just know faster computers run things smoother.
And that is an interesting idea for the color picker. B+ would have to do that since that is all his code.
Anyway, thanks for the help Dav. I appreciate it.

Edit: I apologize, I just re-read what you said and wasn't opening a picture first before selecting boxes or circles. I just did it and see what you are talking about. I'll check into it. Thank you.
« Last Edit: July 03, 2020, 02:08:11 pm by SierraKen »