Author Topic: There goes Pete, pushing Steve's buttons again!  (Read 2448 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
There goes Pete, pushing Steve's buttons again!
« on: February 18, 2021, 05:22:24 pm »
Code: QB64: [Select]
  1. row% = 10: col% = 34: bw% = 13: bh% = 2
  2. button_text$ = "Whole Word"
  3.  
  4. REM PRINT "Input button column width: ";: INPUT bw%
  5. REM PRINT "Input button row height: ";: INPUT bh%
  6. REM PRINT "Input button row: ";: INPUT row%
  7. REM PRINT "Input button column: ";: INPUT col%
  8.  
  9. GOSUB formatbutton
  10.  
  11. GOSUB bdisplay
  12.  
  13.     _LIMIT 60
  14.     mb.l = _MOUSEBUTTON(1)
  15.     mx% = _MOUSEX
  16.     my% = _MOUSEY
  17.  
  18.     IF my% = row% + bh% - 1 AND mx% = col% + bw% - 1 OR my% = row% AND mx% = col% THEN
  19.         IF capp% <> 1 THEN _MOUSESHOW "TOPLEFT_BOTTOMRIGHT": capp% = 1
  20.     ELSEIF my% = row% AND mx% = col% + bw% - 1 OR my% = row% + bh% - 1 AND mx% = col% THEN
  21.         IF capp% <> 2 THEN _MOUSESHOW "TOPRIGHT_BOTTOMLEFT": capp% = 2
  22.     ELSE
  23.         IF capp% THEN _MOUSESHOW "DEFAULT": capp% = 0
  24.     END IF
  25.  
  26.     IF mb.l THEN
  27.         IF lbdown% = 0 THEN
  28.             lbdown% = 1 ' Left mouse button down
  29.         END IF
  30.     ELSE
  31.         IF lbdown% THEN lbdown% = 0 ' Left mouse button released
  32.     END IF
  33.  
  34.     IF drag% THEN
  35.         IF lbdown% THEN
  36.             SELECT CASE drag%
  37.                 CASE -1
  38.                     mx% = _MOUSEX
  39.                     my% = _MOUSEY
  40.                     row% = my% - rdrag%
  41.                     IF row% < 1 THEN row% = 1
  42.                     IF row% + bh% > _HEIGHT THEN row% = _HEIGHT - bh% + 1
  43.                     col% = mx% - cdrag%
  44.                     IF col% < 1 THEN col% = 1
  45.                     IF col% + bw% > _WIDTH THEN col% = _WIDTH - bw% + 1
  46.                     IF oldrow% <> row% OR oldcol% <> col% THEN GOSUB dhover
  47.                     oldrow% = row%: oldcol% = col%
  48.                 CASE 1 ' Left side
  49.                     IF mx% <> oldmx% THEN
  50.                         IF bw% + (oldmx% - mx%) > 2 THEN
  51.                             bw% = bw% + (oldmx% - mx%) ' Expand or shrink width.
  52.                             col% = col% - (oldmx% - mx%)
  53.                         END IF
  54.                     END IF
  55.                     IF my% <> oldmy% THEN
  56.                         IF oldmy% < row% + bh% - 1 THEN
  57.                             IF bh% - (my% - oldmy%) > 1 THEN
  58.                                 row% = row% + (my% - oldmy%) ' Expand or Shrink height upwards.
  59.                                 bh% = bh% - (my% - oldmy%)
  60.                             END IF
  61.                         ELSE
  62.                             IF bh% + (my% - oldmy%) > 1 THEN
  63.                                 bh% = bh% + (my% - oldmy%) ' Expand or Shrink height dowmwards.
  64.                             END IF
  65.                         END IF
  66.                     END IF
  67.                     GOSUB formatbutton
  68.                     GOSUB dhover
  69.                 CASE 2 ' Right side.
  70.                     IF mx% <> oldmx% THEN
  71.                         IF bw% + (mx% - oldmx%) > 2 THEN
  72.                             bw% = bw% + (mx% - oldmx%) ' Expand or shrink width.
  73.                         END IF
  74.                     END IF
  75.                     IF my% <> oldmy% THEN
  76.                         IF oldmy% >= row% + bh% - 1 THEN
  77.                             IF bh% + (my% - oldmy%) > 1 THEN
  78.                                 bh% = bh% + (my% - oldmy%) ' Expand or shrink height downwards.
  79.                             END IF
  80.                         ELSE
  81.                             IF bh% - (my% - oldmy%) > 1 THEN
  82.                                 row% = row% + (my% - oldmy%) ' Expand or shrink height upwards.
  83.                                 bh% = bh% - (my% - oldmy%)
  84.                             END IF
  85.                         END IF
  86.                     END IF
  87.                     GOSUB formatbutton
  88.                     GOSUB dhover
  89.             END SELECT
  90.         ELSE
  91.             drag% = 0
  92.             GOSUB bhover
  93.         END IF
  94.  
  95.     ELSE
  96.  
  97.         IF my% >= row% AND my% <= row% + bh% AND mx% >= col% AND mx% <= col% + bw% THEN
  98.             IF button_hover% = 0 THEN
  99.                 button_hover% = -1
  100.                 GOSUB bhover
  101.             END IF
  102.         ELSE
  103.             IF button_hover% THEN
  104.                 GOSUB bdisplay
  105.                 button_hover% = 0
  106.             END IF
  107.         END IF
  108.  
  109.         IF lbdown% = 1 AND button_hover% AND button_activated% = 0 THEN
  110.             button_activated% = -1
  111.             GOSUB bdisplay: _DELAY .1
  112.             SOUND 1000, .1
  113.             GOSUB bhover
  114.         ELSE
  115.             IF lbdown% = 0 AND button_activated% THEN
  116.                 button_activated% = 0
  117.             ELSE
  118.                 IF lbdown% = 1 AND button_activated% AND drag% = 0 THEN
  119.                     IF mx% = col% AND my% = row% OR mx% = col% AND my% = row% + bh% - 1 THEN
  120.                         drag% = 1 ' Left upper or lower corner.
  121.                     ELSEIF mx% = col% + bw% - 1 AND my% = row% OR mx% = col% + bw% - 1 AND my% = row% + bh% - 1 THEN
  122.                         drag% = 2 ' Right upper or lower corner.
  123.                     ELSE
  124.                         drag% = -1 ' Move.
  125.                         cdrag% = oldmx% - col%
  126.                         rdrag% = oldmy% - row%
  127.                     END IF
  128.                 END IF
  129.             END IF
  130.         END IF
  131.     END IF
  132.  
  133.     oldmx% = mx%: oldmy% = my%
  134.  
  135.  
  136. formatbutton:
  137. Gdown = Button_HW(bw% * 8, bh% * 16, 170, 170, 170, -9, -7, -1, MID$(button_text$, 1, bw% - 2))
  138. Ghover = Button_HW(bw% * 8, bh% * 16, 200, 200, 200, -8, -7, -1, MID$(button_text$, 1, bw% - 2))
  139. Gdrag = Button_HW(bw% * 8, bh% * 16, 200, 200, 200, -1, -1, -1, MID$(button_text$, 1, bw% - 2))
  140.  
  141. bdisplay:
  142. _PUTIMAGE ((col% - 1) * 8, (row% - 1) * 16), Gdown
  143.  
  144. bhover:
  145. _PUTIMAGE ((col% - 1) * 8, (row% - 1) * 16), Ghover
  146.  
  147. dhover:
  148. _PUTIMAGE ((col% - 1) * 8, (row% - 1) * 16), Gdrag
  149.  
  150. FUNCTION Button_HW (wide, tall, r, g, b, rc, gc, bc, caption$)
  151.     ' Courtesy of The Amazing Steve.
  152.     Dest = _DEST
  153.     t = _NEWIMAGE(wide, tall, 32)
  154.     _DEST t
  155.     FOR i = 0 TO 10
  156.         rm = rm + rc
  157.         gm = gm + gc
  158.         bm = bm + bc
  159.         k = _RGB32(r + rm, g + gm, b + bm)
  160.         LINE (x + i, y + i)-(x + wide - i, y + tall - i), k, B
  161.     NEXT
  162.     PAINT (x + i, y + i), k
  163.     COLOR _RGB32(r, g, b), 0
  164.     _PRINTSTRING (x + (wide - _PRINTWIDTH(caption$)) / 2, y + (tall - _FONTHEIGHT) / 2), caption$
  165.     Button_HW = _COPYIMAGE(t, 33)
  166.     _FREEIMAGE t
  167.  
  168.     _DEST Dest

