A simple script for a tutorial

The place for any Hollywood tutorials

A simple script for a tutorial

Postby emeck » Sat Apr 02, 2016 10:28 pm

Hello,

after learning to use Designer, which allows you to see results almost as soon as you start working with it, I decided to try to learn Hollywood itself.

I've written this script as a GUI to use icon2PNG (console program for MorphOS). It is pretty simple right now but does the work: lets you select an icon, select an output name and path, and convert it to PNG format, in dual mode.

I post it here because I want to ask about improvements and maybe other's suggestions can help to go from this simple stage to a more feature complete and complex script and the thread can end beeing like some sort of tutorial itself that can help other newbies like myself.

So for a start, what do you think about it? Is it too long for what it does? Messy? And the first problem I need to solve: how to clear the path printed with DisplayTextObject when selecting another input or output.

Here is the script:

Code: Select all
@APPTITLE "Icon2PNG GUI"
@APPDESCRIPTION "A simple GUI for icon2png."
@DISPLAY {Title="Icon2PNG GUI", Width=450, Height=300, Color=$959595, Mode="Windowed", NoModeSwitch=TRUE}
@BRUSH 1, "drawerpic.png", {LoadAlpha=TRUE, ScaleWidth="50%", ScaleHeight="50%"} ;loads the drawer picture

