File: slider.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 (48 lines) | stat: -rw-r--r-- 1,024 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
#include "slider.h"

#include <string>

using namespace std;

Slider::Slider(AppletWindowParams params, int dist):Applet(params), slide_dist(dist){
    for (int i=0; i<4; ++i)
	actions[i] = "";
}

void Slider::AddAction(SlideDir dir, AppAction action){
    actions[dir] = action;
}

string Slider::OnMousePress(int x, int y){
    pressx = x;
    pressy = y;
    return "";
}

Slider::SlideDir Slider::slide_dir(int px, int py, int kx, int ky){
    const int dist = slide_dist;
    int w = kx-px;
    int h = ky-py;
    if (w*w + h*h < dist*dist)
	return Slider::NO_SLIDE;
    if (w>0 && w>abs(h))
	return Slider::SLIDE_E;
    if (h>0 && h>abs(w))
	return Slider::SLIDE_S;
    if (abs(w) > abs(h))
	return Slider::SLIDE_W;
    return Slider::SLIDE_N;
}


AppAction Slider::OnMouseRelease(int x, int y){
    SlideDir dir = slide_dir(pressx, pressy, x, y);
    if (dir == NO_SLIDE){
	win.UnmapInput();
	win.GetDisplay().GenMouseClickEvent(win.PosX() + x, win.PosY() + y, 1);
	win.MapInput();
    }
    return actions[dir];
}