
(********************************************************************)
(*                                                                  *)
(*  gkb_act.s7i   Generate code for graphics keyboard actions.      *)
(*  Copyright (C) 1990 - 1994, 2004 - 2014  Thomas Mertes           *)
(*                                                                  *)
(*  This file is part of the Seed7 compiler.                        *)
(*                                                                  *)
(*  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., 51 Franklin Street,             *)
(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
(*                                                                  *)
(********************************************************************)


const ACTION: GKB_BUSY_GETC       is action "GKB_BUSY_GETC";
const ACTION: GKB_GETC            is action "GKB_GETC";
const ACTION: GKB_GETS            is action "GKB_GETS";
const ACTION: GKB_KEYPRESSED      is action "GKB_KEYPRESSED";
const ACTION: GKB_LINE_READ       is action "GKB_LINE_READ";
const ACTION: GKB_RAW_GETC        is action "GKB_RAW_GETC";
const ACTION: GKB_WINDOW          is action "GKB_WINDOW";
const ACTION: GKB_WORD_READ       is action "GKB_WORD_READ";
const ACTION: GKB_BUTTON_PRESSED  is action "GKB_BUTTON_PRESSED";
const ACTION: GKB_BUTTON_XPOS     is action "GKB_BUTTON_XPOS";
const ACTION: GKB_BUTTON_YPOS     is action "GKB_BUTTON_YPOS";


const proc: gkb_prototypes (inout file: c_prog) is func

  begin
    declareExtern(c_prog, "boolType    gkbButtonPressed (charType);");
    declareExtern(c_prog, "intType     gkbButtonXpos (void);");
    declareExtern(c_prog, "intType     gkbButtonYpos (void);");
    declareExtern(c_prog, "charType    gkbGetc (void);");
    declareExtern(c_prog, "striType    gkbGets (intType);");
    declareExtern(c_prog, "boolType    gkbKeyPressed (void);");
    declareExtern(c_prog, "striType    gkbLineRead (charType *);");
    declareExtern(c_prog, "charType    gkbRawGetc (void);");
    declareExtern(c_prog, "winType     gkbWindow (void);");
    declareExtern(c_prog, "striType    gkbWordRead (charType *);");
  end func;


const proc: process (GKB_BUSY_GETC, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "(gkbKeyPressed() ? gkbGetc() : ";
    c_expr.expr &:= charLiteral(KEY_NONE);
    c_expr.expr &:= ")";
  end func;


const proc: process (GKB_GETC, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbGetc()";
  end func;


const proc: process (GKB_GETS, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "gkbGets(";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (GKB_KEYPRESSED, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbKeyPressed()";
  end func;


const proc: process (GKB_LINE_READ, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "gkbLineRead(&(";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= "))";
  end func;


const proc: process (GKB_RAW_GETC, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbRawGetc()";
  end func;


const proc: process (GKB_WINDOW, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_win_result(c_expr);
    c_expr.result_expr := "gkbWindow()";
  end func;


const proc: process (GKB_WORD_READ, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "gkbWordRead(&(";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= "))";
  end func;


const proc: process (GKB_BUTTON_PRESSED, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbButtonPressed(";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (GKB_BUTTON_XPOS, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbButtonXpos()";
  end func;


const proc: process (GKB_BUTTON_YPOS, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "gkbButtonYpos()";
  end func;
