qpc/ports/win32/qwin_gui.h

149 lines
5.1 KiB
C
Raw Normal View History

2015-04-28 13:45:35 -04:00
/**
* @file
2016-05-05 12:19:00 -04:00
* @brief QWIN GUI facilities for building realistic embedded front panels
2015-04-28 13:45:35 -04:00
* @cond
******************************************************************************
2016-06-10 21:50:26 -04:00
* Last Updated for Version: 5.6.5
* Date of the Last Update: 2016-05-13
2012-08-14 18:07:04 -04:00
*
* Q u a n t u m L e a P s
* ---------------------------
* innovating embedded systems
*
2015-04-28 13:45:35 -04:00
* Copyright (C) Quantum Leaps, LLC. All rights reserved.
2012-08-14 18:07:04 -04:00
*
* This program is open source software: you can redistribute it and/or
2015-06-05 17:05:16 -04:00
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
2012-08-14 18:07:04 -04:00
*
2015-06-05 17:05:16 -04:00
* Alternatively, this program may be distributed and modified under the
* terms of Quantum Leaps commercial licenses, which expressly supersede
* the GNU General Public License and are specifically designed for
* licensees interested in retaining the proprietary status of their code.
2012-08-14 18:07:04 -04:00
*
2015-06-05 17:05:16 -04:00
* 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.
2015-04-28 13:45:35 -04:00
*
2015-06-05 17:05:16 -04:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2012-08-14 18:07:04 -04:00
*
* Contact information:
2017-05-17 13:16:32 -04:00
* https://state-machine.com
2016-05-05 12:19:00 -04:00
* mailto:info@state-machine.com
2015-04-28 13:45:35 -04:00
******************************************************************************
* @endcond
*/
2016-05-05 12:19:00 -04:00
#ifndef qwin_gui_h
#define qwin_gui_h
2012-08-14 18:07:04 -04:00
2016-05-05 12:19:00 -04:00
#ifndef QWIN_GUI
#error The pre-processor macro QWIN_GUI must be defined
2015-06-04 22:47:13 -04:00
#endif
2012-08-14 18:07:04 -04:00
#define WIN32_LEAN_AND_MEAN
2015-04-28 13:45:35 -04:00
#include <windows.h> /* Win32 API */
2012-08-14 18:07:04 -04:00
2016-06-10 21:50:26 -04:00
#ifdef __cplusplus
extern "C" {
#endif
2012-08-14 18:07:04 -04:00
/* create the custom dialog hosting the embedded front panel ...............*/
HWND CreateCustDialog(HINSTANCE hInst, int iDlg, HWND hParent,
WNDPROC lpfnWndProc, LPCTSTR lpWndClass);
/* OwnerDrawnButton "class" ................................................*/
2016-06-10 21:50:26 -04:00
typedef struct {
UINT itemID;
2012-08-14 18:07:04 -04:00
HBITMAP hBitmapUp;
HBITMAP hBitmapDown;
HCURSOR hCursor;
2016-06-10 21:50:26 -04:00
int isDepressed;
2012-08-14 18:07:04 -04:00
} OwnerDrawnButton;
enum OwnerDrawnButtonAction {
BTN_NOACTION,
BTN_PAINTED,
BTN_DEPRESSED,
BTN_RELEASED
};
void OwnerDrawnButton_init(OwnerDrawnButton * const me,
2016-06-10 21:50:26 -04:00
UINT itemID,
2012-08-14 18:07:04 -04:00
HBITMAP hBitmapUp, HBITMAP hBitmapDwn,
HCURSOR hCursor);
void OwnerDrawnButton_xtor(OwnerDrawnButton * const me);
enum OwnerDrawnButtonAction OwnerDrawnButton_draw(
2016-06-10 21:50:26 -04:00
OwnerDrawnButton * const me,
LPDRAWITEMSTRUCT lpdis);
void OwnerDrawnButton_set(OwnerDrawnButton * const me,
int isDepressed);
BOOL OwnerDrawnButton_isDepressed(OwnerDrawnButton const * const me);
2012-08-14 18:07:04 -04:00
2015-04-28 13:45:35 -04:00
/* GraphicDisplay "class" for drawing graphic displays
* with up to 24-bit color...
*/
2016-06-10 21:50:26 -04:00
typedef struct {
HDC src_hDC;
int src_width;
int src_height;
HDC dst_hDC;
int dst_width;
int dst_height;
2012-08-14 18:07:04 -04:00
HWND hItem;
2016-06-10 21:50:26 -04:00
HBITMAP hBitmap;
2012-08-14 18:07:04 -04:00
BYTE *bits;
BYTE bgColor[3];
2013-09-23 14:34:35 -04:00
} GraphicDisplay;
2012-08-14 18:07:04 -04:00
2013-09-23 14:34:35 -04:00
void GraphicDisplay_init(GraphicDisplay * const me,
2016-06-10 21:50:26 -04:00
UINT width, UINT height,
UINT itemID, BYTE const bgColor[3]);
2013-09-23 14:34:35 -04:00
void GraphicDisplay_xtor(GraphicDisplay * const me);
void GraphicDisplay_clear(GraphicDisplay * const me);
void GraphicDisplay_redraw(GraphicDisplay * const me);
2016-06-10 21:50:26 -04:00
#define GraphicDisplay_setPixel(me_, x_, y_, color_) do { \
BYTE *pixelRGB = &(me_)->bits[3*((x_) \
+ (me_)->src_width * ((me_)->src_height - 1U - (y_)))]; \
pixelRGB[0] = (color_)[0]; \
pixelRGB[1] = (color_)[1]; \
pixelRGB[2] = (color_)[2]; \
} while (0)
#define GraphicDisplay_clearPixel(me_, x_, y_) do { \
BYTE *pixelRGB = &(me_)->bits[3*((x_) \
+ (me_)->src_width * ((me_)->src_height - 1U - (y_)))]; \
pixelRGB[0] = (me_)->bgColor[0]; \
pixelRGB[1] = (me_)->bgColor[1]; \
pixelRGB[2] = (me_)->bgColor[2]; \
} while (0)
2012-08-14 18:07:04 -04:00
/* SegmentDisplay "class" for drawing segment displays, LEDs, etc...........*/
2016-06-10 21:50:26 -04:00
typedef struct {
2015-04-28 13:45:35 -04:00
HWND *hSegment; /* array of segment controls */
UINT segmentNum; /* number of segments */
HBITMAP *hBitmap; /* array of bitmap handles */
UINT bitmapNum; /* number of bitmaps */
2012-08-14 18:07:04 -04:00
} SegmentDisplay;
void SegmentDisplay_init(SegmentDisplay * const me,
UINT segNum, UINT bitmapNum);
void SegmentDisplay_xtor(SegmentDisplay * const me);
BOOL SegmentDisplay_initSegment(SegmentDisplay * const me,
2016-06-10 21:50:26 -04:00
UINT segmentNum, UINT segmentID);
2012-08-14 18:07:04 -04:00
BOOL SegmentDisplay_initBitmap(SegmentDisplay * const me,
UINT bitmapNum, HBITMAP hBitmap);
BOOL SegmentDisplay_setSegment(SegmentDisplay * const me,
UINT segmentNum, UINT bitmapNum);
/* useful helper functions .................................................*/
void DrawBitmap(HDC hdc, HBITMAP hBitmap, int xStart, int yStart);
2016-06-10 21:50:26 -04:00
#ifdef __cplusplus
}
#endif
2016-05-05 12:19:00 -04:00
#endif /* qwin_gui_h */