tesseract 4.1.1
Loading...
Searching...
No Matches
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 *
6 * (C) Copyright 1996, Hewlett-Packard Co.
7 ** Licensed under the Apache License, Version 2.0 (the "License");
8 ** you may not use this file except in compliance with the License.
9 ** You may obtain a copy of the License at
10 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 *
17 **********************************************************************/
18
19// Include automatically generated configuration file if running autoconf.
20#ifdef HAVE_CONFIG_H
21#include "config_auto.h"
22#endif
23
24#include "callcpp.h"
25#include <cstdarg> // for va_end, va_list, va_start
26#include <cstdio> // for vsprintf
27#include <memory> // for unique_ptr
28#include "scrollview.h" // for ScrollView, SVEvent, SVET_ANY, SVET_INPUT
29#include "tprintf.h" // for tprintf
30
31void
32cprintf ( //Trace printf
33const char *format, ... //special message
34) {
35 va_list args; //variable args
36 char msg[1000];
37
38 va_start(args, format); //variable list
39 vsprintf(msg, format, args); //Format into msg
40 va_end(args);
41
42 tprintf("%s", msg);
43}
44
45
46#ifndef GRAPHICS_DISABLED
47ScrollView *c_create_window( /*create a window */
48 const char *name, /*name/title of window */
49 int16_t xpos, /*coords of window */
50 int16_t ypos, /*coords of window */
51 int16_t xsize, /*size of window */
52 int16_t ysize, /*size of window */
53 double xmin, /*scrolling limits */
54 double xmax, /*to stop users */
55 double ymin, /*getting lost in */
56 double ymax /*empty space */
57 ) {
58 return new ScrollView(name, xpos, ypos, xsize, ysize, xmax - xmin, ymax - ymin, true);
59}
60
61
62void c_line_color_index( /*set color */
63 void *win,
64 C_COL index) {
65 // The colors are the same as the SV ones except that SV has COLOR:NONE --> offset of 1
66 auto* window = static_cast<ScrollView*>(win);
67 window->Pen(static_cast<ScrollView::Color>(index + 1));
68}
69
70
71void c_move( /*move pen */
72 void *win,
73 double x,
74 double y) {
75 auto* window = static_cast<ScrollView*>(win);
76 window->SetCursor(static_cast<int>(x), static_cast<int>(y));
77}
78
79
80void c_draw( /*move pen */
81 void *win,
82 double x,
83 double y) {
84 auto* window = static_cast<ScrollView*>(win);
85 window->DrawTo(static_cast<int>(x), static_cast<int>(y));
86}
87
88
89void c_make_current( /*move pen */
90 void *win) {
91 auto* window = static_cast<ScrollView*>(win);
92 window->Update();
93}
94
95
96void c_clear_window( /*move pen */
97 void *win) {
98 auto* window = static_cast<ScrollView*>(win);
99 window->Clear();
100}
101
102
104 // Wait till an input or click event (all others are thrown away)
105 char ret = '\0';
106 SVEventType ev_type = SVET_ANY;
107 do {
108 std::unique_ptr<SVEvent> ev(win->AwaitEvent(SVET_ANY));
109 ev_type = ev->type;
110 if (ev_type == SVET_INPUT)
111 ret = ev->parameter[0];
112 } while (ev_type != SVET_INPUT && ev_type != SVET_CLICK);
113 return ret;
114}
115#endif
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35
void c_draw(void *win, double x, double y)
Definition: callcpp.cpp:80
void cprintf(const char *format,...)
Definition: callcpp.cpp:32
void c_move(void *win, double x, double y)
Definition: callcpp.cpp:71
void c_line_color_index(void *win, C_COL index)
Definition: callcpp.cpp:62
char window_wait(ScrollView *win)
Definition: callcpp.cpp:103
void c_make_current(void *win)
Definition: callcpp.cpp:89
ScrollView * c_create_window(const char *name, int16_t xpos, int16_t ypos, int16_t xsize, int16_t ysize, double xmin, double xmax, double ymin, double ymax)
Definition: callcpp.cpp:47
void c_clear_window(void *win)
Definition: callcpp.cpp:96
C_COL
Definition: callcpp.h:27
SVEventType
Definition: scrollview.h:45
@ SVET_CLICK
Definition: scrollview.h:48
@ SVET_ANY
Definition: scrollview.h:56
@ SVET_INPUT
Definition: scrollview.h:50
static void Update()
Definition: scrollview.cpp:709
SVEvent * AwaitEvent(SVEventType type)
Definition: scrollview.cpp:443
void DrawTo(int x, int y)
Definition: scrollview.cpp:525
void Clear()
Definition: scrollview.cpp:589
void SetCursor(int x, int y)
Definition: scrollview.cpp:519
void Pen(Color color)
Definition: scrollview.cpp:719