示例#1
0
        public void initGridPositions(List <SpellerCell> cells, int numRows, int numColumns, int spacing)
        {
            // Store pointer to cells array (for drawing later)
            taskCells = cells;

            // Store the cell parameters for drawing later
            this.numCharacterRows    = numRows;
            this.numCharacterColumns = numColumns;
            this.spacing             = spacing;

            // Calculate maximum possible size of cells, using 0.7 of total height for grid, first 0.3 part of height is reserved for cue and input
            charactersOffsetX = 0; charactersOffsetY = 0;
            if (getContentWidth() / numColumns > (0.7 * getContentHeight()) / numRows)
            {
                characterCellSize = (int)Math.Floor((double)(((0.7 * getContentHeight()) - (spacing * (numRows + 1))) / numRows));
            }
            else
            {
                characterCellSize = (int)Math.Floor((double)((getContentWidth() - (spacing * (numColumns + 1))) / numColumns));
            }

            // set the x and y offset. x offset is determined by centering the cells around the horizontal center, y offset is determined by the fact that the first 0.3 part of height is reserved for cue and input, so grid starts here
            charactersOffsetX = (getContentWidth() - numColumns * characterCellSize - spacing * (numColumns + 1)) / 2;
            //charactersOffsetY =  getContentHeight() - numRows * characterCellSize - spacing * (numRows + 1);
            charactersOffsetY = (int)(0.3 * getContentHeight());

            // Loop through the cells
            for (int i = 0; i < cells.Count; i++)
            {
                // calculate the row and column index (0 based)
                int row    = (int)Math.Floor((double)(i / numColumns));
                int column = i - (row * numColumns);

                // retrieve the reference to the cell
                SpellerCell cell = cells[i];

                // Set position and size
                cell.x = charactersOffsetX + spacing + column * (characterCellSize + spacing);
                cell.y = charactersOffsetY + spacing + row * (characterCellSize + spacing);

                cell.height = characterCellSize;
                cell.width  = characterCellSize;
            }
        }
