1 # GADGETS/BUTTON.D - Button Gadget
3 # (c)Copyright 2020-2021, Matthew Dillon, All Rights Reserved.
4 # See the COPYRIGHT file at the base of the Rune distribution.
7 subclass ButtonFrame from Frame {
14 ButtonFrame.createButton(
15 lvalue ButtonFrame @this, Frame @parent,
17 int mount, string_p text
20 w = parent->textWidth(text, Str.strlen(text)) + (2 + 2);
22 h = parent->textHeight() + (2 + 2);
24 this.createFrame("button", parent, w, h, mount);
27 this->refreshVisibleFrame();
32 ButtonFrame.mouseMoved(Event @ev)
34 # The button held state controls the button depress graphic, but if
35 # the mouse moves out of bounds while the button is held we have to
36 # restore or re-depress the graphic.
38 switch(this->holding) {
39 case Event.XK_Pointer_Button1:
40 if (this->mouseOutOfBounds(ev)) {
41 this->holding = -this->holding;
42 this->refreshVisibleFrame();
45 case -Event.XK_Pointer_Button1:
46 if (this->mouseInBounds(ev)) {
47 this->holding = -this->holding;
48 this->refreshVisibleFrame();
57 ButtonFrame.buttonPressed(Event @ev)
60 case Event.XK_Pointer_Button1:
61 if (this->mouseInBounds(ev)) {
62 this->holding = ev->keySym;
63 this->setMouseFocus();
65 this->holding = -ev->keySym;
67 this->refreshVisibleFrame();
69 case -Event.XK_Pointer_Button1:
70 # button release, execute the button function if appropriate
72 int hold = this->holding;
75 this->refreshVisibleFrame();
76 this->clearMouseFocus();
77 if (this->mouseInBounds(ev) && hold == Event.XK_Pointer_Button1) {
78 this->buttonExecute();
89 ButtonFrame.buttonExecute()
96 ButtonFrame.refreshFrame(int x, int y, int w, int h)
102 if (this->checklinked() == FALSE)
104 if (this->holding == Event.XK_Pointer_Button1) {
105 pen1 = this->darkPen;
106 pen2 = this->lightPen;
108 pen1 = this->lightPen;
109 pen2 = this->darkPen;
112 this->drawLine(0, 0, this->bounds.w - 2, 0);
113 this->drawLine(0, 1, this->bounds.w - 3, 1);
114 this->drawLine(0, 0, 0, this->bounds.h - 1);
115 this->drawLine(1, 0, 1, this->bounds.h - 2);
117 this->drawLine(1, this->bounds.h - 1,
118 this->bounds.w - 1, this->bounds.h - 1);
119 this->drawLine(2, this->bounds.h - 2,
120 this->bounds.w - 1, this->bounds.h - 2);
121 this->drawLine(this->bounds.w - 1, 0,
122 this->bounds.w - 1, this->bounds.h - 1);
123 this->drawLine(this->bounds.w - 2, 1,
124 this->bounds.w - 2, this->bounds.h - 1);
125 this->pen = this->textPen;
126 descent = this->textPen->textDescent();
127 this->fillText(2, this->bounds.h - 2 - descent, this->bounds.w - 4,
128 this->text, Str.strlen(this->text));
136 ButtonFrame.setTextFGColor(int r, int g, int b)
138 this->textPen->setFGColor(r, g, b);
143 ButtonFrame.setTextBGColor(int r, int g, int b)
145 this->textPen->setBGColor(r, g, b);