2
* This file is part of HexEditor plugin for Code::Blocks Studio
3
* Copyright (C) 2008-2009 Bartlomiej Swiecki
5
* HexEditor plugin is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* HexEditor pluging is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with HexEditor. If not, see <http://www.gnu.org/licenses/>.
19
* $Id: HexEditLineBuffer.cpp 5445 2009-02-07 00:35:09Z byo $
20
* $HeadURL: svn+ssh://jenslody@svn.berlios.de/svnroot/repos/codeblocks/trunk/src/plugins/contrib/HexEditor/HexEditLineBuffer.cpp $
23
#include "HexEditLineBuffer.h"
25
#include <logmanager.h>
27
HexEditLineBuffer::HexEditLineBuffer( unsigned length )
31
m_Buffer = new char[ 2 * length ];
32
m_Position = m_Buffer;
33
m_End = m_Buffer + 2 * length;
44
HexEditLineBuffer::~HexEditLineBuffer()
49
void HexEditLineBuffer::Reset( char defaultChar, char defaultStyle )
51
for ( char* ptr = m_Buffer; ptr < m_End; ptr += 2 )
53
ptr[ 0 ] = defaultChar;
54
ptr[ 1 ] = defaultStyle;
56
m_Position = m_Buffer;
59
void HexEditLineBuffer::PutChar( char ch, char style )
61
if ( m_Position < m_End )
64
*m_Position++ = style;
68
void HexEditLineBuffer::Draw( wxDC& dc, int x, int y, int fontX, int fontY, wxColour* foregrounds, wxColour* backgrounds )
70
for ( char* ptr = m_Buffer; ptr < m_End; )
72
// Searching for continous block with same style
77
str += wxChar( ptr[ 0 ] );
80
while ( ( ptr < m_End ) && ( ptr[1] == ptr[-1] ) );
84
dc.SetBrush( backgrounds[ (int)style ] );
85
dc.SetPen( backgrounds[ (int)style ] );
87
dc.DrawRectangle( x, y, fontX * str.length(), fontY );
89
dc.SetPen( foregrounds[ (int)style ] );
90
dc.SetTextForeground( foregrounds[ (int)style ] );
91
dc.SetTextBackground( backgrounds[ (int)style ] );
93
dc.DrawText( str, x, y );
94
x += fontX * str.length();