Need help with Menu

Find quick help here to get you started with Hollywood
Post Reply
User avatar
Redlion
Posts: 96
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

Need help with Menu

Post by Redlion »

Hi,
I am trying to create a menu in my program, I can create the menu bar and create the dropdown part, I can get the selected menu item but I do not know how to do it without distroying the display under the menu. I tried layers but I donot understand them and it did not work. Does anyone know how to overlay the menu onto the display and then remove the menu leaving the display intact ?

Regards
Redlion
----------------------------------------------------------------------------------------
Redlion
Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32
Bugala
Posts: 1180
Joined: Sun Feb 14, 2010 7:11 pm

Re: Need help with Menu

Post by Bugala »

A couple of questions first.

1. Are you making your own menu system? that you are not using for example AmigaOS supported menus?

2. When you talk of the display, do you mean a display that you yourself have created, for example, you are making a game with Hollywood, in which some of the options are in menus, or is that display for example workbench screen?
User avatar
Redlion
Posts: 96
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

Re: Need help with Menu

Post by Redlion »

@Bugala,

Yes I am making my own, I do not know what you mean by using the OS menu system.

Code: Select all

@DISPLAY 1,{x= 200,Y=200,Width =800,Height =600,Color = $999999}

SetFont("Ruby",12)
SetFontColor(#BLACK)

Line (1,23,800,23,#BLACK)

Box (30,30,400,30,#WHITE)

Global MP,MT,MTW,MC,MS,MM
Global ML,ML0,ML1,ML2,ML3
Function Menus() ;---------------------------------------------------------------------------------
  MenuItems = 4
  MenuTitle = {" File "," Drawing Shapes "," Program Help "," About "}
  Menu0 = {" Open "," Save "," Close "}
  Menu1 = {" Square "," Circle "," Triangle "," Box "}
  Menu2 = {" Help "}
  Menu3 = {" About "}
  For t = 0 to ListItems(Menu0)-1
    Length = TextWidth(Menu0[t])
    If Length > ML0
      ML0 = Length
    EndIf
  Next
  For t = 0 to ListItems(Menu1)-1
    Length = TextWidth(Menu1[t])
    If Length > ML1
      ML1 = Length
    EndIf
  Next
  For t = 0 to ListItems(Menu2)-1
    Length = TextWidth(Menu2[t])
    If Length > ML2
      ML2 = Length
    EndIf
  Next
   For t = 0 to ListItems(Menu3)-1
   Length = TextWidth(Menu3[t])
   If Length > ML3
     ML3 = Length
   EndIf
  Next
  MenuPos = {}
  MenuPosition = 2
  InsertItem(MenuPos,2)
  For t = 1 to MenuItems
    MakeButton(t,#SIMPLEBUTTON,MenuPosition,1,TextWidth(MenuTitle[t-1]),20,{OnMouseDown = MenuFunc,OnMouseOver = MenuFunc,OnMouseOut = MenuFunc,OnMouseUp = MenuFunc})
    TextOut(MenuPosition,5,MenuTitle[t-1])
    MenuPosition = MenuPosition + TextWidth(MenuTitle[t-1])
    InsertItem(MenuPos,MenuPosition)
  Next
EndFunction

Function MenuFunc(msg) ; --------------------------------------------------------------------------
  Switch msg.action
    Case "OnMouseDown":
      MakeMenu()
    Case "OnMouseOut":
      HighLightMenuOff(msg)
    Case "OnMouseOver"
      HighLightMenu(msg)
    Case "OnMouseUp":
      BreakMenu()
    EndSwitch
EndFunction

Function p_MyFunc(msg) ;---------------------------------------------------------------------------
  Switch msg.action
    Case "OnMouseDown":
      ShowMenu(msg)
    Case "OnMouseOut":
      BreakMenu(msg)
    Case "OnMouseUp":
      SelectMenu(msg)
   EndSwitch
EndFunction

Function HighlightMenu(msg) ;----------------------------------------------------------------------
  Switch msg.id
    Case 1:
      Menu = CopyTable(Menu0)
      MS = ListItems(Menu0)
      MP = MenuPos[0]
      MT = MenuTitle[0]
      MTW = TextWidth(MenuTitle[0])
      MC = $888888
      ML = ML0
      MM = 0
      MenuHighLight()
    Case 2:
      Menu = CopyTable(Menu1)
      MS = ListItems(Menu1)
      MP = MenuPos[1]
      MT = MenuTitle[1]
      MTW = TextWidth(MenuTitle[1])
      MC = $888888
      ML = ML1
      MM = 3
      MenuHighLight()
    Case 3:
      Menu = CopyTable(Menu2)
      MS = ListItems(Menu2)
      MP = MenuPos[2]
      MT = MenuTitle[2]
      MTW = TextWidth(MenuTitle[2])
      MC = $888888
      ML = ML2
      MM = 7
      MenuHighLight()
    Case 4:
      Menu = CopyTable(Menu3)
      MS = ListItems(Menu3)
      MP = MenuPos[3]
      MT = MenuTitle[3]
      MTW = TextWidth(MenuTitle[3])
      MC = $888888
      ML = ML3
      MM = 8
      MenuHighLight()
  EndSwitch
EndFunction

Function HighlightMenuOff(msg) ;-------------------------------------------------------------------
  Switch msg.id
    Case 1:
      Menu = CopyTable(Menu0)
      MP = MenuPos[0]
      MT = MenuTitle[0]
      MTW = TextWidth(MenuTitle[0])
      MC = $999999
      If MM <> 0
        BreakMenu()
      EndIf
      MenuHighLight()
    Case 2:
      Menu = CopyTable(Menu1)
      MP = MenuPos[1]
      MT = MenuTitle[1]
      MTW = TextWidth(MenuTitle[1])
      MC = $999999
      If MM <> 3
        BreakMenu()
      EndIf
      MenuHighLight()
    Case 3:
      Menu = CopyTable(Menu2)
      MP = MenuPos[2]
      MT = MenuTitle[2]
      MTW = TextWidth(MenuTitle[2])
      MC = $999999
      If MM <> 7
        BreakMenu()
      EndIf
      MenuHighLight()
    Case 4:
      Menu = CopyTable(Menu3)
      MP = MenuPos[3]
      MT = MenuTitle[3]
      MTW = TextWidth(MenuTitle[3])
      MC = $999999
      If MM <> 8
        BreakMenu()
      EndIf
      MenuHighLight()
  EndSwitch
EndFunction

Function MenuHighLight() ; -----------------------------------------------
  SetFillStyle(#FILLCOLOR)
  Box(MP,1,MTW,20,MC)
  SetFontColor(#BLACK)
  TextOut(MP,5,MT)
EndFunction

Function MakeMenu() ; ----------------------------------------------------
  Box(MP,26,ML,(20*MS)+1,$888888)
  MakeButton(MenuItems+1,#SIMPLEBUTTON,MP,26,ML,(20*MS)+1,{OnMouseOver = p_MyFunc,OnMouseOut = p_MyFunc,OnMouseUp = p_MyFunc,OnMouseDown = p_MyFunc})
  For t = 0 to MS-1
    TextOut(MP+2,29+(t*20),Menu[t])
  Next
EndFunction

Function BreakMenu() ; ----------------------------------------------------
    Box(MP,26,ML,(20*MS)+1,$999999)
    DeleteButton(MenuItems+1)
EndFunction

Function ShowMenu() ; -----------------------------------------------------------------------------
  Local MPosY = MouseY()
  MPosY = Int((MposY-29)/20)
  Box(MP,26,ML,(20*MS)+1,$888888)
  Box(MP+1,26+(MPosy*20),ML-2,20,$AAAAAA)
  For t = 0 to MS-1
    TextOut(MP+2,29+(t*20),Menu[t])
  Next
EndFunction

Function SelectMenu() ;----------------------------------------------------------------------------
  Local MPosY = MouseY()
  If MM+Int((MPosY-29)/20) = 0
     Selected0()
  ElseIf MM+Int((MPosY-29)/20) = 1
     Selected1()
  ElseIf MM+Int((MPosY-29)/20) = 2
     Selected2()
  ElseIf MM+Int((MPosY-29)/20) = 3
     Selected3()
  ElseIf MM+Int((MPosY-29)/20) = 4
     Selected4()
  ElseIf MM+Int((MPosY-29)/20) = 5
     Selected5()
  ElseIf MM+Int((MPosY-29)/20) = 6
     Selected6()
  ElseIf MM+Int((MPosY-29)/20) = 7
     Selected7()
  ElseIf MM+Int((MPosY-29)/20) = 8
     Selected8()
  EndIf
EndFunction

Function Selected0()
  Box(100,250,150,40,$999999)
  TextOut(100,250,"Selection 0")
EndFunction

Function Selected1()
  Box(100,250,150,40,$999999)
  TextOut(100,250,"Selection 1")
EndFunction

Function Selected2()
  Box(100,250,150,40,$999999)
  TextOut(100,250,"Selection 2")
EndFunction

Function Selected3()
  Box(100,250,150,40,$999999)
  TextOut(100,250,"Selection 3")
EndFunction

Function Selected4()
  Box(100,250,150,40,$999999)
  TextOut(100,250,"Selection 4")
EndFunction


Function Selected5()
  Box(100,250,150,40,$999999)
  TextOut(100,250,"Selection 5")
EndFunction

Function Selected6()
  Box(100,250,150,40,$999999)
  TextOut(100,250,"Selection 6")
EndFunction

Function Selected7()
  Box(100,250,150,40,$999999)
  TextOut(100,250,"Selection 7")
EndFunction

Function Selected8()
  Box(100,250,150,40,$999999)
  TextOut(100,250,"Selection 8")
EndFunction
; Allow quit with ESC at any time! ****************************************************************
EscapeQuit(True)


;
Menus()
;
; Main loop!
;
Repeat
    WaitEvent
Forever                
The code above is what I could remember as I am at work now,but it does the same thing.

Once the menu is drawn it destroys the white box, is there a way to have the menu on its own layer so what is under it does not get destroyed?

Regards
Redlion
----------------------------------------------------------------------------------------
Redlion
Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32
Bugala
Posts: 1180
Joined: Sun Feb 14, 2010 7:11 pm

Re: Need help with Menu

Post by Bugala »

Yeah, there is way. You might have some other way to do this too, that you proapbly are able to make those boxes become layers maybe by using the name tag or something, but this is how i made boxes for a very simple game:

Code: Select all

CreateBrush(1, square.sizex, square.sizey, color)
InsertLayer(1, #BRUSH, 1, x, y)	
SetLayerName(1, "nameofyourlayer")
and then later you can just:

Code: Select all

RemoveLayer("nameofyourlayer")

And although there is proapbly better way to make those lines, but as long as they are straight lines on one of the 90 degree angles, then you can use that CreateBrush to make them in way of:

vertical line:
CreateBrush(number, length, 1, color)

or horizontal line:
CreateBrush(number, 1, length, color)

then you just need to place them accordingly in your code on top of the box you first created.
User avatar
Juan Carlos
Posts: 891
Joined: Mon Sep 06, 2010 1:02 pm

Re: Need help with Menu

Post by Juan Carlos »

We need implement in Hollywood the menus functions as the old menus style in Amiga OS or Windows, because AmiBlitz has this funcions and you can make donw menus.
User avatar
Allanon
Posts: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: Need help with Menu

Post by Allanon »

You could have life easier if you use a separate window (display) with your own menu, set an event when the window became inactive to get rid of the window and you will have the same behaviour almost standard menus. At least I've implemented it in this way on my gui system.
Post Reply