EDIT: Added button resizing, but you can only do so at any one of the 4-corners. Go to a corner, hold the left mouse button down, and drag in a direction to resize.

You can drag the button anywhere on the screen, and it will make a click sound during a left mouse click. Slight display changes are seen with hover and drag.

I've known about mixing graphics with SCREEN 0 for quite some time, but I thought I'd have some fun today by actually using the _PUTIMAGE function Steve came up with, and adding my my mouse routine. It's a nice marriage, but it probably won't last. There's not enough room in the IDE to hold both of the egos.

Pete
« Last Edit: February 19, 2021, 11:35:10 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: There goes Pete, pushing Steve's buttons again!
« Reply #1 on: February 18, 2021, 05:28:08 pm »
MuHahahaha!! I am THE AMAZING STEVE(tm)!!  I even managed to teach Pete a new trick -- that's how amazing I am!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: There goes Pete, pushing Steve's buttons again!
« Reply #2 on: February 19, 2021, 04:26:01 pm »
Added bells and whistles, and yet it's still just a button... but now you can resize it, as well as hover, drag or click it.

Hey, didn't somebody come up with a simple way to change the mouse cursor appearance, to go with resizing?

So learned another new trick, and added Changing the cursor appearance at the corners!

Pete
« Last Edit: February 19, 2021, 11:35:56 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/