示例#2
0
        protected override void render()
        {
            // check if fixation should be shown
            if (showFixation)
            {
                // set the fixation to white
                glColor3(1f, 1f, 1f);

                // set the text count
                int fixationTextWidth = fixationFont.getTextWidth("+");
                fixationFont.printLine((int)((getContentWidth() - fixationTextWidth) / 2), (int)((getContentHeight() - fixationFont.height) / 2), "+");
            }

            // TODO, use bool instead of value to determine whether to draw
            // check if countdown should be shown
            if (showCountDown >= 0)
            {
                // set the countdown to white
                glColor3(1f, 1f, 1f);

                // set the text count
                int countTextWidth = countdownFont.getTextWidth(showCountDown.ToString());
                countdownFont.printLine((int)((getContentWidth() - countTextWidth) / 2), (int)((getContentHeight() - countdownFont.height) / 2), showCountDown.ToString());
            }

            // Check if we should draw grid
            if (showGrid)
            {
                // loop through the cells
                for (int i = 0; i < taskCells.Count; i++)
                {
                    // retrieve cell reference
                    SpellerCell cell = taskCells[i];

                    // if cell is of a type that requires drawing
                    if (cell.cellType == SpellerCell.CellType.Input || cell.cellType == SpellerCell.CellType.Exit || cell.cellType == SpellerCell.CellType.Backspace)
                    {
                        // set white color for drawing
                        glColor3(1f, 1f, 1f);

                        // if cell type is input, draw letter, in case of backspace, draw backapace code, in case of exit, draw exit texture
                        if (cell.cellType == SpellerCell.CellType.Input || cell.cellType == SpellerCell.CellType.Backspace)
                        {
                            // get width of content that goes into cell
                            int contentWidth = inputFont.getTextWidth(cell.content);

                            // if too large fro cell, adjust font size and then reset to old values
                            //if (contentWidth > cell.width) {
                            //    double shrinkFactor = cell.width / contentWidth;
                            //    float originalHeight = inputFont.height;
                            //    inputFont.init(this, inputFontFont, (uint)(originalHeight * shrinkFactor), inputFontInputs);
                            //    inputFont.printLine((int)(cell.x + ((cell.width - inputFont.getTextWidth(cell.content)) / 2)), (int)(cell.y + ((cell.height - inputFont.height) / 2)), cell.content);
                            //    inputFont.init(this, inputFontFont, (uint)originalHeight, inputFontInputs);
                            //} else
                            inputFont.printLine((int)(cell.x + ((cell.width - inputFont.getTextWidth(cell.content)) / 2)), (int)(cell.y + ((cell.height - inputFont.height) / 2)), cell.content);
                        }
                        else if (cell.cellType == SpellerCell.CellType.Exit)
                        {
                            glBindTexture2D(exitTexture);

                            // draw cell
                            glBeginTriangles();

                            // vertex 0
                            glTexCoord2(1.0f, 1.0f);
                            glVertex3(cell.x + cell.width, cell.y + cell.height, 0.0f);

                            glTexCoord2(1.0f, 0.0f);
                            glVertex3(cell.x + cell.width, cell.y, 0.0f);

                            glTexCoord2(0.0f, 0.0f);
                            glVertex3(cell.x, cell.y, 0.0f);

                            //vertex 1
                            glTexCoord2(0.0f, 1.0f);
                            glVertex3(cell.x, cell.y + cell.height, 0.0f);

                            glTexCoord2(1.0f, 1.0f);
                            glVertex3(cell.x + cell.width, cell.y + cell.height, 0.0f);

                            glTexCoord2(0.0f, 0.0f);
                            glVertex3(cell.x, cell.y, 0.0f);

                            glEnd();
                        }
                    }
                }

                // check if the selection should be drawn
                if (selectionWidth != 0 && selectionHeight != 0)
                {
                    // set the color
                    float colorR = 1, colorG = 1, colorB = 0;
                    if (mSelected)
                    {
                        colorG = 0;
                    }

                    // draw selection
                    drawRectangle(selectionX,
                                  selectionY,
                                  (selectionX + selectionWidth),
                                  (selectionY + selectionHeight),
                                  5,
                                  colorR, colorG, colorB);
                }
            }

            // TODO, use bool instead of value to determine whether to draw
            // write the score text
            if (score > -1)
            {
                glColor3(1f, 1f, 1f);
                scoreFont.printLine(getContentWidth() - scoreFont.height * 9, 5, ("Score: " + score));
            }

            // TODO, use bool instead of value to determine whether to draw
            // check if instructions should be shown
            if (instructionText.Length != 0)
            {
                // set the text to white
                glColor3(1f, 1f, 1f);

                // print the text
                textFont.printLine((getContentWidth() - instructionTextWidth) / 2, getContentHeight() / 2, instructionText);
            }

            // check if cues should be shown
            if (cueText.Length != 0)
            {
                // set the text to white
                glColor3(1f, 1f, 1f);

                float yCueText = Math.Max(spacing + cueTextY, spacing + textFont.height);

                // print the text
                textFont.printLine((getContentWidth() - cueTextWidth) / 2, yCueText, cueText);            // show line at minum height from above, in case font is small

                drawLine(20, yCueText + textFont.height * 1.8f,
                         getContentWidth() - 20, yCueText + textFont.height * 1.8f,
                         2, false, 1, 1, 1);
            }

            // check if input should be shown
            if (inputText.Length != 0)
            {
                // set the text to white
                glColor3(1f, 1f, 1f);

                // print the text
                textFont.printLine((getContentWidth() - cueTextWidth) / 2, (spacing + textFont.height) * 3, inputText);
            }

            // check if there is no signal
            if (showConnectionLost)
            {
                // set white color for drawing
                glColor3(1f, 1f, 1f);

                // print text
                int textWidth = textFont.getTextWidth("Lost connection with device");
                textFont.printLine((int)((getContentWidth() - textWidth) / 2), (int)((getContentHeight()) / 4), "Lost connection with device");

                // set texture
                glBindTexture2D(connectionLostTexture);

                // draw texture
                glBeginTriangles();

                // vertex 0
                glTexCoord2(0.0f, 0.0f);
                glVertex3((getContentWidth() - 200) / 2, (getContentHeight() - 200) / 2, 0.0f);

                glTexCoord2(1.0f, 0.0f);
                glVertex3((getContentWidth() - 200) / 2 + 200, (getContentHeight() - 200) / 2, 0.0f);

                glTexCoord2(1.0f, 1.0f);
                glVertex3((getContentWidth() - 200) / 2 + 200, (getContentHeight() - 200) / 2 + 200, 0.0f);

                //vertex 1
                glTexCoord2(0.0f, 0.0f);
                glVertex3((getContentWidth() - 200) / 2, (getContentHeight() - 200) / 2, 0.0f);

                glTexCoord2(1.0f, 1.0f);
                glVertex3((getContentWidth() - 200) / 2 + 200, (getContentHeight() - 200) / 2 + 200, 0.0f);

                glTexCoord2(0.0f, 1.0f);
                glVertex3((getContentWidth() - 200) / 2, (getContentHeight() - 200) / 2 + 200, 0.0f);

                glEnd();
            }
        }