File: applet.cpp

package info (click to toggle)
literki 0.0.0+20100113.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 (143 lines) | stat: -rw-r--r-- 3,111 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <iostream>
#include "applet.h"
#include "logger.h"

using namespace std;

Applet::Applet(AppletWindowParams p):
	win(p.width_portrait, p.height_portrait, p.disp),
	params(p),
	rot(PORTRAIT),
	vibrator(NULL){
    LOG(INFO) << "Creating applet window";
    win.Create();
    if (!win.SetFont(params.font_path))
	LOG(FATAL) << "Cannot load font: " << params.font_path;
    else 
	LOG(INFO) << "Loaded font: " << params.font_path;
    win.SetFontSize(params.font_size);
}
int Applet::GetCurrentWidth(){
    switch (rot){
	case LANDSCAPE: return params.width_landscape;
	case PORTRAIT:  return params.width_portrait;
	default:	LOG(FATAL) << "Unknown orientation";
    }
}
int Applet::GetCurrentHeight(){
    switch (rot){
	case LANDSCAPE: return params.height_landscape;
	case PORTRAIT:  return params.height_portrait;
	default:	LOG(FATAL) << "Unknown orientation";
    }
}

void Applet::SetPosition(Position p){
    pos = p;
    int posy_hidden = params.disp.Height(),
	posy_south  = params.disp.Height() - GetCurrentHeight(),
	posy_north  = 0,
	posx_center = (params.disp.Width() - GetCurrentWidth())/2,
	posx_west   = 0,
	posx_east   = params.disp.Width() - GetCurrentWidth();

    int posx, posy;

    switch (pos) {
	case NORTH: posx = posx_center;
		    posy = posy_north;
		    break;	
	case SOUTH: posx = posx_center;
		    posy = posy_south;
		    break;
	case NORTH_WEST:
		    posx = posx_west;
		    posy = posy_north;
		    break;
	case NORTH_EAST:
		    posx = posx_east;
		    posy = posy_north;
		    break;
	case SOUTH_WEST:
		    posx = posx_west;
		    posy = posy_south;
		    break;
	case SOUTH_EAST:
		    posx = posx_east;
		    posy = posy_south;
		    break;

	default:    LOG(FATAL) << "Unknown position "<<pos;
    }
    if (hidden)
	posy = posy_hidden;
    win.Move(posx, posy, GetCurrentWidth(), GetCurrentHeight());

}
void Applet::Show(){
    hidden = false;
    SetPosition(pos);
    OnShow();
 /*   switch (pos) {
	case NORTH: win.Move(win.PosX(), 0);
		    break;	
	case SOUTH: win.Move(win.PosX(), win.GetDisplay().Height() - win.Height()-1);
		    break;
	default:    LOG(FATAL) << "Unknown position";
    }
    hidden = false;*/
}

void Applet::Hide(){
    win.Move(win.PosX(), win.GetDisplay().Height());
    hidden = true;
    OnHide();
}
void Applet::Refresh(){
    LOG(INFO) << "Applet refresh";
    win.Refresh();
}


void Applet::SetBackground(XColor col){
    win.SetBackground(col);
}
void Applet::SetForeground(XColor col){
    win.SetForeground(col);
}
 

void Applet::SetTransparent(bool trans){
    win.SetTransparent(trans);
}

void Applet::ToggleTransparent(){
    win.SetTransparent(!win.IsTransparent());
}

bool Applet::IsTransparent(){
    return win.IsTransparent();
}

void Applet::WindowRotate(Rotation r){
    rot = r;
    SetPosition(pos);
    OnRotate(r);
}

bool Applet::Hidden(){
    return hidden;
}

bool Applet::IsWindowOwner(Window xwin){
    return xwin == win.GetInputWindow() || xwin == win.GetWindow();
}

void Applet::SetVibrator(Vibrator* vib){
    vibrator = vib;
}

void Applet::Vibrate(){
    if (vibrator)
	vibrator->Vibrate();
}