summaryrefslogtreecommitdiffstats
path: root/kblackbox/kbbgfx.h
blob: b3cb5d680de4806bb60731b12945010f29d94172 (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
//
//
// KBlackBox
//
// A simple game inspired by an emacs module
// 
// File: kbbgfx.h
//
// The definition of the KBBGraphic widget
// 

#ifndef KBBGFX_H
#define KBBGFX_H

#include <tqwidget.h>
#include <tqpixmap.h>

#include "util.h"

/*
   Default size of a cell
*/

#define CELLW 32
#define CELLH 32

/*
   Graphical types of the boxes
*/

#define OUTERBBG  0  
#define INNERBBG  1
#define LASERBBG  2
#define FBALLBBG  3
#define TBALLBBG  4
#define WBALLBBG  5
#define MARK1BBG  6 
#define LFIREBBG  7

/*
  These have the same pixmaps as some of those above...
*/

#define RLASERBBG 8
#define HLASERBBG 9

#define NROFTYPES 8

/*
   Negative numbers are deflected lasers... 
*/

class KBBGraphic : public TQWidget
{
  TQ_OBJECT
  
public:
  KBBGraphic(  TQPixmap** p=0, TQWidget* parent=0, const char* name=0 );
  ~KBBGraphic();

  friend class KBBGame;
  
  void setSize( int w, int h );
  RectOnArray *getGraphicBoard();
  int numC();
  int numR();
  int width();
  int height();
  int wHint() const;
  int hHint() const;
  void setCellWidth( int w );
  void setCellHeight( int h );
  void setNumRows( int rows );
  void setNumCols( int cols );

public slots:
  void setInputAccepted( bool b );
  void updateElement( int col, int row );
  void slotUp();
  void slotDown();
  void slotLeft();
  void slotRight();
  void slotInput();

signals:
  void sizeChanged();
  void inputAt( int, int, int );
  void endMouseClicked();

protected:
  virtual TQSize sizeHint() const;
  void paintEvent( TQPaintEvent* );
  void mousePressEvent( TQMouseEvent* );
  void mouseMoveEvent( TQMouseEvent* );
  void focusInEvent( TQFocusEvent* );
  void focusOutEvent( TQFocusEvent* );
  void resizeEvent( TQResizeEvent* e );

  void moveSelection(int drow, int dcol);

private:
  void paintCell( TQPainter* p, int row, int col );
  void paintCellDefault( TQPainter*, int row, int col );
  void paintCellPixmap( TQPainter*, int row, int col );
  void scalePixmaps( int w, int h );
  RectOnArray *graphicBoard;
  int curRow;
  int curCol;
  bool inputAccepted;
  int minW;
  int minH;
  int cellW;
  int cellH;
  int numCols;
  int numRows;
  TQPixmap **pix;
  TQPixmap **pixScaled;
  TQPixmap *drawBuffer;
};

#endif // KBBGFX_H