~onli/simdock/master

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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*  
 *   Copyright 2007 Simone Della Longa <simonedll@yahoo.it>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
#include "simImage.h"


simImage::simImage()
{
  img = wxImage();
  status = STATUS_NONE;
  blur = 0;
  pid = PID_NONE;
  lastWindow = 0;
  task = false;
}

simImage::~simImage()
{
	
}


simImage::simImage (wxImage img, const wxString& img_link, const wxString& link, const wxString& name, const wxString& descr, int i)
{
  if (!img.HasAlpha ())
    img.InitAlpha ();

  task = false;
  this->img = img;		//wxImage(path);
  initReflex();
  this->img_link = img_link;
  id = i;
  this->link = link;
  this->name = name;
  this->descr = descr;
  status = STATUS_DECREASING;
  blur = MAX_BLUR;
  pid = PID_NONE;
  lastWindow = 0;
  this->cycleMinimize = true;
  /*
     status = STATUS_NONE;
     blur = 0;
   */
}

void simImage::addWindow(WnckWindow* window)
{
  	array.Add(window);
}

WnckWindow* simImage::getWindow()
{
  	int count = array.GetCount();
  	if (count == 0)
  	return NULL;
  	
  	
  	WnckWindow* value = array[this->lastWindow];
  	this->lastWindow = (lastWindow+1) % count;
  	return value;
}

void simImage::removeWindow(WnckWindow* window)
{
	/*
	int idx = array.Index(window);
	if (idx == wxNOT_FOUND)
	{
		return false;
	}
	*/
	if (lastWindow > 0)
	{
		lastWindow--;
	}

	array.Remove(window);
}

bool simImage::hasWindow(WnckWindow* window)
{
	return array.Index(window) != wxNOT_FOUND;
}

int simImage::windowCount()
{
	return array.GetCount();
}

void simImage::initReflex()
{
	reflex = img.Mirror(false);
}

bool simImage::loadImage(const wxString& path)
{
   if (!img.LoadFile(path))
   	return false;
   
   if (!img.HasAlpha ())
   	img.InitAlpha ();
   	
   initReflex();
   return true;	
}

bool simImage::allNotMinimized() {
    int count = array.GetCount();
    int i = 0;
    while (i < count) {
        bool comp =  wnck_window_is_minimized(array[i]);
        if (comp) {
            return false;
        }
        i++;
    }
    return true;
}

bool simImage::allMinimized() {
    int count = array.GetCount();
    int i = 0;
    while (i < count) {
        bool comp =  wnck_window_is_minimized(array[i]);
        if (!comp) {
            return false;
        }
        i++;
    }
    return true;
}

void
simImage::handleStatus ()
{
    switch (status)
    {
        case STATUS_NONE:
        break;
        case STATUS_DECREASING:
            blur--;
            if (blur == 0)
            {
                status = STATUS_NONE;
            }
        break;
        case STATUS_INCREASING:
            blur++;
            if (blur >= MAX_BLUR)
            {
                status = STATUS_DECREASING;
            }
        break;
    }
}
bool simImage::isIn (int m_x, int m_y)
{
  return m_x > x && m_y > y && m_x < x + w && m_y < y + h;
}
wxPoint simImage::center()
{
	return wxPoint(x+w/2,y+h/2);
}