/* Global part */
EnableLayers()
SetFontColor(#BLACK)

GLOBAL icon_input$         ;stores path of icon to convert
GLOBAL png_output$         ;stores path of converted icon
GLOBAL icon_mode$="DUAL"   ;stores dual or simple mode option
GLOBAL commandline$      ;command and parameters to run icon2png

CreateTextObject(1, "Select input")
CreateTextObject(2, "Select output")
CreateTextObject(3, "Mode: dual")
CreateTextObject(4, "Convert")
CreateTextObject(5, "Quit")


/* Functions */
Function p_Input()
   SetFontColor(#WHITE)
   icon_input$=FileRequest("Select input", "*.info", #REQ_NORMAL, "RAM:", "")
   CreateTextObject(6, icon_input$)
   DisplayTextObject(6, 90, 98)
EndFunction

Function p_Output()
   SetFontColor(#WHITE)
   png_output$=FileRequest("Select output", "*.info", #REQ_NORMAL, "RAM:", "output.info")
   CreateTextObject(7, png_output$)
   DisplayTextObject(7, 90, 158)
EndFunction

Function p_Convert()
   commandline$="icon2png".." MODE="..icon_mode$.." FROM=\""..icon_input$.."\"".." TO=\""..png_output$.."\""
   Execute(commandline$)
EndFunction

Function p_End()
   End()
EndFunction


/* Interface and events */
;displays text and button for input
DisplayTextObject(1, 50, 70)
DisplayBrush(1, 50, 85)
MakeButton(1, #SIMPLEBUTTON, 50, 85, 50, 50, {OnMouseUp=p_Input})

;displays text and button for output
DisplayTextObject(2, 50, 130)
DisplayBrush(1, 50, 145)
MakeButton(2, #SIMPLEBUTTON, 50, 145, 50, 50, {OnMouseUp=p_Output})

;displays selected Mode option
DisplayTextObject(3, 50, 200)

;displays Convert button
SetFillStyle(#FILLCOLOR)
Box(347, 197, 61, 13, #YELLOW, {RoundLevel=25})
DisplayTextObject(4, 350, 200)
MakeButton(3, #SIMPLEBUTTON, 347, 197, 61, 13, {OnMouseUp=p_Convert})

;displays Quit button
SetFillStyle(#FILLCOLOR)
Box(347, 247, 38, 13, #RED, {RoundLevel=25})
DisplayTextObject(5, 350, 250)
MakeButton(4, #SIMPLEBUTTON, 347, 247, 38, 13, {OnMouseUp=p_End})


EscapeQuit(TRUE)

Repeat
   WaitEvent
Forever
emeck
 
Posts: 40
Joined: Fri Apr 03, 2015 3:17 pm

Re: A simple script for a tutorial

Postby airsoftsoftwair » Sun Apr 03, 2016 9:20 pm

Thanks, but if you use the [code] ... [/code] format tag your code will look much better. I'll edit your post and change this for the time being.
User avatar
airsoftsoftwair
 
Posts: 2105
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: A simple script for a tutorial

Postby emeck » Sun Apr 03, 2016 11:33 pm

airsoftsoftwair wrote:Thanks, but if you use the code ... /code format tag your code will look much better. I'll edit your post and change this for the time being.

Sorry, forgot about that. Thanks for the correction.

Regards
emeck
 
Posts: 40
Joined: Fri Apr 03, 2015 3:17 pm

Re: A simple script for a tutorial

Postby emeck » Sat Apr 23, 2016 11:39 pm

Ok, I've make some progress with my simple script and have been using it for a couple of weeks and seems to work as expected.

So here is version 0.2 if anyone is interested. Doing it has helped me a lot to start learning Hollywood! I'll add latter some explanations of what I did. Comments, suggestions and corrections are welcome.

Code: Select all
@APPTITLE "icon2png GUI"
@APPAUTHOR "Enrique Mecklenburg Serkovic"
@APPVERSION "$VER: icon2png GUI 0.2 (16-April-2016)"
@APPDESCRIPTION "A simple GUI for icon2png."
@DISPLAY 1, {Title="icon2png GUI", Width=450, Height=300, Color=$959595, Mode="Windowed", NoModeSwitch=TRUE}

;loads the drawer picture and makes it available for linking
@BRUSH 1, "drawerpic.png", {LoadAlpha=TRUE, ScaleWidth="50%", ScaleHeight="50%"}

/* Global part */
SetWBIcon("icon2png GUI.info")
EnableLayers()

SetFont(#SERIF, 18, {#FONTENGINE_INBUILT})
SetFontStyle(#ANTIALIAS)
SetFontColor(#BLACK)

GLOBAL icon_input$         ;stores the path of icon to convert
GLOBAL png_output$         ;stores path of converted icon
GLOBAL mode$ = "DUAL"      ;stores dual or simple mode option
GLOBAL commandline$      ;command and parameters to run icon2png


/* Functions */
Function p_Input()
   RemoveLayer(13)
   SetFontColor(#WHITE)
   icon_input$ = FileRequest("Select input", "*.info", #REQ_NORMAL, "RAM:", "")
   CreateTextObject(1, icon_input$)
   InsertLayer(13, #TEXTOBJECT, 1, 90, 93)
EndFunction

Function p_Output()
   RemoveLayer(14)
   SetFontColor(#WHITE)
   png_output$ = FileRequest("Select output", "*.info", #REQ_NORMAL, "RAM:", "output.info")
   CreateTextObject(1, png_output$)
   InsertLayer(14, #TEXTOBJECT, 1, 90, 153)
EndFunction

Function p_Mode(a)
   Switch a
   Case 3:
      If (mode$ <> "DUAL")
         mode$ = "DUAL"
         HideLayer(7)
         MoveLayer(7, #USELAYERPOSITION, #USELAYERPOSITION, 51, 195)
         ShowLayer(7)
      Endif
   Case 4:
      If (mode$ <> "STANDARD")
         mode$ = "STANDARD"
         HideLayer(7)
         MoveLayer(7, #USELAYERPOSITION, #USELAYERPOSITION, 51, 211)
         ShowLayer(7)
      Endif
   Case 5:
      If (mode$ <> "SINGLE2")
         mode$ = "SINGLE2"
         HideLayer(7)
         MoveLayer(7, #USELAYERPOSITION, #USELAYERPOSITION, 51, 227)
         ShowLayer(7)
      Endif
   EndSwitch      
EndFunction

Function p_Convert()
   commandline$ = "icon2png" .. " MODE=" .. mode$ .. " FROM=\"" .. icon_input$ .. "\"" .. " TO=\"" .. png_output$ .. "\""
   Execute(commandline$)
EndFunction

Function p_ShowInfo()
   CreateDisplay(2, {X=#CENTER, Y=300, Title="About", Width=400, Height=180, Color=#WHITE, NoModeSwitch=TRUE, NoHide=TRUE, NoClose=TRUE})
   OpenDisplay(2)
   ActivateDisplay(2)
   SetFillStyle(#FILLCOLOR)
   SetFormStyle(#NORMAL)
   Box(70, 60, 260, 1, #GRAY)
   SetFontColor(#BLACK)
   TextOut(#CENTER, 5, "[b]icon2png GUI v0.2   16/4/2016[/b]")
   TextOut(#CENTER, 25, "Written by Enrique Mecklenburg Serkovic")
   TextOut(#CENTER, 75, "Special thanks to:",{Color=#RED})
   TextOut(50, 100, "Andreas Falkenhahn, for [i]Hollywood MAL[/i].")
   TextOut(50, 120, "Ilkka Lehtoranta, for [i]icon2png[/i].")
   TextOut(50, 140, "Drawer and app icons by Martin \"Mason\" Merz.")
   WaitLeftMouse()
   CloseDisplay(2)
   SelectDisplay(1)
   FreeDisplay(2)
EndFunction

Function p_DrawButtons()
   ;displays text and button for input
   DisplayTextObject(1, 50, 65)            ;layer 1
   DisplayBrush(1, 50, 85)               ;layer 2

   ;displays text and button for output
   DisplayTextObject(2, 50, 125)            ;layer 3
   DisplayBrush(1, 50, 145)               ;layer 4

   ;displays dual mode option (selected by default)
   DisplayTextObject(3, 70, 195)            ;layer 5
   Box(50, 198, 12, 12, #BLACK)            ;layer 6
   DisplayTextObject(6, 51, 195)            ;layer 7
   
   ;displays standard mode option
   DisplayTextObject(4, 70, 211)            ;layer 8
   Box(50, 214, 12, 12, #BLACK)            ;layer 9
   
   ;displays single2 mode option
   DisplayTextObject(5, 70, 227)            ;layer 10
   Box(50, 230, 12, 12, #BLACK)            ;layer 11

   ;sets style for the forms bellow
   SetFormStyle(#ANTIALIAS)
   SetFormStyle(#SHADOW, $606060)
   SetFormStyle(#EDGE, 1)

   ;displays Convert button
   SetFillStyle(#FILLCOLOR)
   Box(347, 195, 64, 17, #YELLOW, {RoundLevel=25})   ;layer 12
   DisplayTextObject(7, 350, 195)               ;layer 13

   ;displays Quit button
   SetFillStyle(#FILLCOLOR)
   Box(347, 245, 40, 17, #RED, {RoundLevel=25})      ;layer 14
   DisplayTextObject(8, 350, 245)               ;layer 15

   ;displays About button
   SetFillStyle(#FILLCOLOR)
   Circle(420, 10, 10, #WHITE)               ;layer 16

   ;create hidden layers for displaying input and output paths
   InsertLayer(13, #TEXTOBJECT, 7, 90, 93, TRUE)      ;layer 17
   InsertLayer(14, #TEXTOBJECT, 8, 90, 153, TRUE)   ;layer 18
EndFunction

Function p_EventFunc(msg) ;function called using the evttable
        Switch msg.action
        Case "OnMouseUp":
            If msg.id = 1
                  p_Input()
            ElseIf msg.id = 2
                  p_Output()
            ElseIf (msg.id = 3) Or (msg.id = 4) Or (msg.id = 5)
                  p_mode(msg.id)
            ElseIf msg.id = 6
                  p_Convert()
            ElseIf msg.id = 7
                  p_ShowInfo()
            ElseIf msg.id = 8
                  End()
            EndIf
        EndSwitch
EndFunction


/* Table of events */
evttable = {OnMouseUp = p_EventFunc}

/* Create buttons for mouse events */
MakeButton(1, #SIMPLEBUTTON, 54, 90, 25, 25, evttable)         ;input button
MakeButton(2, #SIMPLEBUTTON, 54, 150, 25, 25, evttable)      ;output button
MakeButton(3, #SIMPLEBUTTON, 50, 198, 12, 12, evttable)      ;dual mode button
MakeButton(4, #SIMPLEBUTTON, 50, 214, 12, 12, evttable)      ;standard mode button
MakeButton(5, #SIMPLEBUTTON, 50, 230, 12, 12, evttable)      ;single2 mode button
MakeButton(6, #SIMPLEBUTTON, 347, 195, 64, 17, evttable)      ;convert button
MakeButton(7, #SIMPLEBUTTON, 420, 10, 20, 20, evttable)      ;about button
MakeButton(8, #SIMPLEBUTTON, 347, 245, 38, 17, evttable)      ;quit button


CreateTextObject(1, "Select input")
CreateTextObject(2, "Select output")
CreateTextObject(3, "Dual mode")
CreateTextObject(4, "Standard mode")
CreateTextObject(5, "Single2 mode")
CreateTextObject(6, "X")
CreateTextObject(7, "Convert")
CreateTextObject(8, "Quit")
CreateTextObject(9, "")         ;this is a temporary text to be replaced with the input path
CreateTextObject(10, "")         ;this is a temporary text to be replaced with the output path

p_DrawButtons()

EscapeQuit(TRUE)

Repeat
   WaitEvent
Forever
emeck
 
Posts: 40
Joined: Fri Apr 03, 2015 3:17 pm


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron