Skip to content

Commit 1c737cd

Browse files
Merge pull request #192 from lab-neuro-comp/ConvertPixel
179/Conversão de pixels para centímetros
2 parents 9287e88 + cf095b4 commit 1c737cd

10 files changed

+79
-66
lines changed

StroopTest/Controllers/ExpositionController.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ public static void BeginMatchingTest(string programName, string participantName,
150150
}
151151
}
152152

153-
public static PictureBox InitializeImageBox(int stimuliSize, Image image, bool expandImage)
153+
public static PictureBox InitializeImageBox(double stimuliSize, Image image, bool expandImage, Form form)
154154
{
155155
PictureBox newPictureBox = new PictureBox();
156+
int size = CentimeterToPixel(stimuliSize, form);
156157
newPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
157-
newPictureBox.Size = new Size(stimuliSize, stimuliSize);
158+
newPictureBox.Size = new Size(size, size);
158159

159160
newPictureBox.Image = image;
160161
newPictureBox.Enabled = true;
@@ -229,6 +230,16 @@ public static void formSecondScreen(Form form)
229230

230231
}
231232

233+
public static int CentimeterToPixel(double Centimeter, Form form)
234+
{
235+
double pixel = -1;
236+
using (Graphics g = form.CreateGraphics())
237+
{
238+
pixel = Centimeter * g.DpiY / 2.54d;
239+
}
240+
return (int)pixel;
241+
}
242+
232243

233244
}
234245
}

StroopTest/Models/Tests/Reaction/ReactionProgram.cs

+10-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace TestPlatform.Models
99
{
1010
class ReactionProgram : Program
1111
{
12-
private Int32 stimuluSize; // [3]
12+
private double stimuluSize; // [3]
1313
private Boolean isBeeping; // [9]
1414
private Boolean beepingRandom; // [19]
1515
private Int32 beepDuration; // [10]
@@ -43,7 +43,7 @@ public override string ToString()
4343
/// <summary>
4444
/// This constructor is used to create a reaction program with shapes
4545
/// </summary>
46-
public ReactionProgram(string programName, int expositionTime, int numExpositions, int stimuluSize, int intervalTime,
46+
public ReactionProgram(string programName, int expositionTime, int numExpositions, double stimuluSize, int intervalTime,
4747
bool isBeeping, int beepDuration, string stimulusColor,
4848
string fixPoint, string backgroundColor, string fixPointColor, bool intervalTimeRandom,
4949
string stimuluShape, bool beepRandom, int numberPositions,
@@ -102,7 +102,7 @@ public ReactionProgram(string programName, int expositionTime, int numExposition
102102
{
103103
// ReactionProgram properties
104104
this.expositionType = "words";
105-
this.stimuluSize = stimuluSize;
105+
this.fontSize = stimuluSize;
106106
this.isBeeping = isBeeping;
107107
this.beepDuration = beepDuration;
108108
this.FontSize = fontSize;
@@ -125,10 +125,11 @@ public ReactionProgram(string programName, int expositionTime, int numExposition
125125
this.setColorListFile(colorList);
126126
}
127127

128-
//default configurations for shapes version of ReactionProgram
128+
//default configurations for words version of ReactionProgram
129129
this.setAudioListFile("false");
130130
this.setImageListFile("false");
131131
this.ExpandImage = false;
132+
this.stimuluSize = 10;
132133

133134
// Program properties
134135
this.programName = programName;
@@ -146,7 +147,7 @@ public ReactionProgram(string programName, int expositionTime, int numExposition
146147
/// <summary>
147148
/// This constructor is used to create a reaction program with image type
148149
/// </summary>
149-
public ReactionProgram(string programName, int expositionTime, int numExpositions, int stimuluSize, int intervalTime,
150+
public ReactionProgram(string programName, int expositionTime, int numExpositions, double stimuluSize, int intervalTime,
150151
bool isBeeping, int beepDuration,
151152
string fixPoint, string backgroundColor, string fixPointColor, bool intervalTimeRandom,
152153
string imageList, bool beepRandom, int numberPositions,
@@ -188,7 +189,7 @@ public ReactionProgram(string programName, int expositionTime, int numExposition
188189
/// <summary>
189190
/// This constructor is used to create a reaction program with image and words
190191
/// </summary>
191-
public ReactionProgram(string programName, int expositionTime, int numExpositions, int stimuluSize, int intervalTime,
192+
public ReactionProgram(string programName, int expositionTime, int numExpositions, double stimuluSize, int intervalTime,
192193
bool isBeeping, int beepDuration,
193194
string fixPoint, string backgroundColor, string fixPointColor, bool intervalTimeRandom,
194195
string imageList, string wordList, string colorList, bool beepRandom, int numberPositions,
@@ -295,7 +296,7 @@ public ReactionProgram(string programName, int expositionTime, int numExposition
295296
/// </summary>
296297
public ReactionProgram(string programName, int expositionTime, int numExpositions, int intervalTime,
297298
string fixPoint, string backgroundColor, string fixPointColor, bool intervalTimeRandom, int numberPositions,
298-
string responseType, int stimulusSize, bool isExpositionRandom,string audioListFile, string imageListFile, bool expandImage, bool sstInterval)
299+
string responseType, double stimulusSize, bool isExpositionRandom,string audioListFile, string imageListFile, bool expandImage, bool sstInterval)
299300
{
300301

301302
// ReactionProgram properties
@@ -331,7 +332,7 @@ public ReactionProgram(string programName, int expositionTime, int numExposition
331332
this.intervalTimeRandom = intervalTimeRandom;
332333
}
333334

334-
public int StimuluSize
335+
public double StimuluSize
335336
{
336337
get
337338
{
@@ -587,7 +588,7 @@ public void readProgramFile(string filepath)
587588
{
588589
NumExpositions = int.Parse(config[1]);
589590
ExpositionTime = int.Parse(config[2]);
590-
StimuluSize = int.Parse(config[3]);
591+
StimuluSize = double.Parse(config[3]);
591592
IntervalTime = int.Parse(config[4]);
592593
setWordListFile(config[5]);
593594
setColorListFile(config[6]);

StroopTest/Views/MatchingPages/MatchingExposition.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ private void drawModel()
605605
else
606606
{
607607
modelControl = ExpositionController.InitializeImageBox(executingTest.ProgramInUse.StimuluSize,
608-
Image.FromFile(matchingGroups.ElementAt(groupCounter).getModelName()), false);
608+
Image.FromFile(matchingGroups.ElementAt(groupCounter).getModelName()), false, this);
609609
size = modelControl.Size;
610610
}
611611

@@ -650,7 +650,7 @@ private void drawStimulu()
650650
}
651651
else
652652
{
653-
newStimulu = ExpositionController.InitializeImageBox(executingTest.ProgramInUse.StimuluSize, Image.FromFile(element), false);
653+
newStimulu = ExpositionController.InitializeImageBox(executingTest.ProgramInUse.StimuluSize, Image.FromFile(element), false, this);
654654
newStimulu.Tag = element;
655655
size = modelControl.Size;
656656
}

StroopTest/Views/ReactionPages/FormReactExposition.cs

+15-10
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ private void drawWord()
477477
private void drawImage()
478478
{
479479
imgPictureBox = ExpositionController.InitializeImageBox(executingTest.ProgramInUse.StimuluSize, Image.FromFile(imagesList[imageCounter]),
480-
executingTest.ProgramInUse.ExpandImage);
480+
executingTest.ProgramInUse.ExpandImage, this);
481481
Point screenPosition = ScreenPosition(imgPictureBox.Size);
482482
imgPictureBox.Location = screenPosition;
483483

@@ -886,8 +886,9 @@ private Point randomScreenEightPositions(Size size)
886886
// draw on screen filled square stimulus
887887
private void drawFullSquareShape()
888888
{
889-
float widthSquare = executingTest.ProgramInUse.StimuluSize;
890-
float heightSquare = executingTest.ProgramInUse.StimuluSize;
889+
int size = ExpositionController.CentimeterToPixel(executingTest.ProgramInUse.StimuluSize, this);
890+
float widthSquare = size;
891+
float heightSquare = size;
891892

892893
SolidBrush myBrush = new SolidBrush(ColorTranslator.FromHtml(colorsList[colorCounter]));
893894
Graphics formGraphicsSquare = CreateGraphics();
@@ -906,8 +907,9 @@ private void drawFullSquareShape()
906907

907908
private void drawSquareShape()
908909
{
909-
float widthSquare = executingTest.ProgramInUse.StimuluSize;
910-
float heightSquare = executingTest.ProgramInUse.StimuluSize;
910+
int size = ExpositionController.CentimeterToPixel(executingTest.ProgramInUse.StimuluSize, this);
911+
float widthSquare = size;
912+
float heightSquare = size;
911913

912914
Pen myPen = new Pen(ColorTranslator.FromHtml(colorsList[colorCounter]));
913915
Graphics formGraphicsSquare = CreateGraphics();
@@ -926,8 +928,9 @@ private void drawSquareShape()
926928

927929
private void drawFullCircleShape()
928930
{
929-
float widthEllipse = executingTest.ProgramInUse.StimuluSize;
930-
float heightEllipse = executingTest.ProgramInUse.StimuluSize;
931+
int size = ExpositionController.CentimeterToPixel(executingTest.ProgramInUse.StimuluSize, this);
932+
float widthEllipse = size;
933+
float heightEllipse = size;
931934

932935
SolidBrush myBrush = new SolidBrush(ColorTranslator.FromHtml(colorsList[colorCounter]));
933936
Graphics formGraphicsEllipse = CreateGraphics();
@@ -946,8 +949,9 @@ private void drawFullCircleShape()
946949

947950
private void drawCircleShape()
948951
{
949-
float widthEllipse = executingTest.ProgramInUse.StimuluSize;
950-
float heightEllipse = executingTest.ProgramInUse.StimuluSize;
952+
int size = ExpositionController.CentimeterToPixel(executingTest.ProgramInUse.StimuluSize, this);
953+
float widthEllipse = size;
954+
float heightEllipse = size;
951955

952956
Pen myPen = new Pen(ColorTranslator.FromHtml(colorsList[colorCounter]));
953957
Graphics formGraphicsEllipse = CreateGraphics();
@@ -1006,7 +1010,8 @@ private void drawFullTriangleShape()
10061010
private Point[] createTrianglePoints()
10071011
{
10081012
int[] clientMiddle = { (ClientSize.Width / 2), (ClientSize.Height / 2) };
1009-
int heightTriangle = executingTest.ProgramInUse.StimuluSize;
1013+
int size = ExpositionController.CentimeterToPixel(executingTest.ProgramInUse.StimuluSize, this);
1014+
int heightTriangle = size;
10101015
Point screenPosition = this.ScreenPosition(new Size(heightTriangle, heightTriangle));
10111016
screenPosition.X -= heightTriangle / 3;
10121017
screenPosition.Y += heightTriangle / 2;

StroopTest/Views/ReactionPages/FormTRConfig.Designer.cs

+10-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

StroopTest/Views/ReactionPages/FormTRConfig.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private void editProgram()
5656
intervalTime.Value = editProgram.IntervalTime;
5757
beepingCheckbox.Checked = editProgram.IsBeeping;
5858
beepDuration.Value = editProgram.BeepDuration;
59-
stimuluSize.Value = editProgram.StimuluSize;
59+
stimuluSize.Value = (decimal) editProgram.StimuluSize;
6060
fontSizeUpDown.Value = editProgram.FontSize;
6161
positionsBox.SelectedIndex = editProgram.NumberPositions - 1;
6262
expandImageCheck.Checked = editProgram.ExpandImage;
@@ -383,7 +383,7 @@ private ReactionProgram configureNewProgram()
383383
// Program type "shapes"
384384
case 0:
385385
newProgram = new ReactionProgram(prgNameTextBox.Text, Convert.ToInt32(expoTime.Value),
386-
Convert.ToInt32(numExpo.Value), Convert.ToInt32(stimuluSize.Value),
386+
Convert.ToInt32(numExpo.Value), Convert.ToDouble(stimuluSize.Value),
387387
Convert.ToInt32(intervalTime.Value),
388388
beepingCheckbox.Checked,
389389
Convert.ToInt32(beepDuration.Value), stimulusColorCheck(),
@@ -394,7 +394,7 @@ private ReactionProgram configureNewProgram()
394394
// Program type "words"
395395
case 1:
396396
newProgram = new ReactionProgram(prgNameTextBox.Text, Convert.ToInt32(expoTime.Value),
397-
Convert.ToInt32(numExpo.Value), Convert.ToInt32(stimuluSize.Value),
397+
Convert.ToInt32(numExpo.Value), Convert.ToInt32(fontSizeUpDown.Value),
398398
Convert.ToInt32(intervalTime.Value),
399399
beepingCheckbox.Checked,
400400
Convert.ToInt32(beepDuration.Value), stimulusColorCheck(),
@@ -406,7 +406,7 @@ private ReactionProgram configureNewProgram()
406406

407407
// Program type "images"
408408
case 2:
409-
newProgram = new ReactionProgram(prgNameTextBox.Text, Convert.ToInt32(expoTime.Value), Convert.ToInt32(numExpo.Value), Convert.ToInt32(stimuluSize.Value),
409+
newProgram = new ReactionProgram(prgNameTextBox.Text, Convert.ToInt32(expoTime.Value), Convert.ToInt32(numExpo.Value), Convert.ToDouble(stimuluSize.Value),
410410
Convert.ToInt32(intervalTime.Value), beepingCheckbox.Checked, Convert.ToInt32(beepDuration.Value),
411411
fixPointValue(), bgColorButton.Text, fixPointColor(), rndIntervalCheck.Checked, openImgListButton.Text,
412412
randomBeepCheck.Checked, Convert.ToInt32(positionsBox.Text), responseType(), isRandomExposition.Checked,
@@ -415,7 +415,7 @@ private ReactionProgram configureNewProgram()
415415

416416
// Program type "imageAndWord"
417417
case 3:
418-
newProgram = new ReactionProgram(prgNameTextBox.Text, Convert.ToInt32(expoTime.Value), Convert.ToInt32(numExpo.Value), Convert.ToInt32(stimuluSize.Value),
418+
newProgram = new ReactionProgram(prgNameTextBox.Text, Convert.ToInt32(expoTime.Value), Convert.ToInt32(numExpo.Value), Convert.ToDouble(stimuluSize.Value),
419419
Convert.ToInt32(intervalTime.Value), beepingCheckbox.Checked, Convert.ToInt32(beepDuration.Value),
420420
fixPointValue(), bgColorButton.Text, fixPointColor(), rndIntervalCheck.Checked,
421421
openImgListButton.Text, openWordListButton.Text, openColorListButton.Text, randomBeepCheck.Checked,
@@ -437,7 +437,7 @@ private ReactionProgram configureNewProgram()
437437
case 5:
438438
newProgram = new ReactionProgram(prgNameTextBox.Text, Convert.ToInt32(expoTime.Value), Convert.ToInt32(numExpo.Value), Convert.ToInt32(intervalTime.Value),
439439
fixPointValue(), bgColorButton.Text, fixPointColor(), rndIntervalCheck.Checked, Convert.ToInt32(positionsBox.Text),
440-
responseType(), Convert.ToInt32(stimuluSize.Value), isRandomExposition.Checked, openAudioListButton.Text,
440+
responseType(), Convert.ToDouble(stimuluSize.Value), isRandomExposition.Checked, openAudioListButton.Text,
441441
openImgListButton.Text, expandImageCheck.Checked, sstCheckBox.Checked);
442442
break;
443443

StroopTest/Views/ReactionPages/FormTRConfig.en-US.resx

+3-3
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ Color:</value>
214214
<data name="numExpoLabel.Text" xml:space="preserve">
215215
<value>Number of Attempts:</value>
216216
</data>
217-
<data name="wordSizeLabel.Text" xml:space="preserve">
218-
<value>Stimulus size:</value>
217+
<data name="stimulusSizeLabel.Text" xml:space="preserve">
218+
<value>Stimulus size (cm):</value>
219219
</data>
220220
<data name="instructionsLabel.Text" xml:space="preserve">
221221
<value>Instructions:</value>
@@ -230,7 +230,7 @@ Color:</value>
230230
<value>save</value>
231231
</data>
232232
<data name="fontSizeLabel.Text" xml:space="preserve">
233-
<value>Font Size:</value>
233+
<value>Font Size (pt):</value>
234234
</data>
235235
<data name="fixPointGroupBox.Text" xml:space="preserve">
236236
<value>Fix Point</value>

0 commit comments

Comments
 (0)