Студопедия

Главная страница Случайная страница

Разделы сайта

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






Basics - No HTML Required




You've already seen how to create GUI interfaces using HTML. In cases where graphics and animation need to be mixed with GUIs, or in situations where you prefer not to use the HTML/Javascript interface, it can be useful to build GUI interfaces from scratch using native graphic elements. The following example demonstrates some basic techniques for creating interactive GUIs using RFO Basic commands:

! This example will allow the user to input 4 pieces of data. Set those! variables initially to null: text$ = " " bigtext$ = " " number = 0listselection$ = " "! Open the graphics screen: gr.open 255, 255, 255, 255gr.color 255, 0, 0, 0, 0gr.orientation 1! Draw a text label on screen and a text area where the entered text will! be displayed. Underline the text area. This text area will accept! simple text (entered via an " input" function): gr.text.draw t1, 10, 50, " Text: " gr.text.draw f1, 100, 50, " " gr.line l1, 100, 52, 300, 52! Draw another label, text area and underline. This will accept! long text (entered via a " text.input" function): gr.text.draw t2, 10, 100, " Big Text: " gr.text.draw f2, 100, 100, " " gr.line l2, 100, 102, 300, 102! Another label, area, and underline. This accepts numbers (entered via! an " input" function, with the input variable type set to a number,! instead of a string): gr.text.draw t3, 10, 150, " Number: " gr.text.draw f3, 100, 150, " " gr.line l3, 100, 152, 300, 152! Another label, area, and underline. This accepts data selected by the! user from a selection list (entered via a " select" function): gr.text.draw t4, 10, 200, " List Select: " gr.text.draw f4, 100, 200, " " gr.line l4, 100, 202, 300, 202! Add a red " Submit" link which the user will click after all data has! been entered: gr.color 255, 255, 0, 0, 0gr.text.draw b1, 100, 270, " SUBMIT" gr.color 255, 0, 0, 0, 0! Show the screen: gr.render! Start an endless loop that accepts user input: getText:! Wait for the user to touch the screen. Assign the touched! coordinate to the variables " x" and " y": do gr.touch touched, x, y until touched! Hide the graphics screen momentarily (to show input dialogs): gr.front 0! Respond appropriately, according the position at which the screen! was touched: if y < 75! " Text" field touched. Run the " input" function and update the! text field with the user entered results: input " Text: ", text$, text$ gr.modify f1, " text", text$ elseif y < 125! " Big Text" field touched. Run the " text.input" function and! update the text field with the user entered results: text.input bigtext$, bigtext$ gr.modify f2, " text", bigtext$ elseif y < 175! " Number" field touched. Run the " input" function and update the! text field with the user entered results (formatted as needed): input " Number: ", number, number gr.modify f3, " text", replace$(str$(number), ".0", " ") elseif y < 225! " List Select" field touched. Run the " selected" function and! update the text field with the user selected results: array.delete list$[] array.load list$[], " Red", " Green", " Blue" select selecteditem, list$[], " Favorite Color: " listselection$ = list$[selecteditem] gr.modify f4, " text", listselection$ elseif y > 250 & y < 300! " Submit" link touched. In your program, this is where you will! procees the data submitted by the user. In this example, the! entered data is simply printed on the screen: gr.front 0 print " Submitted: \n\n"; text$, bigtext$, number, listselection$ pause 2000 endif! Show the graphics screen update to display the entered data: gr.front 1 gr.render! Continue to accept input until the user submits data or exits: goto getText! If the user exits the program with the back button, exit gracefully: onError: cls end

Here's the whole program without comments:

text$ = " " bigtext$ = " " number = 0listselection$ = " " gr.open 255, 255, 255, 255gr.color 255, 0, 0, 0, 0gr.orientation 1 gr.text.draw t1, 10, 50, " Text: " gr.text.draw f1, 100, 50, " " gr.line l1, 100, 52, 300, 52 gr.text.draw t2, 10, 100, " Big Text: " gr.text.draw f2, 100, 100, " " gr.line l2, 100, 102, 300, 102 gr.text.draw t3, 10, 150, " Number: " gr.text.draw f3, 100, 150, " " gr.line l3, 100, 152, 300, 152 gr.text.draw t4, 10, 200, " List Select: " gr.text.draw f4, 100, 200, " " gr.line l4, 100, 202, 300, 202 gr.color 255, 255, 0, 0, 0gr.text.draw b1, 100, 270, " SUBMIT" gr.color 255, 0, 0, 0, 0 gr.render getText: do gr.touch touched, x, y until touched gr.front 0 if y < 75 input " Text: ", text$, text$ gr.modify f1, " text", text$ elseif y < 125 text.input bigtext$, bigtext$ gr.modify f2, " text", bigtext$ elseif y < 175 input " Number: ", number, number gr.modify f3, " text", replace$(str$(number), ".0", " ") elseif y < 225 array.delete list$[] array.load list$[], " Red", " Green", " Blue" select selecteditem, list$[], " Favorite Color: " listselection$ = list$[selecteditem] gr.modify f4, " text", listselection$ elseif y > 250 & y < 300 gr.front 0 print " Submitted: \n\n"; text$, bigtext$, number, listselection$ pause 2000 endif gr.front 1 gr.rendergoto getTextonError: cls end

Данная страница нарушает авторские права?





© 2023 :: MyLektsii.ru :: Мои Лекции
Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав.
Копирование текстов разрешено только с указанием индексируемой ссылки на источник.