File: switcher.cpp

package info (click to toggle)
literki 0.0.0%2B20100113.git1da40724-1.2
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 3,444 kB
  • ctags: 1,153
  • sloc: cpp: 5,263; makefile: 72
file content (60 lines) | stat: -rw-r--r-- 1,734 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <cmath>
#include "switcher.h"
#include "logger.h"

using namespace std;

Switcher::Switcher(AppletWindowParams params,
	const std::string& apps,
	const std::string& phone,
	const std::string& launch)
		:Applet(params), apps_icon(apps), phone_icon(phone), launch_icon(launch){
}
AppAction Switcher::OnMousePress(int x, int y){
    lastx = x;
    lasty = y;
    for (int i=0; i<buttons.size(); ++i)
	if (x>=buttons[i].px && y>=buttons[i].py && x<buttons[i].px + buttons[i].w && y<buttons[i].py + buttons[i].h){
	    pressed_button = i;
	    return "";
	}
    return "";
}


AppAction Switcher::OnMouseRelease(int x, int y){
    if (pressed_button > -1){
	int but = pressed_button;
	pressed_button = -1;
	if (y < lasty - 50){
	    Hide();
	    return "top_slider_show";
	} else {
	    win.GetDisplay().GenKeyEvent(buttons[but].action);
	    LOG(INFO) << "Gen action " << buttons[but].action;
	    Hide();
	    return "top_slider_show";
	    return "";
	}
    }
    return "";
}
void Switcher::OnRotate(Rotation r){
    win.Clear();
    DrawButtons();
    win.Refresh();
    SetTransparent(IsTransparent());
}

void Switcher::DrawButtons(){
    buttons.clear();
    buttons.push_back(Button(0, 0, GetCurrentWidth()/3, GetCurrentHeight(), "$desktop_switch2", phone_icon));
    buttons.push_back(Button(GetCurrentWidth()/3, 0, GetCurrentWidth()/3, GetCurrentHeight(), "$desktop_switch1", launch_icon));
    buttons.push_back(Button(GetCurrentWidth()/3*2, 0, GetCurrentWidth()/3, GetCurrentHeight(), "$desktop_switch0", apps_icon));

    for (int i=0; i<buttons.size(); ++i){
	string look = buttons[i].look;
	win.AddImage(buttons[i].px + buttons[i].w/2, buttons[i].py + buttons[i].h/2, look, NULL, NULL, MyWindow::CENTER);
    }
}