' Copyright (c) 2006 Ian Cowburn ' ' Permission is hereby granted, free of charge, to any person obtaining a copy of ' this software and associated documentation files (the "Software"), to deal in ' the Software without restriction, including without limitation the rights to ' use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies ' of the Software, and to permit persons to whom the Software is furnished to do ' so, subject to the following conditions: ' ' The above copyright notice and this permission notice shall be included in all ' copies or substantial portions of the Software. ' ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ' SOFTWARE. ' ' $Id$ ' Rem bbdoc: noddybox.showlicense EndRem Module noddybox.showlicense ModuleInfo "Framework: License acceptance routines" ModuleInfo "Copyright: Ian Cowburn -- released under the MIT License" ModuleInfo "Author: Ian Cowburn" ModuleInfo "Version: $Revision$" Strict Import brl.max2d Import brl.stream Import brl.basic Import brl.linkedlist Rem bbdoc: Displays a license for the user to accept. returns: True if the license is accepted, false otherwise. about: The license stored in text format at the URL @short_license is displayed with a title of @title. If the URL @full_license is not null then the user is provided with an option to display that too. The width of text in the license files must fit on the screen... EndRem Function ShowLicense:Int(title:String, short_license:String, full_license:String) Local accepted:Int=False Local license:TLicense=New TLicense If full_license license.Init(title,short_license,["ACCEPT","DECLINE","VIEW FULL LICENSE"]) Else license.Init(title,short_license,["ACCEPT","DECLINE"]) EndIf Select license.Show() Case 0 accepted=True Case 1 Case 2 license=New TLicense license.Init(title,full_license,["ACCEPT","DECLINE"]) If (license.Show()=0) accepted=True End If End Select Return accepted End Function Private Type TLicense Field top:Int Field bottom:Int Field list:TList Field item:TLink Field title:String Field opts:String[] Field sel:Int Field col:Int Field coli:Int Method New() End Method Method Centre(s:String, y:Int) DrawText(s,(GraphicsWidth()-TextWidth(s))/2,y) End Method Method MaxHeight:Int() Return TextHeight("X") End Method Method Init(t:String, u:String, o:String[]) Local str:TStream=ReadStream(u) Assert str,"Unable to open help file" list=CreateList() While Not str.Eof() list.AddLast(str.ReadLine()) Wend str.Close() title=t item=list.FirstLink() top=MaxHeight()*2 bottom=GraphicsHeight()-MaxHeight()*3 opts=o sel=0 col=255 coli=-5 End Method Method Draw() Local y:Int=top+1 Local i:TLink=item While y255 coli=-coli col:+coli EndIf End Method Method Current:String() Return String(item.Value()) End Method Method Show:Int() Local done:Int=False FlushKeys() While Not done Cls Draw() If KeyDown(KEY_DOWN) If item.NextLink() item=item.NextLink() EndIf ElseIf KeyDown(KEY_UP) If item.PrevLink() item=item.PrevLink() EndIf ElseIf KeyHit(KEY_LEFT) sel=Max(0,sel-1) ElseIf KeyHit(KEY_RIGHT) sel=Min(opts.length-1,sel+1) ElseIf KeyHit(KEY_RETURN) done=True EndIf Flip Wend FlushKeys() Return sel End Method End Type