Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Gtk;
- namespace My
- {
- public class Window : Gtk.Window
- {
- public uint delay{get;set;}
- public Gdk.RGBA background_color{
- set{
- override_background_color(StateFlags.NORMAL,value);
- }
- }
- public Window(WindowType wtype = WindowType.TOPLEVEL){
- GLib.Object(type: wtype);
- Timeout.add(100,()=>{
- int x; int y;
- Gdk.Display.get_default().get_device_manager().get_client_pointer().get_position(null,out x, out y);
- x_pointer = x;
- y_pointer = y;
- return true;
- });
- }
- public int y_pointer{get;private set;}
- public int x_pointer{get;private set;}
- }
- public class FadeWindow : My.Window
- {
- double fade = 1;
- public signal bool fade_completed();
- public FadeWindow(Gtk.WindowType window_type = Gtk.WindowType.TOPLEVEL){
- base(window_type);
- fade_range = 0.1;
- delay = 10;
- }
- public double fade_range{get;set;}
- public void fade_out(){
- Timeout.add(delay,()=>{
- (this as Widget).set_opacity(fade);
- fade -= fade_range;
- if(fade < 0){fade_completed();return false;}
- return true;
- });
- }
- public void fade_in(){
- Timeout.add(delay,()=>{
- (this as Widget).set_opacity(fade);
- fade += fade_range;
- if(fade > 1){fade_completed();return false;}
- return true;
- });
- }
- }
- public enum WindowPosition{Left,Top,Right,Bottom}
- public class SlideWindow : My.Window
- {
- double fade = 0;
- double fade_range = 0.04;
- public SlideWindow(My.WindowPosition window_position = My.WindowPosition.Left, int size = 50){
- base(WindowType.POPUP);
- move_range = 2;
- delay = 10;
- position = window_position;
- width = size;
- switch(position){
- case My.WindowPosition.Top:
- move(0,-width);
- set_size_request(Gdk.Screen.width(),width);
- break;
- case My.WindowPosition.Right:
- move(Gdk.Screen.width()+width,0);
- set_size_request(width,Gdk.Screen.height());
- break;
- case My.WindowPosition.Bottom:
- move(0,Gdk.Screen.height()+width);
- set_size_request(Gdk.Screen.width(),width);
- break;
- default:
- move(-width,0);
- set_size_request(width,Gdk.Screen.height());
- break;
- }
- Timeout.add(100,()=>{
- int w = get_allocated_width();
- int h = get_allocated_height();
- switch(position){
- case My.WindowPosition.Top:
- if(y_pointer<2)move_in();
- else if(y_pointer>width)move_out();
- break;
- case My.WindowPosition.Right:
- if(x_pointer>Gdk.Screen.width()-2)move_in();
- else if(x_pointer<Gdk.Screen.width()-width)move_out();
- break;
- case My.WindowPosition.Bottom:
- if(y_pointer>Gdk.Screen.height()-2)move_in();
- else if(y_pointer<Gdk.Screen.height()-width)move_out();
- break;
- case My.WindowPosition.Left:
- if(x_pointer<2)
- move_in();
- else if(x_pointer>width)move_out();
- break;
- }
- return true;
- });
- }
- public signal bool move_completed();
- public signal void move_init();
- public My.WindowPosition position{get;set;}
- public int move_range{get;set;}
- public int width{get;set;}
- public bool move_in(){
- move_init();
- int x; int y;
- get_position(out x, out y);
- int w = get_allocated_width();
- int h = get_allocated_height();
- Timeout.add(delay,()=>{
- switch(position){
- case My.WindowPosition.Top:
- if(y == 0){move_completed();return false;}
- y += move_range;
- move(x,y);
- (this as Widget).set_opacity((y+width)/((double)width));
- break;
- case My.WindowPosition.Right:
- if(x <= Gdk.Screen.width()-w){move_completed();return false;}
- x -= move_range;
- move(x,y);
- (this as Widget).set_opacity((Gdk.Screen.width()-x)/((double)width));
- break;
- case My.WindowPosition.Bottom:
- if(y <= Gdk.Screen.height()-h){move_completed();return false;}
- y -= move_range;
- move(x,y);
- (this as Widget).set_opacity((Gdk.Screen.height()-y)/((double)width));
- break;
- case My.WindowPosition.Left:
- if(x == 0){move_completed();return false;}
- x += move_range;
- move(x,y);
- (this as Widget).set_opacity((width+x)/((double)width));
- break;
- }
- return true;
- });
- return true;
- }
- public bool move_out(){
- move_init();
- int x; int y;
- get_position(out x, out y);
- int w = get_allocated_width();
- int h = get_allocated_height();
- Timeout.add(delay,()=>{
- switch(position){
- case My.WindowPosition.Top:
- if(y <= -h){move_completed();return false;}
- y -= move_range;
- move(x,y);
- (this as Widget).set_opacity((width+y)/((double)width));
- break;
- case My.WindowPosition.Right:
- if(x > Gdk.Screen.width()){move_completed();return false;}
- x += move_range;
- move(x,y);
- (this as Widget).set_opacity((Gdk.Screen.width()-x)/((double)width));
- break;
- case My.WindowPosition.Bottom:
- if(y > Gdk.Screen.height()){move_completed();return false;}
- y += move_range;
- move(x,y);
- (this as Widget).set_opacity((Gdk.Screen.height()-y)/((double)width));
- break;
- case My.WindowPosition.Left:
- if(x <= -w){return false;}
- x -= move_range;
- move(x,y);
- (this as Widget).set_opacity((width+x)/((double)width));
- break;
- }
- return true;
- });
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement