diff options
author | Ian C <ianc@noddybox.co.uk> | 2006-06-03 23:53:18 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2006-06-03 23:53:18 +0000 |
commit | 7f63cfa0d7da1b9d98e21dd08d4981975b31a7ac (patch) | |
tree | a444f983ea1d41bfc8e39681d7a2b6765609873e /showlicense.mod | |
parent | c8f2209abdb7a0e5948ec06ff31e01022fd2143e (diff) |
Added module to view licenses
Diffstat (limited to 'showlicense.mod')
-rw-r--r-- | showlicense.mod/.cvsignore | 4 | ||||
-rw-r--r-- | showlicense.mod/showlicense.bmx | 200 |
2 files changed, 204 insertions, 0 deletions
diff --git a/showlicense.mod/.cvsignore b/showlicense.mod/.cvsignore new file mode 100644 index 0000000..a37585c --- /dev/null +++ b/showlicense.mod/.cvsignore @@ -0,0 +1,4 @@ +doc +.bmx +*.a +*.i diff --git a/showlicense.mod/showlicense.bmx b/showlicense.mod/showlicense.bmx new file mode 100644 index 0000000..09ea7c3 --- /dev/null +++ b/showlicense.mod/showlicense.bmx @@ -0,0 +1,200 @@ +' 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 y<bottom And i + Local s:String=String(i.Value()) + DrawText(s,0,y) + y:+TextHeight(s) + i=i.NextLink() + Wend + + SetColor(0,0,0) + DrawRect(0,0,GraphicsWidth(),top) + DrawRect(0,bottom,GraphicsWidth(),GraphicsHeight()-bottom) + + SetColor(255,255,255) + DrawLine(0,TOP,GraphicsWidth(),TOP) + DrawLine(0,BOTTOM,GraphicsWidth(),BOTTOM) + + Centre(title,MaxHeight()/2) + Centre("CURSORS VIEW AND CHOOSE. RETURN SELECTS.",bottom+MaxHeight()/2) + + Local x:Int=0 + y=GraphicsHeight()-MaxHeight() + + For Local f:Int=0 Until opts.length + If f=sel + SetColor(col/2,col/2,128+col) + DrawRect(x,y,TextWidth(opts[f]),MaxHeight()) + SetColor(255,255,255) + EndIf + DrawText(opts[f],x,y) + x:+TextWidth(opts[f])+20 + Next + + col:+coli + + If col<128 Or col>255 + 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 + |