cleaned all trailing white space from source files.
[sdk] / samples / games / cards / ruff / src / bet.ec
1 import "ruff.ec"
2
3 class BetDialog : Window
4 {
5    background = activeBorder;
6    tabCycle = true;
7    hasClose = true;
8    size = Size { 160 }, clientSize.h = 80;
9
10    Button bet
11    {
12       this, isDefault = true, text = "Bet", hotKey = altB;
13       size = Size { 40, 20 };
14       anchor = Anchor { horz = -20, top = 40 };
15
16       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
17       {
18          RuffGame * game = &((Ruff)master).game;
19          Round * round = &game->rounds[game->round];
20
21          int bet = atoi(edit.contents);
22          if(bet >= 40 && bet <= 100 && !(bet%5) && bet >= round->bet.howMuch &&
23             (game->turn == round->shuffle || bet > round->bet.howMuch))
24             Destroy(bet);
25          return true;
26       }
27    };
28
29    Button pass
30    {
31       this, text = "Pass", hotKey = altP;
32       anchor = Anchor { horz = 20, top = 40 };
33       size = Size { 40, 20 };
34       NotifyClicked = ButtonCloseDialog;
35    };
36
37    EditBox edit { this, size = Size { 80, 20 }, anchor = Anchor { top = 10 }; };
38
39    bool OnPostCreate()
40    {
41       edit.Activate();
42       return true;
43    }
44
45    bool OnCreate()
46    {
47       RuffGame * game = &((Ruff)master).game;
48       Round * round = &game->rounds[game->round];
49
50       edit.Clear();
51       pass.disabled = false;
52       if(game->turn == round->shuffle)
53       {
54          if(!round->bet.howMuch)
55          {
56             edit.Printf("%d", 40);
57             pass.disabled = true;
58          }
59          else
60             edit.Printf("%d", round->bet.howMuch);
61       }
62       else
63       {
64          if(round->bet.howMuch)
65          {
66             if(round->bet.howMuch < 100)
67                edit.Printf("%d", round->bet.howMuch + 5);
68          }
69          else
70             edit.Printf("%d", 40);
71       }
72       return true;
73    }
74
75    bool OnKeyDown(Key key, unichar ch)
76    {
77       switch(key)
78       {
79          case escape:
80             if(!pass.disabled)
81             {
82                pass.NotifyClicked(this, pass, 0, 0, key.modifiers);
83                return false;
84             }
85             break;
86       }
87       return true;
88    }
89 }