tesseract  4.00.00dev
callcpp.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * File: callcpp.cpp
3  * Description: extern C interface calling C++ from C.
4  * Author: Ray Smith
5  * Created: Sun Feb 04 20:39:23 MST 1996
6  *
7  * (C) Copyright 1996, Hewlett-Packard Co.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 // Include automatically generated configuration file if running autoconf.
21 #ifdef HAVE_CONFIG_H
22 #include "config_auto.h"
23 #endif
24 
25 #include "errcode.h"
26 #ifdef __UNIX__
27 #include <assert.h>
28 #include <stdarg.h>
29 #endif
30 #include <time.h>
31 #include "memry.h"
32 #include "scrollview.h"
33 #include "params.h"
34 #include "callcpp.h"
35 #include "tprintf.h"
36 #include "host.h"
37 #include "unichar.h"
38 
39 void
40 cprintf ( //Trace printf
41 const char *format, ... //special message
42 ) {
43  va_list args; //variable args
44  char msg[1000];
45 
46  va_start(args, format); //variable list
47  vsprintf(msg, format, args); //Format into msg
48  va_end(args);
49 
50  tprintf ("%s", msg);
51 }
52 
53 
54 #ifndef GRAPHICS_DISABLED
55 ScrollView *c_create_window( /*create a window */
56  const char *name, /*name/title of window */
57  inT16 xpos, /*coords of window */
58  inT16 ypos, /*coords of window */
59  inT16 xsize, /*size of window */
60  inT16 ysize, /*size of window */
61  double xmin, /*scrolling limits */
62  double xmax, /*to stop users */
63  double ymin, /*getting lost in */
64  double ymax /*empty space */
65  ) {
66  return new ScrollView(name, xpos, ypos, xsize, ysize, xmax - xmin, ymax - ymin, true);
67 }
68 
69 
70 void c_line_color_index( /*set color */
71  void *win,
72  C_COL index) {
73  // The colors are the same as the SV ones except that SV has COLOR:NONE --> offset of 1
74  ScrollView* window = (ScrollView*) win;
75  window->Pen((ScrollView::Color) (index + 1));
76 }
77 
78 
79 void c_move( /*move pen */
80  void *win,
81  double x,
82  double y) {
83  ScrollView* window = (ScrollView*) win;
84  window->SetCursor((int) x, (int) y);
85 }
86 
87 
88 void c_draw( /*move pen */
89  void *win,
90  double x,
91  double y) {
92  ScrollView* window = (ScrollView*) win;
93  window->DrawTo((int) x, (int) y);
94 }
95 
96 
97 void c_make_current( /*move pen */
98  void *win) {
99  ScrollView* window = (ScrollView*) win;
100  window->Update();
101 }
102 
103 
104 void c_clear_window( /*move pen */
105  void *win) {
106  ScrollView* window = (ScrollView*) win;
107  window->Clear();
108 }
109 
110 
112  SVEvent* ev;
113  // Wait till an input or click event (all others are thrown away)
114  char ret = '\0';
115  SVEventType ev_type = SVET_ANY;
116  do {
117  ev = win->AwaitEvent(SVET_ANY);
118  ev_type = ev->type;
119  if (ev_type == SVET_INPUT)
120  ret = ev->parameter[0];
121  delete ev;
122  } while (ev_type != SVET_INPUT && ev_type != SVET_CLICK);
123  return ret;
124 }
125 #endif
126 
127 void reverse32(void *ptr) {
128  char tmp;
129  char *cptr = (char *) ptr;
130 
131  tmp = *cptr;
132  *cptr = *(cptr + 3);
133  *(cptr + 3) = tmp;
134  tmp = *(cptr + 1);
135  *(cptr + 1) = *(cptr + 2);
136  *(cptr + 2) = tmp;
137 }
138 
139 
140 void reverse16(void *ptr) {
141  char tmp;
142  char *cptr = (char *) ptr;
143 
144  tmp = *cptr;
145  *cptr = *(cptr + 1);
146  *(cptr + 1) = tmp;
147 }
char * parameter
Definition: scrollview.h:71
SVEventType type
Definition: scrollview.h:64
C_COL
Definition: callcpp.h:32
ScrollView * c_create_window(const char *name, inT16 xpos, inT16 ypos, inT16 xsize, inT16 ysize, double xmin, double xmax, double ymin, double ymax)
Definition: callcpp.cpp:55
#define tprintf(...)
Definition: tprintf.h:31
void reverse16(void *ptr)
Definition: callcpp.cpp:140
int16_t inT16
Definition: host.h:36
void SetCursor(int x, int y)
Definition: scrollview.cpp:525
void Clear()
Definition: scrollview.cpp:595
void reverse32(void *ptr)
Definition: callcpp.cpp:127
void c_move(void *win, double x, double y)
Definition: callcpp.cpp:79
void c_clear_window(void *win)
Definition: callcpp.cpp:104
void c_draw(void *win, double x, double y)
Definition: callcpp.cpp:88
static void Update()
Definition: scrollview.cpp:715
char window_wait(ScrollView *win)
Definition: callcpp.cpp:111
SVEventType
Definition: scrollview.h:45
void c_line_color_index(void *win, C_COL index)
Definition: callcpp.cpp:70
void c_make_current(void *win)
Definition: callcpp.cpp:97
void cprintf(const char *format,...)
Definition: callcpp.cpp:40
void Pen(Color color)
Definition: scrollview.cpp:726
void DrawTo(int x, int y)
Definition: scrollview.cpp:531
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:449