File: selcolor.cpp

package info (click to toggle)
kicad 0.0.20060829-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 56,544 kB
  • ctags: 9,194
  • sloc: cpp: 88,990; ansic: 4,790; makefile: 88; sh: 39
file content (142 lines) | stat: -rw-r--r-- 3,635 bytes parent folder | download
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
	/************************/
	/*	 SETCOLOR.CPP		*/
	/************************/
/* Affichage et selection de la palette des couleurs disponibles
dans une frame
*/

#include "fctsys.h"
#include "gr_basic.h"
#include "macros.h"

#include "common.h"
#include "colors.h"


enum colors_id {
	ID_COLOR_BLACK = 2000,	// ID_COLOR_ = ID_COLOR_BLACK a ID_COLOR_BLACK + 31
};


/*******************************************/
class WinEDA_SelColorFrame: public wxDialog
/*******************************************/
/* Frame d'affichage de la palette des couleurs disponibles
*/
{
private:
public:

	// Constructor and destructor
	WinEDA_SelColorFrame(wxWindow *parent, const wxPoint& framepos);
	~WinEDA_SelColorFrame(void) {};

private:
	void SelColor(wxCommandEvent& event);

	DECLARE_EVENT_TABLE()

};
/* Construction de la table des evenements pour FrameClassMain */
BEGIN_EVENT_TABLE(WinEDA_SelColorFrame, wxDialog)
	EVT_COMMAND_RANGE(ID_COLOR_BLACK,ID_COLOR_BLACK+31,
		wxEVT_COMMAND_BUTTON_CLICKED,
		WinEDA_SelColorFrame::SelColor)
END_EVENT_TABLE()

/***************************************/
int DisplayColorFrame(wxWindow * parent)
/***************************************/
{
wxPoint framepos;
int color;

	wxGetMousePosition(&framepos.x, &framepos.y);

	WinEDA_SelColorFrame * frame = new WinEDA_SelColorFrame(parent,framepos);
	color = frame->ShowModal(); frame->Destroy();
	if (color > NBCOLOR) color = -1;
	return color;
}

/*******************************************************************/
WinEDA_SelColorFrame::WinEDA_SelColorFrame(wxWindow *parent,
							const wxPoint& framepos):
		wxDialog(parent, -1, _("Colors"), framepos, wxSize(375, 240),
				DIALOG_STYLE )
/*******************************************************************/
{
#define START_Y 10
wxBitmapButton * Button;
int ii, butt_ID, buttcolor;
wxPoint pos;
int w = 20, h = 20;
wxStaticText * text;
int right, bottom, line_height;
	
	SetFont(*g_DialogFont);

	SetReturnCode(-1);

	bottom = pos.x = 5; right = pos.y = START_Y;
	line_height = h;
	for ( ii = 0; ColorRefs[ii].m_Name != NULL ; ii++ )
	{
		butt_ID = ID_COLOR_BLACK + ii;
		wxMemoryDC iconDC;
		wxBitmap ButtBitmap(w,h);
		wxBrush Brush;
		iconDC.SelectObject( ButtBitmap );
		buttcolor = ColorRefs[ii].m_Numcolor;
		iconDC.SetPen(*wxBLACK_PEN);
		Brush.SetColour(
						ColorRefs[buttcolor].m_Red,
						ColorRefs[buttcolor].m_Green,
						ColorRefs[buttcolor].m_Blue
						);
		Brush.SetStyle(wxSOLID);

		iconDC.SetBrush(Brush);
		iconDC.SetBackground(*wxGREY_BRUSH);
		iconDC.Clear();
		iconDC.DrawRoundedRectangle(0,0, w, h, (double)h/3);

		text = new wxStaticText(this,-1,
					ColorRefs[ii].m_Name,
					wxPoint(pos.x + 2 + w , pos.y ),
					wxSize(-1,-1), 0 );
		line_height = MAX( line_height, text->GetRect().GetHeight());
		right = MAX(right, text->GetRect().GetRight());
		bottom = MAX(bottom, text->GetRect().GetBottom());
		
		Button = new wxBitmapButton(this, butt_ID,
						ButtBitmap,
						wxPoint(pos.x, pos.y  - ((h -line_height)/2)),
						wxSize(w,h) );

		pos.y +=  line_height + 5;
		if ( ii == 7 )
		{
			pos.x = right + 10; pos.y = START_Y;
		}
		else if ( (ii == 15) || (ii == 23) )
		{
			pos.x = right+ 10; pos.y = START_Y;
		}
	}
	
	SetClientSize( wxSize(right + 10, bottom + 10) );
}


/*********************************************************/
void WinEDA_SelColorFrame::SelColor(wxCommandEvent& event)
/*********************************************************/
{
int id = event.GetId();

	EndModal(id  - ID_COLOR_BLACK);
}