Tuesday, November 8, 2022

Enhancing the Arrow buttons in the Macintosh HyperCard 2.4.1 Home stack

HyperCard 2.4.1 Home stack changes for enhanced left/right arrow buttons

by Brendan Bellina 11/2022


Benefits of these changes

~~~~~~~~~~~~~~~~~~~~


Unenhanced the Home stack allows 5 Home Card cards to be displayed along the bottom. Additional cards can be created via the New Card menu option and accessed via the arrow buttons, but their names will not be displayed along the bottom of the Home card. When enhanced any added cards will scroll along the bottom when the arrow buttons are used to navigate. This encourages spreading QuickLinks across multiple cards rather than crowding them all onto the five standard Home cards.


Unenhanced the left/right arrow buttons in the Home stack cycle through all cards in the stack, not just the Home Card background. When enhanced the buttons advance only through the Home Cards. The User Preference cards remain accessible via the Home menu.


Holding down the option key while clicking on an enhanced left/right arrow button  will execute their original unenhanced logic.


Known issues

~~~~~~~~~~


The enhanced buttons require Home cards to be uniquely named.


When creating new Home Cards, if a name is not specified for the new card then standard behavior is that it is defaulted to "Untitled Card" which can lead to duplicate card names. For this reason if an "Untitled Card" button is scrolled off the screen and then back onto the screen its name will be changed to its unique card id.


When deleting the last Home card some Home menu options will be incorrectly disabled. To reenable them select Preferences from the Home menu and then return to the Home cards. This is a bug in the unmodified Home stack code that is more noticable since the enhanced left/right arrow buttons make adding more Home cards a more reasonable thing to do than crowding all QuickLinks on the five standard Home cards.


The Home Card title buttons are not defined in a button family, so it is possible for multiple of them to be hilited at the same time or none hilited. While this should not happen, if it does then use the arrow buttons to scroll through the cards and the hiliting will be corrected.


Applying these Enhancements

~~~~~~~~~~~~~~~~~~~~~~~


1. Add the following to the "Home Cards" background script":


---

Message Handlers added to this script by B Bellina 11/2022:

openCard, resetToFirstCard


on openCard -- added by B Bellina 11/2022

  -- required for enhanced "left arrow" "right arrow" buttons

  put ((number of bg btn id 169) - 1) into homeCardBtnCnt

  -- Determine which btn to hilite

  get the short name of this card

  put false into foundIt

  repeat with i = 1 to homeCardBtnCnt

    if short name of bg btn i is it then

      put true into foundIt

      exit repeat

    end if

  end repeat

  if foundIt then

    put i into foundCardNum

    repeat with i = 1 to homeCardBtnCnt

      set hilite of bg btn i to (i = foundCardNum)

    end repeat

  else

    -- failed to find so reset to first card (normally Welcome to...)

    resetToFirstCard

  end if

  pass openCard -- so others can use it

end openCard


on resetToFirstCard -- added by B Bellina 11/2022

  -- required for enhanced "left arrow" "right arrow" buttons

  if short name of this card is not short name of cd 1 then go cd 1

  put ((number of bg btn id 169) - 1) into homeCardBtnCnt

  repeat with i = 1 to homeCardBtnCnt

    set name of bg btn i to short name of cd i

    set hilite of bg btn i to false

  end repeat

  set hilite of bg btn 1 to true

end resetToFirstCard

---


2. Replace the mouseUp handler of the "left arrow" button with the following:


on mouseUp

  -- enhanced "left arrow" button logic

  -- by Brendan Bellina 11/2022

  -- also requires openCard and resetToFirstCard handlers in the

  -- background script

  if the optionKey is down then

    -- original logic for the button

    visual effect wipe right

    go prev card

  else -- enhanced logic

    lock screen

    set cursor to watch

    -- how many buttons along the bottom, typically 5

    put ((number of bg btn id 169) - 1) into homeCardBtnCnt

    -- how many home cards (they are cards 1...n)

    put number of cards of this bg into homeCardCnt

    if homeCardBtnCnt = homeCardCnt then

      go to prev card of this bg

      unlock screen with visual effect wipe right

    else -- more cards than buttons

      -- determine which button is hilited

      put 0 into fromCdBtnNum

      put short name of this cd into thisCd

      repeat with i = 1 to homeCardBtnCnt

        if hilite of bg btn i is true or ¬

        short name of bg btn i is thisCd then

          put i into fromCdBtnNum

          exit repeat

        end if

      end repeat

      if fromCdBtnNum = 0 then -- messed up so do default action

        go to prev card of this bg

        unlock screen with visual effect wipe right

        exit mouseUp

      end if

      if fromCdBtnNum is 1 then

        -- scroll all of the buttons except the rightmost to the right

        repeat with i = (homeCardBtnCnt - 1) down to 1

          set name of bg btn (i + 1) to short name of bg btn i

        end repeat

        put number of prev cd of this bg into prevCdNum

        get short name of cd prevCdNum

        if it is empty or it is "Untitled Card" then -- no dups allowed

          put id of cd prevCdNum into it

          set name of cd prevCdNum to it

        end if

        set name of bg btn 1 to short name of cd prevCdNum

        go to prev cd of this bg

        repeat with i = 1 to homeCardBtnCnt

          set hilite of bg btn i to (i = 1)

        end repeat

        unlock screen with visual effect wipe right

      else

        go to prev cd of this bg

        repeat with i = 1 to homeCardBtnCnt

          set hilite of bg btn i to (i = fromCdBtnNum - 1)

        end repeat

        unlock screen with visual effect wipe right

      end if

    end if

  end if

end mouseUp


3. Replace the mouseUp handler of the "right arrow" button with the following:


on mouseUp

  -- enhanced "right arrow" button logic

  -- by Brendan Bellina 11/2022

  -- also requires openCard and resetToFirstCard handlers in the

  -- background script

  if the optionKey is down then

    -- original logic for the button

    visual effect wipe left

    go next card

  else -- enhanced logic

    lock screen

    set cursor to watch

    -- how many buttons along the bottom, typically 5

    put ((number of bg btn id 169) - 1) into homeCardBtnCnt

    -- how many home cards (they are cards 1...n)

    put number of cards of this bg into homeCardCnt

    if homeCardBtnCnt = homeCardCnt then

      go to next card of this bg

      unlock screen with visual effect wipe left

    else -- more cards than buttons

      -- determine which button is hilited

      put 0 into fromCdBtnNum

      put short name of this cd into thisCd

      repeat with i = 1 to homeCardBtnCnt

        if hilite of bg btn i is true or ¬

        short name of bg btn i is thisCd then

          put i into fromCdBtnNum

          exit repeat

        end if

      end repeat

      if fromCdBtnNum = 0 then -- messed up so do default action

        go to next card of this bg

        unlock screen with visual effect wipe left

        exit mouseUp

      end if

      if fromCdBtnNum is homeCardBtnCnt then

        -- scroll all of the buttons except the leftmost to the left

        repeat with i = 2 to homeCardBtnCnt

          set name of bg btn (i - 1) to short name of bg btn i

        end repeat

        put number of next cd of this bg into nextCdNum

        get short name of cd nextCdNum

        if it is empty or it is "Untitled Card" then -- no dups allowed

          put id of cd nextCdNum into it

          set name of cd nextCdNum to it

        end if

        set name of bg btn homeCardBtnCnt to short name of cd nextCdNum

        go to next cd of this bg

        repeat with i = 1 to homeCardBtnCnt

          set hilite of bg btn i to (i = homeCardBtnCnt)

        end repeat

        unlock screen with visual effect wipe left

      else

        go to next cd of this bg

        repeat with i = 1 to homeCardBtnCnt

          set hilite of bg btn i to (i = fromCdBtnNum + 1)

        end repeat

        unlock screen with visual effect wipe left

      end if

    end if

  end if

end mouseUp



No comments:

Post a Comment