summaryrefslogtreecommitdiff
path: root/graphtft-fe/graphtft.hpp
blob: e6f2d9a41b86d2a1494824521705e3d2261026e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//***************************************************************************
// Group VDR/GraphTFT
// File graphtft.hpp
// Date 28.10.06 - Jörg Wendel
// This code is distributed under the terms and conditions of the
// GNU GENERAL PUBLIC LICENSE. See the file COPYING for details.
//--------------------------------------------------------------------------
// Class GraphTft
// Class ComThread
//***************************************************************************

#ifndef __GRAPHTFT_HPP__
#define __GRAPHTFT_HPP__

#include <X11/Xlib.h>
#include <Imlib2.h>
#include <string.h>
#include <unistd.h>

#define __FRONTEND

#include "../common.h"
#include "../service.h"

#include "thread.h"
#include "tcpchannel.h"

class GraphTft;

//***************************************************************************
// Communication Thread
//***************************************************************************

class ComThread : public cMyThread, public cGraphTftComService
{
   public:
      
      enum Misc
      {
         maxBuffer = 1024*1024
      };

      ComThread();
      virtual ~ComThread();

      void stop();

      int mouseEvent(int x, int y, int button, int flag, int data = 0);
      int keyEvent(int key, int flag);

      const char* getBuffer()            { return buffer; }
      int getSize()                      { return header->size; }

      void setHost(const char* aHost)    { strcpy(host, aHost); }
      void setPort(unsigned short aPort) { port = aPort; }
      void setClient(GraphTft* aClient)  { client = aClient; }
      void setJpegQuality(int quality)   { jpegQuality = quality; }

   protected:
      
      void Action();
      int read();

      TcpChannel* line;

      char* buffer;
      int bufferSize;
      GraphTft* client;

      long timeout;
      int running;
      int jpegQuality;
      TcpChannel::Header* header;
      unsigned short port;
      char host[100];
};

//***************************************************************************
// Graph TFT
//***************************************************************************

class GraphTft
{
   public:
      
      GraphTft();
      virtual ~GraphTft();

      int init();
      int exit();
      int start();
      int run();
      int paint();

      void setArgs(int argc, char *argv[]);
      int sendEvent();
      void updateImage(const unsigned char* buffer, int size);
      void dumpImage(Imlib_Image image);
      void showUsage();
      int onMotion();
      int onButtonPress(XEvent event, int press);
      int onKeyPress(XEvent event);

      static void setEloquence(int aElo) { eloquence = aElo; }
      static int getEloquence()          { return eloquence; }

   protected:

      // functions 

      void hideCursor();
      void showCursor();
      void hideBorder();
      
      // data

      Window win;
      Display* disp;
      int screen;
      Pixmap pix;
      Imlib_Image image;
      ComThread* thread;
      int hideCursorDelay;
      int resize;
      int managed;
      int width;
      int height;
      int border;
      char dump[200];
      int showHelp;
      cMutex bufferLock;
      int vdrWidth;
      int vdrHeight;
      int cursorVisible;
      int borderVisible;
      int ignoreEsc;
      time_t lastMotion;

      static int eloquence;
};

//***************************************************************************
#endif  // __GRAPHTFT_HPP__