How can I assign standart popup menu item to the SimpleThemeButton? Can anybody show me at just one example? I want to redraw original menu with wsh...
function RGB(r, g, b) {
return (0xff000000 | (r << 16) | (g << 8) | (b));
}
ButtonStates = {
normal: 0,
hover: 1,
down: 2,
hide: 3
}
var DT_TOP = 0x00000000;
var DT_CENTER = 0x00000001;
var DT_VCENTER = 0x00000004;
var DT_WORDBREAK = 0x00000010;
var DT_CALCRECT = 0x00000400;
var DT_NOPREFIX = 0x00000800;
var g_theme = window.CreateThemeManager("Button");
var g_font = gdi.Font("Tahoma", 12);
var g_bkclr = RGB(46, 48, 63);
var ww = window.Width;
var wh = window.Height;
var menuman = fb.CreateMainMenuManager();
var menu = window.CreatePopupMenu();
var ret;
function SimpleButton(x, y, w, h, text, fonClick, state) {
this.state = state ? state : ButtonStates.normal;
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.text = text;
this.fonClick = fonClick;
this.containXY = function (x, y) {
return (this.x <= x) && (x <= this.x + this.w) && (this.y <= y) && (y <= this.y + this.h);
}
this.changeState = function (state) {
var old = this.state;
this.state = state;
return old;
}
this.draw = function (gr) {
if (this.state == ButtonStates.hide) return;
switch (this.state)
{
case ButtonStates.normal:
g_theme.SetPartAndStateId(1, 1);
break;
case ButtonStates.hover:
g_theme.SetPartAndStateId(1, 2);
break;
case ButtonStates.down:
g_theme.SetPartAndStateId(1, 3);
break;
case ButtonStates.hide:
return;
}
g_theme.DrawThemeBackground(gr, this.x, this.y, this.w, this.h);
gr.GdiDrawText(this.text, g_font, RGB(0,0,0), this.x, this.y, this.w, this.h, DT_CENTER| DT_VCENTER | DT_CALCRECT | DT_NOPREFIX);
}
this.onClick = function () {
this.fonClick && this.fonClick();
}
}
function drawAllButtons(gr) {
gr.FillSolidRect(0, 0, ww, wh, g_bkclr);
for (var i in $buttons) {
$buttons[i].draw(gr);
}
}
function chooseButton(x, y) {
for (var i in $buttons) {
if ($buttons[i].containXY(x, y) && $buttons[i].state != ButtonStates.hide) return $buttons[i];
}
return null;
}
$buttons = {
Console: new SimpleButton(0, 0, 40, 24, "File", function () {
fb.ShowConsole();
}),
Edit: new SimpleButton(40, 0, 40, 24, "Edit", function () {
window.ShowConfigure();
}),
View: new SimpleButton(80, 0, 40, 24, "View", function () {
// Build a menu based on "View"
menuman.Init("View");
menuman.BuildMenu(menu, 1, 128);
}),
Playback: new SimpleButton(120, 0, 60, 24, "Playback", function () {
//window.ShowConfigure();
}),
Library: new SimpleButton(180, 0, 50, 24, "Library", function () {
//window.ShowConfigure();
}),
Help: new SimpleButton(230, 0, 40, 24, "Help", function () {
//window.ShowConfigure();
})
}
var cur_btn = null;
var g_down = false;
// --- APPLICATION START
function on_paint(gr) {
drawAllButtons(gr);
}
function on_mouse_move(x, y) {
var old = cur_btn;
cur_btn = chooseButton(x, y);
if (old == cur_btn) {
if (g_down) return;
} else if (g_down && cur_btn && cur_btn.state != ButtonStates.down) {
cur_btn.changeState(ButtonStates.down);
window.Repaint();
return;
}
old && old.changeState(ButtonStates.normal);
cur_btn && cur_btn.changeState(ButtonStates.hover);
window.Repaint();
}
function on_mouse_leave() {
g_down = false;
if (cur_btn) {
cur_btn.changeState(ButtonStates.normal);
window.Repaint();
}
}
function on_mouse_lbtn_down(x, y) {
g_down = true;
if (cur_btn) {
cur_btn.changeState(ButtonStates.down);
window.Repaint();
}
}
function on_mouse_lbtn_up(x, y) {
g_down = false;
if (cur_btn) {
cur_btn.onClick();
cur_btn.changeState(ButtonStates.hover);
window.Repaint();
}
}
// --- APPLICATION END