'Compileroption -s console

#include "sGUI\sGUI.bas"
#include once "sGUI\SimpleGadget.bas"
#include once "sGUI\BMPSimpleGadget.bas"
#include once "sGUI\ToggleGadget.bas"
#include once "sGUI\CheckMarkGadget.bas"
#include once "sGUI\RadioButton.bas"
#include once "sGUI\StringGadget.bas"
#include once "sGUI\TrackBar.bas"
#include once "sGUI\ScrollBar.bas"
#include once "sGUI\Arrows.bas"
#include once "sGUI\ListBox.bas"
#include once "sGUI\MultiLineEditBox.bas"
#include once "sGUI\FileRequester.bas"
#include once "sGUI\Label.bas"
#include once "sGUI\Menu.bas"

screen 19,32,,&H04
InitGFX

bload "BMPs\effekt.bmp",0

dim as EventHandle ptr event
event=CreateEventHandle

'Alles fürs Activation Menü
dim as Gadget ptr acton,actsleep,actoff
acton     =AddRadioButton(event,730,540,1,"On",0)
actsleep  =AddRadioButton(event,730,560,0,"Sleep",acton)
actoff    =AddRadioButton(event,730,580,0,"Off",acton)
GadgetOn(acton,actoff)

'MenüKontrolle
dim as Gadget ptr check
check=AddCheckMarkGadget(event,730,500,1,"Menue")
GadgetOn(check)

'Deklaration der Control-Variablen als Gadget Pointer
dim as Gadget ptr okay,opta,checker,radioa,radiob,radioc
dim as Gadget ptr stringer,track,scroll
dim as Gadget ptr arrowl,arrowr,arrowu,arrowd,sarrowl,sarrowr,sarrowu,sarrowd
dim as Gadget ptr bmpplus,bmpminus,label
dim as Gadget ptr textbox

'Erzeugen der Gadgets und "Anfügen" an den EventHandle zur Überprüfung
okay    =AddSimpleGadget(event,20,30,80,20,"Okay")
opta    =AddToggleGadget(event,20,60,70,20,1,"Option A")
checker =AddCheckMarkGadget(event,20,90,1,"Option")

radioa  =AddRadioButton(event,20,120,1,"Kugel",0)
radiob  =AddRadioButton(event,20,140,0,"Quader",radioa)
radioc  =AddRadioButton(event,20,160,0,"Tetraeder",radioa)

stringer=AddStringGadget(event,20,190,10,"Text")
track   =AddTrackBar(event,20,220,150,-5,2,1,0)
scroll  =AddScrollBar(event,20,250,150,1,100,22,30,0)

arrowl  =AddArrow(event,20,280,0)
arrowr  =AddArrow(event,40,280,1)
arrowu  =AddArrow(event,60,280,2)
arrowd  =AddArrow(event,80,280,3)
sarrowl =AddSmallArrow(event,20,310,0)
sarrowr =AddSmallArrow(event,40,310,1)
sarrowu =AddSmallArrow(event,60,310,2)
sarrowd =AddSmallArrow(event,80,310,3)
bmpplus= AddBMPSimpleGadget(event,30,330,"BMPs\PlusUnSelected.bmp","BMPs\PlusSelected.bmp","BMPs\PlusMask.bmp")
bmpminus= AddBMPSimpleGadget(event,41,330,"BMPs\MinusUnSelected.bmp","BMPs\MinusSelected.bmp","BMPs\MinusMask.bmp")
label=AddLabel(event,10,360,"ein anklickbares Label",&H003FFF)
textbox=AddMultiLineEditBox(event,150,25,40,10,1)

GadgetOn (okay,textbox)

MenuOn(event)
menu (event,1,0,1,"Projekt")
menu (event,1,1,1,"Laden")
menu (event,1,2,0,"Sichern")
menu (event,1,3,4,)
menu (event,1,4,3,"Option")
menu (event,1,5,4,)
menu (event,1,6,1,"Ende")

GadgetSleep (acton,textbox)
MessageBox(200,300,"Activation Demo","Hinweis",MBType_OK)
RestoreActivation (acton,textbox)


'Console öffnen für output
dim as integer ff=freefile
open cons for output as ff

dim as integer menunum,itemnum'Hilfsvariablen um Menünummer und Eintragnummer zu verarbeiten
dim as string openfile
'Beginn EventLoop**************************************************************
do
  event->xSleep(1)

'Auswertung des Menüs (nur teilweise!)
  if event->MENUMESSAGE then
    menunum=event->MENUNUMBER
    itemnum=event->ITEMNUMBER

    if menunum=1 then
      select case itemnum
        case 1
          ' OOOPS!!!! Kleiner Spaß, mir war mal danach alles abzuschalten ;P
          MenuOff(event)
          GadgetOff (acton,textbox)
          openfile=FileRequester(160,80,"Load",curdir,,1)
          RestoreActivation (acton,textbox)'alte ControlActivation wieder herstellen
          MenuOn (event)
        
        case 4
          if GetChecked(event,1,4) then
            Menu (event,1,4,1,"Option")
          else
            Menu (event,1,4,3,"Option")
          end if
        case 6
          GadgetSleep (acton,textbox)
          if MessageBox(200,200,"Programm wirklich beenden?","Frage",MBType_YESNO)=MBButton_YES then
            event->EXITEVENT=1
          else
            RestoreActivation (acton,textbox)
          end if
      end select
    end if
  end if

'einfache Auswertung der Gadgets
  if event->GADGETMESSAGE then
    select case event->GADGETMESSAGE
      case okay
        print #ff,"OK Button, lese jetzt die MultiLineEditBox aus:"
        print #ff,
        print #ff,TO_GetText(textbox)
        print #ff,
      case opta
        if GetSelect(opta) then          '1
          print #ff,"Option A selektiert"
        else                               '0
          print #ff,"Option A nicht selektiert"
        end if
      case checker
        if GetSelect(checker) then          '1
          print #ff,"Option selektiert"
        else                               '0
          print #ff,"Option nicht selektiert"
        end if
      case radioa
        print #ff,"Kugel"
      case radiob
        print #ff,"Quader"
      case radioc
        print #ff,"Tetraeder"
      case stringer
        print #ff,GetString(stringer)
      case track
        print #ff,GetTrackBarVal(track)
      case scroll
        print #ff,GetScrollBarVal(scroll)
      case arrowl,arrowr,arrowu,arrowd,sarrowl,sarrowr,sarrowu,sarrowd
        'es ist nicht notwendig, den Zustand der Maustaste abzufragen
        'hier nur um zu verdeutlichen das beim Halten des ARROWS auch etwas passiert!!
        if event->LMB=HIT then  print #ff,"Arrow wurde angeklickt"
        if event->LMB=HOLD then  print #ff,"Arrow wird gehalten und triggert jetzt"
      case bmpplus,bmpminus
        print #ff,"einer der BMP Button wurde angeklickt"
      case label
        print #ff,"Label wurde angeklickt"

'Activation Kontrolle****************************
      case acton
        GadgetOn (okay,textbox)'<---------------------------!!!!!!!

      case actsleep
        GadgetSleep (okay,textbox)'<---------------------------!!!!!!!

      case actoff
        GadgetOff (okay,textbox)'<---------------------------!!!!!!!

'Menü Kontrolle**********************************
      case check
        if GetSelect(check) then
          MenuOn(event)
        else
          MenuOff(event)
        end if
'************************************************
    end select
  end if
loop until event->EXITEVENT
'Ende EventLoop ***************************************************************

DestroyEventHandle (event)'löscht den EventHandle und alle mit ihm verknüpften Gadgets
end
