Compare commits
13 Commits
0.2.1
...
dev-testDi
Author | SHA1 | Date | |
---|---|---|---|
472b85b94b | |||
d21a3892df | |||
eff5e3ae25 | |||
85806b2638 | |||
4477ef0ab5 | |||
7cf06ba256 | |||
df4b14611e | |||
127ad0aac5 | |||
1d0bcd7087 | |||
d3efb637ab | |||
3dad4f219b | |||
74cfca4516 | |||
db85018627 |
@@ -59,6 +59,10 @@ Buffer::Buffer()
|
||||
tmpAnchor.m_idAnchor = -1;
|
||||
tmpAnchor.m_lineId = 0;
|
||||
tmpAnchor.m_bufferPos = 0;
|
||||
for(int32_t iii=0; iii<MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) {
|
||||
tmpAnchor.m_redrawLine[iii] = true;
|
||||
}
|
||||
tmpAnchor.m_BufferNumberLineOffset = 0;
|
||||
m_AnchorList.PushBack(tmpAnchor);
|
||||
|
||||
m_lineWidth = 10;
|
||||
@@ -86,6 +90,10 @@ Buffer::Buffer(Edn::File &newName)
|
||||
tmpAnchor.m_idAnchor = -1;
|
||||
tmpAnchor.m_lineId = 0;
|
||||
tmpAnchor.m_bufferPos = 0;
|
||||
for(int32_t iii=0; iii<MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) {
|
||||
tmpAnchor.m_redrawLine[iii] = true;
|
||||
}
|
||||
tmpAnchor.m_BufferNumberLineOffset = 0;
|
||||
m_AnchorList .PushBack(tmpAnchor);
|
||||
}
|
||||
|
||||
@@ -177,6 +185,25 @@ void Buffer::DrawLine(DrawerManager &drawer, bufferAnchor_ts &anchor)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param[in,out] ---
|
||||
*
|
||||
* @return ---
|
||||
*
|
||||
*/
|
||||
void Buffer::DrawLineEmpty(DrawerManager &drawer, int32_t lineScreenID)
|
||||
{
|
||||
ColorizeManager * myColorManager = ColorizeManager::getInstance();
|
||||
int32_t positionY = m_lineHeight * (lineScreenID);
|
||||
# ifdef NDEBUG
|
||||
drawer.Rectangle(myColorManager->Get(COLOR_CODE_BASIC_BG), 0, positionY, drawer.GetWidth(), m_lineHeight );
|
||||
# else
|
||||
drawer.Rectangle(myColorManager->Get(COLOR_CODE_CURSOR), 0, positionY, drawer.GetWidth(), m_lineHeight );
|
||||
# endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
@@ -399,6 +426,9 @@ void Buffer::AnchorAdd(int32_t anchorID)
|
||||
bufferAnchorReference_ts tmpAnchor = m_AnchorList[0];
|
||||
m_AnchorList[0].m_curent = false;
|
||||
tmpAnchor.m_idAnchor = anchorID;
|
||||
for(int32_t iii=0; iii<MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) {
|
||||
tmpAnchor.m_redrawLine[iii] = true;
|
||||
}
|
||||
m_AnchorList.PushBack(tmpAnchor);
|
||||
EDN_DEBUG("[" << m_uniqueID << "] AnchorID="<< anchorID << " ==> Added");
|
||||
}
|
||||
@@ -415,6 +445,10 @@ void Buffer::AnchorRm(int32_t anchorID)
|
||||
if (localID >=0) {
|
||||
if (m_AnchorList.Size() == 2) {
|
||||
m_AnchorList[0] = m_AnchorList[1];
|
||||
for(int32_t iii=0; iii<MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) {
|
||||
m_AnchorList[0].m_redrawLine[iii] = true;
|
||||
}
|
||||
m_AnchorList[0].m_BufferNumberLineOffset = 0;
|
||||
}
|
||||
m_AnchorList.Erase(localID);
|
||||
EDN_DEBUG("[" << m_uniqueID << "] AnchorID="<< anchorID << " ==> Remove");
|
||||
@@ -424,6 +458,21 @@ void Buffer::AnchorRm(int32_t anchorID)
|
||||
}
|
||||
|
||||
|
||||
void Buffer::AnchorRedrawAll(int32_t anchorID)
|
||||
{
|
||||
if (anchorID == -1) {
|
||||
EDN_ERROR("[" << m_uniqueID << "] AnchorID="<< anchorID << " Can not redraw this one !!!");
|
||||
return;
|
||||
}
|
||||
int32_t localID = AnchorRealId(anchorID);
|
||||
if (localID >=0) {
|
||||
AnchorForceRedrawAll(localID);
|
||||
} else {
|
||||
EDN_ERROR("[" << m_uniqueID << "] AnchorID="<< anchorID << " does not exist !!!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Buffer::AnchorGet(int32_t anchorID, bufferAnchor_ts & anchor)
|
||||
{
|
||||
EDN_ERROR("[" << m_uniqueID << "] AnchorID="<< anchorID << " Main buffer ==> can not manage Anchor (type buffer specific)");
|
||||
@@ -442,8 +491,15 @@ void Buffer::AnchorSetSize(int32_t anchorID, int32_t sizePixelX, int32_t sizePix
|
||||
{
|
||||
int32_t localID = AnchorRealId(anchorID);
|
||||
if (localID >=0) {
|
||||
m_AnchorList[localID].m_displaySize.x = sizePixelX / m_lineWidth;
|
||||
m_AnchorList[localID].m_displaySize.y = sizePixelY / m_lineHeight;
|
||||
position_ts mySize;
|
||||
mySize.x = sizePixelX / m_lineWidth;
|
||||
mySize.y = sizePixelY / m_lineHeight;
|
||||
if( m_AnchorList[localID].m_displaySize.x != mySize.x
|
||||
|| m_AnchorList[localID].m_displaySize.y != mySize.y )
|
||||
{
|
||||
AnchorForceRedrawAll(localID);
|
||||
}
|
||||
m_AnchorList[localID].m_displaySize = mySize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,6 +516,7 @@ void Buffer::AnchorSetStartOffset(int32_t anchorID, int32_t offsetX, int32_t off
|
||||
if (0<m_AnchorList[localID].m_displayStart.y) {
|
||||
m_AnchorList[localID].m_displayStart.y = 0;
|
||||
}
|
||||
AnchorForceRedrawAll(localID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,3 +542,94 @@ int32_t Buffer::AnchorCurrentId(void)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Buffer::AnchorForceRedrawAll(int32_t realAnchorId)
|
||||
{
|
||||
EDN_DEBUG("AnchorForceRedrawAll(" << realAnchorId << ")");
|
||||
if (-5000 == realAnchorId) {
|
||||
int32_t localID = AnchorCurrentId();
|
||||
if (localID >=0) {
|
||||
m_AnchorList[localID].m_BufferNumberLineOffset = 0;
|
||||
for(int32_t iii=0; iii < MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) {
|
||||
m_AnchorList[localID].m_redrawLine[iii] = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m_AnchorList[realAnchorId].m_BufferNumberLineOffset = 0;
|
||||
for(int32_t iii=0; iii < MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) {
|
||||
m_AnchorList[realAnchorId].m_redrawLine[iii] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Buffer::AnchorForceRedrawLine(int32_t lineID)
|
||||
{
|
||||
for(int32_t iii=0; iii < m_AnchorList.Size(); iii++) {
|
||||
if( m_AnchorList[iii].m_displayStart.y <= lineID
|
||||
&& m_AnchorList[iii].m_displayStart.y + MAX_LINE_DISPLAYABLE_BY_BUFFER > lineID )
|
||||
{
|
||||
m_AnchorList[iii].m_redrawLine[lineID-m_AnchorList[iii].m_displayStart.y] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO : optimiser cette fonction qui met plusieurs fois des variables a true ....
|
||||
|
||||
void Buffer::AnchorForceRedrawOffsef(int32_t offset)
|
||||
{
|
||||
EDN_DEBUG("** => set ofset : " << offset);
|
||||
if (0 == offset) {
|
||||
EDN_DEBUG("No apply offset ...");
|
||||
return;
|
||||
}
|
||||
int32_t localID = AnchorCurrentId();
|
||||
if (localID >=0) {
|
||||
EDN_DEBUG("offset ID=" << localID);
|
||||
m_AnchorList[localID].m_BufferNumberLineOffset += offset;
|
||||
|
||||
EDN_DEBUG("move redraw request : [" << m_AnchorList[localID].m_displaySize.y << "," << MAX_LINE_DISPLAYABLE_BY_BUFFER << "[=true");
|
||||
for(int32_t iii=m_AnchorList[localID].m_displaySize.y; iii < MAX_LINE_DISPLAYABLE_BY_BUFFER; iii++) {
|
||||
m_AnchorList[localID].m_redrawLine[iii] = true;
|
||||
}
|
||||
|
||||
int32_t maxSize = edn_min(m_AnchorList[localID].m_displaySize.y, MAX_LINE_DISPLAYABLE_BY_BUFFER);
|
||||
|
||||
if (offset < 0) {
|
||||
if (-1 * offset < maxSize) {
|
||||
EDN_DEBUG("move redraw request : ]" << maxSize << "," << -1*offset << "]=]" << maxSize+offset << "," << -1*offset + offset << "]");
|
||||
for(int32_t iii=maxSize-1; iii >= -1*offset; iii--) {
|
||||
m_AnchorList[localID].m_redrawLine[iii] = m_AnchorList[localID].m_redrawLine[iii+offset];
|
||||
}
|
||||
EDN_DEBUG("move redraw request : [" << 0 << "," << -1*offset << "[=true");
|
||||
for(int32_t iii=0; iii < -1*offset; iii++) {
|
||||
m_AnchorList[localID].m_redrawLine[iii] = true;
|
||||
}
|
||||
} else {
|
||||
EDN_WARNING("FORCE a total redraw... 1");
|
||||
for(int32_t iii=0; iii < maxSize; iii++) {
|
||||
m_AnchorList[localID].m_redrawLine[iii] = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (offset < maxSize) {
|
||||
EDN_DEBUG("move redraw request : [" << 0 << "," << maxSize-offset << "[=[" << offset << "," << maxSize << "[");
|
||||
for(int32_t iii=0; iii < maxSize-offset ; iii++) {
|
||||
m_AnchorList[localID].m_redrawLine[iii] = m_AnchorList[localID].m_redrawLine[iii+offset];
|
||||
}
|
||||
// note the -1 is to force the redisplay of the previous of the last line ==> special case of the gtk 3.0 marker to resize the windows
|
||||
EDN_DEBUG("move redraw request : [" << maxSize-offset-1 << "," << maxSize << "[=true");
|
||||
for(int32_t iii=maxSize-offset-1; iii < maxSize; iii++) {
|
||||
m_AnchorList[localID].m_redrawLine[iii] = true;
|
||||
}
|
||||
} else {
|
||||
EDN_WARNING("FORCE a total redraw... 2");
|
||||
for(int32_t iii=0; iii < maxSize; iii++) {
|
||||
m_AnchorList[localID].m_redrawLine[iii] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EDN_ERROR("can not find the real ID in linste.Size()=" << m_AnchorList.Size());
|
||||
}
|
||||
}
|
||||
|
@@ -31,6 +31,8 @@
|
||||
#include "charset.h"
|
||||
#include "Edn.h"
|
||||
|
||||
#define MAX_LINE_DISPLAYABLE_BY_BUFFER (200)
|
||||
|
||||
extern "C"
|
||||
{
|
||||
typedef struct{
|
||||
@@ -49,6 +51,8 @@ extern "C"
|
||||
int32_t m_bufferPos; //!< position of the first lineId
|
||||
position_ts m_displayStart; //!< start display position
|
||||
position_ts m_displaySize; //!< size of the curent display
|
||||
bool m_redrawLine[MAX_LINE_DISPLAYABLE_BY_BUFFER]; //!< List of the current line that must be redisplayed
|
||||
int32_t m_BufferNumberLineOffset; //!< number of line that might be an ofset on the curent screen
|
||||
} bufferAnchorReference_ts;
|
||||
|
||||
typedef struct {
|
||||
@@ -60,6 +64,8 @@ extern "C"
|
||||
int32_t m_posStop; //!< position of the end of the line
|
||||
int32_t m_selectionPosStart; //!< position of the selection start
|
||||
int32_t m_selectionPosStop; //!< position of the selection stop
|
||||
bool m_redrawLine[MAX_LINE_DISPLAYABLE_BY_BUFFER]; //!< List of the current line that must be redisplayed
|
||||
int32_t m_BufferNumberLineOffset; //!< number of line that might be an ofset on the curent screen
|
||||
} bufferAnchor_ts;
|
||||
}
|
||||
|
||||
@@ -104,6 +110,7 @@ class Buffer {
|
||||
virtual void SetLineDisplay(uint32_t lineNumber);
|
||||
|
||||
virtual void DrawLine(DrawerManager &drawer, bufferAnchor_ts &anchor);
|
||||
virtual void DrawLineEmpty(DrawerManager &drawer, int32_t lineScreenID);
|
||||
// return the new cursor position ...
|
||||
virtual void AddChar(char * UTF8data);
|
||||
virtual void cursorMove(int32_t gtkKey);
|
||||
@@ -142,6 +149,7 @@ class Buffer {
|
||||
public:
|
||||
void AnchorAdd(int32_t anchorID);
|
||||
void AnchorRm(int32_t anchorID);
|
||||
void AnchorRedrawAll(int32_t anchorID);
|
||||
virtual bool AnchorGet(int32_t anchorID, bufferAnchor_ts & anchor);
|
||||
virtual bool AnchorNext(bufferAnchor_ts & anchor);
|
||||
void AnchorSetSize(int32_t anchorID, int32_t sizePixelX, int32_t sizePixelY);
|
||||
@@ -152,6 +160,9 @@ class Buffer {
|
||||
int32_t m_lineHeight;
|
||||
int32_t AnchorRealId(int32_t anchorID);
|
||||
int32_t AnchorCurrentId(void);
|
||||
void AnchorForceRedrawAll(int32_t realAnchorId = -5000);
|
||||
void AnchorForceRedrawLine(int32_t lineID);
|
||||
void AnchorForceRedrawOffsef(int32_t offset);
|
||||
Edn::VectorType<bufferAnchorReference_ts> m_AnchorList; //!< list of all line anchor in the current buffer
|
||||
int32_t m_uniqueID;
|
||||
|
||||
|
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file BufferAnchor.cpp
|
||||
* @brief Editeur De N'ours : anchor on a secific buffer (Sources)
|
||||
* @author Edouard DUPIN
|
||||
* @date 11/09/2011
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#include "BufferAnchor.h"
|
||||
|
||||
BufferAnchor::BufferAnchor(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
BufferAnchor::~BufferAnchor(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
@@ -1,56 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file BufferAnchor.h
|
||||
* @brief Editeur De N'ours : anchor on a secific buffer (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 11/09/2011
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __BUFFER_ANCHOR_H__
|
||||
#define __BUFFER_ANCHOR_H__
|
||||
|
||||
#include "Display.h"
|
||||
#include "charset.h"
|
||||
#include "Edn.h"
|
||||
|
||||
|
||||
class BufferAnchor
|
||||
{
|
||||
public :
|
||||
BufferAnchor(void);
|
||||
~BufferAnchor(void);
|
||||
MoveAnchor(int32_t offsetLine);
|
||||
//BufModification(...);
|
||||
bool DisplayUpdateFirstLine(void);
|
||||
bool DisplayUpdateNextLine(void);
|
||||
private :
|
||||
int32_t m_lineId;
|
||||
int32_t m_bufferPos;
|
||||
public:
|
||||
int32_t m_lineNumber;
|
||||
int32_t m_posStart;
|
||||
int32_t m_posStop;
|
||||
int32_t m_selectionPosStart;
|
||||
int32_t m_selectionPosStop;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -43,7 +43,7 @@
|
||||
BufferEmpty::BufferEmpty()
|
||||
{
|
||||
m_lineWidth = Display::GetFontWidth();
|
||||
m_lineHeight = Display::GetFontHeight();
|
||||
m_lineHeight = Display::GetFontHeight()*4;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -56,14 +56,13 @@ void BufferText::BasicInit(void)
|
||||
m_nbColoneForLineNumber = 1;
|
||||
// init the link with the buffer manager
|
||||
myColorManager = ColorizeManager::getInstance();
|
||||
// Init Selection mode :
|
||||
SelectionEnd();
|
||||
//EDN_INFO("Init");
|
||||
// new mode :
|
||||
m_cursorPos = 0;
|
||||
m_cursorPosPrevious = m_cursorPos;
|
||||
m_cursorPreferredCol = -1;
|
||||
m_cursorOn = true;
|
||||
|
||||
// set at the sustem buffer internal
|
||||
m_lineWidth = Display::GetFontWidth();
|
||||
m_lineHeight = Display::GetFontHeight();
|
||||
}
|
||||
@@ -88,7 +87,6 @@ void BufferText::NameChange(void)
|
||||
m_EdnBuf.SetHLSystem(myHL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -175,28 +173,6 @@ BufferText::~BufferText(void)
|
||||
}
|
||||
|
||||
|
||||
void BufferText::SelectionStart(void)
|
||||
{
|
||||
// start a nex selection
|
||||
SelectionCheckMode();
|
||||
//EDN_DEBUG("SELECT_start");
|
||||
}
|
||||
|
||||
void BufferText::SelectionEnd(void)
|
||||
{
|
||||
//EDN_DEBUG("SELECT_stop");
|
||||
}
|
||||
|
||||
void BufferText::SelectionCheckMode(void)
|
||||
{
|
||||
/*
|
||||
if (true == globals::IsSetCtrl() ) {
|
||||
} else {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
@@ -207,7 +183,7 @@ void BufferText::SelectionCheckMode(void)
|
||||
*/
|
||||
void BufferText::GetInfo(infoStatBuffer_ts &infoToUpdate)
|
||||
{
|
||||
|
||||
EDN_WARNING("TODO ...");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,7 +196,7 @@ void BufferText::GetInfo(infoStatBuffer_ts &infoToUpdate)
|
||||
*/
|
||||
void BufferText::SetLineDisplay(uint32_t lineNumber)
|
||||
{
|
||||
|
||||
EDN_WARNING("TODO ...");
|
||||
}
|
||||
|
||||
|
||||
@@ -432,6 +408,10 @@ void BufferText::MouseEvent(int32_t width, int32_t height)
|
||||
m_cursorPreferredCol = posX;
|
||||
}
|
||||
m_EdnBuf.Unselect(SELECTION_PRIMARY);
|
||||
/*
|
||||
// for the redraw to permit to remove display error ...
|
||||
AnchorForceRedrawAll();
|
||||
*/
|
||||
|
||||
UpdateWindowsPosition();
|
||||
}
|
||||
@@ -500,6 +480,7 @@ void BufferText::MouseEventDouble(void)
|
||||
int32_t beginPos, endPos;
|
||||
if (true == m_EdnBuf.SelectAround(m_cursorPos, beginPos, endPos)) {
|
||||
m_EdnBuf.Select(SELECTION_PRIMARY, beginPos, endPos);
|
||||
m_cursorPosPrevious = m_cursorPos;
|
||||
m_cursorPos = endPos;
|
||||
}
|
||||
// no else
|
||||
@@ -516,6 +497,7 @@ void BufferText::MouseEventDouble(void)
|
||||
void BufferText::MouseEventTriple(void)
|
||||
{
|
||||
m_EdnBuf.Select(SELECTION_PRIMARY, m_EdnBuf.StartOfLine(m_cursorPos), m_EdnBuf.EndOfLine(m_cursorPos));
|
||||
m_cursorPosPrevious = m_cursorPos;
|
||||
m_cursorPos = m_EdnBuf.EndOfLine(m_cursorPos);
|
||||
}
|
||||
|
||||
@@ -524,6 +506,8 @@ void BufferText::RemoveLine(void)
|
||||
int32_t start = m_EdnBuf.StartOfLine(m_cursorPos);
|
||||
int32_t stop = m_EdnBuf.EndOfLine(m_cursorPos);
|
||||
m_EdnBuf.Remove(start, stop+1);
|
||||
// for the redraw to permit to remove display error ...
|
||||
AnchorForceRedrawAll();
|
||||
SetInsertPosition(start);
|
||||
SetModify(true);
|
||||
}
|
||||
@@ -531,14 +515,20 @@ void BufferText::RemoveLine(void)
|
||||
void BufferText::SelectAll(void)
|
||||
{
|
||||
m_EdnBuf.Select(SELECTION_PRIMARY, 0, m_EdnBuf.Size());
|
||||
m_cursorPosPrevious = m_cursorPos;
|
||||
m_cursorPos = m_EdnBuf.Size();
|
||||
AnchorForceRedrawAll();
|
||||
}
|
||||
|
||||
void BufferText::SelectNone(void)
|
||||
{
|
||||
m_EdnBuf.Unselect(SELECTION_PRIMARY);
|
||||
// for the redraw to permit to remove display error ...
|
||||
AnchorForceRedrawAll();
|
||||
}
|
||||
|
||||
#define SCROLL_NB_LINE (3)
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
@@ -549,7 +539,7 @@ void BufferText::SelectNone(void)
|
||||
*/
|
||||
void BufferText::ScrollDown(void)
|
||||
{
|
||||
MoveUpDown(3);
|
||||
MoveUpDown(SCROLL_NB_LINE);
|
||||
}
|
||||
|
||||
|
||||
@@ -563,7 +553,7 @@ void BufferText::ScrollDown(void)
|
||||
*/
|
||||
void BufferText::ScrollUp(void)
|
||||
{
|
||||
MoveUpDown(-3);
|
||||
MoveUpDown(-1 * SCROLL_NB_LINE);
|
||||
}
|
||||
|
||||
|
||||
@@ -582,7 +572,9 @@ void BufferText::MoveUpDown(int32_t ofset)
|
||||
int32_t nbLine = m_EdnBuf.NumberOfLines();
|
||||
if (m_AnchorList[iii].m_displayStart.y+ofset+3 > nbLine) {
|
||||
m_AnchorList[iii].m_displayStart.y = nbLine-3;
|
||||
AnchorForceRedrawOffsef(m_AnchorList[iii].m_displayStart.y-(nbLine-3));
|
||||
} else {
|
||||
AnchorForceRedrawOffsef(ofset);
|
||||
m_AnchorList[iii].m_displayStart.y += ofset;
|
||||
}
|
||||
m_AnchorList[iii].m_bufferPos = m_EdnBuf.CountForwardNLines(0, m_AnchorList[iii].m_displayStart.y);
|
||||
@@ -590,10 +582,12 @@ void BufferText::MoveUpDown(int32_t ofset)
|
||||
} else {
|
||||
ofset *= -1;
|
||||
if (m_AnchorList[iii].m_displayStart.y < ofset) {
|
||||
AnchorForceRedrawOffsef(-1 * m_AnchorList[iii].m_displayStart.y);
|
||||
m_AnchorList[iii].m_displayStart.y = 0;
|
||||
m_AnchorList[iii].m_bufferPos = 0;
|
||||
m_AnchorList[iii].m_lineId = 0;
|
||||
} else {
|
||||
AnchorForceRedrawOffsef(-1 * ofset);
|
||||
m_AnchorList[iii].m_displayStart.y -= ofset;
|
||||
m_AnchorList[iii].m_bufferPos = m_EdnBuf.CountForwardNLines(0, m_AnchorList[iii].m_displayStart.y);
|
||||
m_AnchorList[iii].m_lineId = m_AnchorList[iii].m_displayStart.y;
|
||||
@@ -610,7 +604,6 @@ void BufferText::SetInsertPosition(int32_t newPos, bool insertChar)
|
||||
int32_t rememberCursorPos = m_cursorPos;
|
||||
|
||||
//EDN_DEBUG("newPos=" << newPos);
|
||||
|
||||
// unselect buffer:
|
||||
m_EdnBuf.Unselect(SELECTION_PRIMARY);
|
||||
/* make sure new position is ok, do nothing if it hasn't changed */
|
||||
@@ -621,6 +614,7 @@ void BufferText::SetInsertPosition(int32_t newPos, bool insertChar)
|
||||
if (newPos > m_EdnBuf.Size()) {
|
||||
newPos = m_EdnBuf.Size();
|
||||
}
|
||||
m_cursorPosPrevious = m_cursorPos;
|
||||
m_cursorPos = newPos;
|
||||
}
|
||||
m_cursorPreferredCol = -1;
|
||||
@@ -727,19 +721,8 @@ bool BufferText::TextDMoveDown(int32_t offset)
|
||||
*/
|
||||
void BufferText::cursorMove(int32_t gtkKey)
|
||||
{
|
||||
int32_t tmplineID;
|
||||
bool needUpdatePosition = true;
|
||||
// check selection event ...
|
||||
/*
|
||||
if (true == globals::IsSetShift() ) {
|
||||
if ( CURSOR_MODE_NORMAL == cursorMode) {
|
||||
SelectionStart();
|
||||
} else {
|
||||
SelectionCheckMode();
|
||||
}
|
||||
} else {
|
||||
SelectionEnd();
|
||||
}
|
||||
*/
|
||||
switch(gtkKey) {
|
||||
# ifdef USE_GTK_VERSION_3_0
|
||||
case GDK_KEY_Left:
|
||||
@@ -784,7 +767,7 @@ void BufferText::cursorMove(int32_t gtkKey)
|
||||
case GDK_Page_Up:
|
||||
# endif
|
||||
//EDN_INFO("keyEvent : <PAGE-UP>");
|
||||
TextDMoveUp(m_AnchorList[AnchorCurrentId()].m_displaySize.x);
|
||||
TextDMoveUp(m_AnchorList[AnchorCurrentId()].m_displaySize.y);
|
||||
break;
|
||||
# ifdef USE_GTK_VERSION_3_0
|
||||
case GDK_KEY_Page_Down:
|
||||
@@ -792,7 +775,7 @@ void BufferText::cursorMove(int32_t gtkKey)
|
||||
case GDK_Page_Down:
|
||||
# endif
|
||||
//EDN_INFO("keyEvent : <PAGE-DOWN>");
|
||||
TextDMoveDown(m_AnchorList[AnchorCurrentId()].m_displaySize.x);
|
||||
TextDMoveDown(m_AnchorList[AnchorCurrentId()].m_displaySize.y);
|
||||
break;
|
||||
# ifdef USE_GTK_VERSION_3_0
|
||||
case GDK_KEY_Begin:
|
||||
@@ -831,16 +814,25 @@ void BufferText::cursorMove(int32_t gtkKey)
|
||||
*/
|
||||
void BufferText::UpdateWindowsPosition(bool centerPage)
|
||||
{
|
||||
for (int32_t iii=0; iii < m_AnchorList.Size() ; iii++) {
|
||||
int32_t iii = AnchorCurrentId();
|
||||
if (iii >=0) {
|
||||
int32_t linePreviousID = m_EdnBuf.GetLinesIdWithRef(m_cursorPosPrevious, m_AnchorList[iii].m_bufferPos, m_AnchorList[iii].m_lineId);
|
||||
AnchorForceRedrawLine(linePreviousID);
|
||||
|
||||
if (centerPage == false) {
|
||||
// Display position (Y mode):
|
||||
//EDN_INFO(" m_displayStart(" << m_displayStart.x << "," << m_displayStart.y << ") m_displaySize(" << m_displaySize.x << "," <<m_displaySize.y << ")");
|
||||
int32_t lineStartPos;
|
||||
// Get current position of cursor :
|
||||
position_ts cursorPosition;
|
||||
cursorPosition.y = m_EdnBuf.CountLines(0, m_cursorPos);
|
||||
int32_t lineStartPos = m_EdnBuf.StartOfLine(m_cursorPos);
|
||||
EDN_WARNING("plop");
|
||||
cursorPosition.y = m_EdnBuf.GetLinesIdWithRef(m_cursorPos, m_AnchorList[iii].m_bufferPos, m_AnchorList[iii].m_lineId);
|
||||
AnchorForceRedrawLine(cursorPosition.y);
|
||||
lineStartPos = m_EdnBuf.StartOfLine(m_cursorPos);
|
||||
cursorPosition.x = m_EdnBuf.CountDispChars(lineStartPos, m_cursorPos);
|
||||
//EDN_INFO(" curent cursor position : (" << cursorPosition.x << "," << cursorPosition.y << ")");
|
||||
|
||||
position_ts displayPreviousStart = m_AnchorList[iii].m_displayStart;
|
||||
//EDN_INFO(" m_displayStart(" << m_AnchorList[iii].m_displayStart.x << "," << m_AnchorList[iii].m_displayStart.y << ") m_displaySize(" << m_AnchorList[iii].m_displaySize.x << "," << m_AnchorList[iii].m_displaySize.y << ")");
|
||||
if (m_AnchorList[iii].m_displayStart.y > (int32_t)cursorPosition.y - globals::getNbLineBorder() ) {
|
||||
m_AnchorList[iii].m_displayStart.y = cursorPosition.y - globals::getNbLineBorder();
|
||||
if (m_AnchorList[iii].m_displayStart.y < 0) {
|
||||
@@ -863,11 +855,32 @@ void BufferText::UpdateWindowsPosition(bool centerPage)
|
||||
//update the buffer position ID :
|
||||
m_AnchorList[iii].m_bufferPos = m_EdnBuf.CountForwardNLines(0, m_AnchorList[iii].m_displayStart.y);
|
||||
m_AnchorList[iii].m_lineId = m_AnchorList[iii].m_displayStart.y;
|
||||
if (m_AnchorList[iii].m_displayStart.x != displayPreviousStart.x) {
|
||||
AnchorForceRedrawAll(iii);
|
||||
} else {
|
||||
if (m_AnchorList[iii].m_displayStart.y != displayPreviousStart.y) {
|
||||
//EDN_WARNING("SELECT an ofset : displayPreviousStart.y=" << displayPreviousStart.y << " m_AnchorList[iii].m_displayStart.y=" << m_AnchorList[iii].m_displayStart.y << " ==>" << m_AnchorList[iii].m_displayStart.y - displayPreviousStart.y);
|
||||
//EDN_WARNING("SELECT ... offset = " << m_AnchorList[iii].m_BufferNumberLineOffset);
|
||||
AnchorForceRedrawOffsef(m_AnchorList[iii].m_displayStart.y - displayPreviousStart.y);
|
||||
//EDN_WARNING("SELECT ... offset = " << m_AnchorList[iii].m_BufferNumberLineOffset);
|
||||
}
|
||||
int32_t SelectionStart, SelectionEnd, SelectionRectStart, SelectionRectEnd;
|
||||
bool SelectionIsRect;
|
||||
bool haveSelectionActive = m_EdnBuf.GetSelectionPos(SELECTION_PRIMARY, SelectionStart, SelectionEnd, SelectionIsRect, SelectionRectStart, SelectionRectEnd);
|
||||
if (true == haveSelectionActive) {
|
||||
int32_t start = edn_min(linePreviousID, cursorPosition.y);
|
||||
int32_t stop = edn_max(linePreviousID, cursorPosition.y);
|
||||
//EDN_WARNING("SELECT force redraw range of lines : (" << start << "," << stop << ")");
|
||||
for (int32_t jjj=start; jjj <= stop; jjj++) {
|
||||
AnchorForceRedrawLine(jjj);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// center the line at the middle of the screen :
|
||||
position_ts cursorPosition;
|
||||
//EDN_DEBUG(" -------------------------------------------------");
|
||||
cursorPosition.y = m_EdnBuf.CountLines(0, m_cursorPos);
|
||||
cursorPosition.y = m_EdnBuf.GetLinesIdWithRef(m_cursorPos, m_AnchorList[iii].m_bufferPos, m_AnchorList[iii].m_lineId);
|
||||
//EDN_DEBUG(" cursor position : " << m_cursorPos << " ==> ligne=" << cursorPosition.y);
|
||||
cursorPosition.x = 0;
|
||||
|
||||
@@ -879,6 +892,7 @@ void BufferText::UpdateWindowsPosition(bool centerPage)
|
||||
m_AnchorList[iii].m_lineId = m_AnchorList[iii].m_displayStart.y;
|
||||
//EDN_DEBUG(" display start : " << m_displayStart.x << "x" << m_displayStart.y);
|
||||
//EDN_DEBUG(" -------------------------------------------------");
|
||||
AnchorForceRedrawAll(iii);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -917,11 +931,13 @@ void BufferText::AddChar(char * UTF8data)
|
||||
m_EdnBuf.ReplaceSelected(SELECTION_PRIMARY, tmpVect);
|
||||
SetInsertPosition(SelectionStart+tmpVect.Size(), true);
|
||||
} else {
|
||||
int32_t tmpPos = m_cursorPos;
|
||||
if (true == globals::IsSetShift() ) {
|
||||
m_cursorPos = m_EdnBuf.UnIndent(SELECTION_PRIMARY);
|
||||
tmpPos = m_EdnBuf.UnIndent(SELECTION_PRIMARY);
|
||||
} else {
|
||||
m_cursorPos = m_EdnBuf.Indent(SELECTION_PRIMARY);
|
||||
tmpPos = m_EdnBuf.Indent(SELECTION_PRIMARY);
|
||||
}
|
||||
SetInsertPosition(tmpPos, true);
|
||||
}
|
||||
}
|
||||
actionDone = true;
|
||||
@@ -981,6 +997,7 @@ void BufferText::AddChar(char * UTF8data)
|
||||
}
|
||||
actionDone = true;
|
||||
}
|
||||
AnchorForceRedrawAll();
|
||||
}
|
||||
|
||||
if (false == actionDone) {
|
||||
@@ -1011,7 +1028,6 @@ void BufferText::AddChar(char * UTF8data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetModify(true);
|
||||
UpdateWindowsPosition();
|
||||
}
|
||||
@@ -1041,6 +1057,8 @@ void BufferText::JumpAtLine(int32_t newLine)
|
||||
{
|
||||
int32_t positionLine = m_EdnBuf.CountForwardNLines(0, newLine);
|
||||
m_EdnBuf.Unselect(SELECTION_PRIMARY);
|
||||
// for the redraw to permit to remove display error ...
|
||||
AnchorForceRedrawAll();
|
||||
EDN_DEBUG("jump at the line : " << newLine );
|
||||
SetInsertPosition(positionLine);
|
||||
UpdateWindowsPosition(true);
|
||||
@@ -1204,8 +1222,10 @@ void BufferText::Cut(int8_t clipboardID)
|
||||
if (true == haveSelectionActive ) {
|
||||
EDN_INFO("REMOVE SELECTION");
|
||||
m_EdnBuf.RemoveSelected(SELECTION_PRIMARY);
|
||||
m_cursorPos = SelectionStart;
|
||||
SetInsertPosition(SelectionStart, true);
|
||||
}
|
||||
// for the redraw to permit to remove display error ...
|
||||
AnchorForceRedrawAll();
|
||||
UpdateWindowsPosition();
|
||||
SetModify(true);
|
||||
}
|
||||
@@ -1232,13 +1252,14 @@ void BufferText::Paste(int8_t clipboardID)
|
||||
if (true == haveSelectionActive ) {
|
||||
// replace data
|
||||
m_EdnBuf.ReplaceSelected(SELECTION_PRIMARY, mVect );
|
||||
m_cursorPos = SelectionStart + mVect.Size();
|
||||
SetInsertPosition(SelectionStart + mVect.Size(), true);
|
||||
} else {
|
||||
// insert data
|
||||
m_EdnBuf.Insert(m_cursorPos, mVect);
|
||||
m_cursorPos += mVect.Size();
|
||||
SetInsertPosition(m_cursorPos + mVect.Size(), true);
|
||||
}
|
||||
|
||||
// for the redraw to permit to remove display error ...
|
||||
AnchorForceRedrawAll();
|
||||
UpdateWindowsPosition();
|
||||
SetModify(true);
|
||||
}
|
||||
@@ -1252,6 +1273,8 @@ void BufferText::Undo(void)
|
||||
UpdateWindowsPosition();
|
||||
SetModify(true);
|
||||
}
|
||||
// for the redraw to permit to remove display error ...
|
||||
AnchorForceRedrawAll();
|
||||
}
|
||||
|
||||
void BufferText::Redo(void)
|
||||
@@ -1262,6 +1285,8 @@ void BufferText::Redo(void)
|
||||
UpdateWindowsPosition();
|
||||
SetModify(true);
|
||||
}
|
||||
// for the redraw to permit to remove display error ...
|
||||
AnchorForceRedrawAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -1301,6 +1326,17 @@ bool BufferText::AnchorGet(int32_t anchorID, bufferAnchor_ts & anchor)
|
||||
anchor.m_selectionPosStart = selStart+1;
|
||||
anchor.m_selectionPosStop = selEnd+1;
|
||||
}
|
||||
EDN_DEBUG("SET in anchor " << m_AnchorList[localID].m_displaySize.y << " lines to display");
|
||||
for(int32_t iii=0; iii</*edn_min(*/m_AnchorList[localID].m_displaySize.y/*, MAX_LINE_DISPLAYABLE_BY_BUFFER)*/; iii++) {
|
||||
anchor.m_redrawLine[iii] = m_AnchorList[localID].m_redrawLine[iii];
|
||||
m_AnchorList[localID].m_redrawLine[iii] = false;
|
||||
/*if (iii > m_AnchorList[localID].m_displaySize.y - 4) {
|
||||
anchor.m_redrawLine[iii] = true;
|
||||
}*/
|
||||
}
|
||||
anchor.m_BufferNumberLineOffset = m_AnchorList[localID].m_BufferNumberLineOffset;
|
||||
m_AnchorList[localID].m_BufferNumberLineOffset = 0;
|
||||
|
||||
EDN_DEBUG("Request display : line=" << anchor.m_lineNumber << " (" << anchor.m_posStart << "," << anchor.m_posStop << ")");
|
||||
EDN_DEBUG(" ==> select : (" << anchor.m_selectionPosStart << "," << anchor.m_selectionPosStop << ")");
|
||||
return true;
|
||||
|
@@ -87,11 +87,8 @@ class BufferText : public Buffer {
|
||||
// Direct buffer IO
|
||||
EdnBuf m_EdnBuf; //!< buffer associated on this displayer
|
||||
|
||||
//position_ts m_displayStart; //!< position where the display is starting
|
||||
//position_ts m_displaySize; //!< number of char displayable in the screan
|
||||
//int32_t m_displayStartBufferPos; //!< position where the buffer start
|
||||
|
||||
// Cursor :
|
||||
int32_t m_cursorPosPrevious; //!< Previous position in the buffer of the cursor
|
||||
int32_t m_cursorPos; //!< position in the buffer of the cursor
|
||||
int32_t m_cursorPreferredCol; //!< colomn of the last up and down ...
|
||||
bool m_cursorOn; //!< the blink of the cursor ...
|
||||
@@ -104,10 +101,6 @@ class BufferText : public Buffer {
|
||||
|
||||
void CleanSelectLine(void);
|
||||
|
||||
void SelectionStart(void);
|
||||
void SelectionEnd(void);
|
||||
void SelectionCheckMode(void);
|
||||
|
||||
void CheckAndUpdateLineForModification(uint32_t lineID);
|
||||
bool TextDMoveUp(int32_t offset);
|
||||
bool TextDMoveDown(int32_t offset);
|
||||
|
@@ -57,6 +57,8 @@ BufferView::BufferView(void) : MsgBroadcast("Buffer View", EDN_CAT_GUI)
|
||||
# elif defined( USE_GTK_VERSION_2_0 )
|
||||
GTK_WIDGET_SET_FLAGS(m_widget, GTK_CAN_FOCUS);
|
||||
# endif
|
||||
// Remove double-buffering ==> in the current case we can not get the previous display...
|
||||
gtk_widget_set_double_buffered(m_widget, false);
|
||||
// Focus Event
|
||||
g_signal_connect( G_OBJECT(m_widget), "focus_in_event", G_CALLBACK(CB_focusGet), this);
|
||||
g_signal_connect( G_OBJECT(m_widget), "focus_out_event", G_CALLBACK(CB_focusLost), this);
|
||||
|
@@ -65,6 +65,9 @@ CodeView::CodeView(void) : MsgBroadcast("Code View", EDN_CAT_WORK_AREA)
|
||||
# elif defined( USE_GTK_VERSION_2_0 )
|
||||
GTK_WIDGET_SET_FLAGS(m_widget, GTK_CAN_FOCUS);
|
||||
# endif
|
||||
// Remove double-buffering ==> in the current case we can not get the previous display...
|
||||
gtk_widget_set_double_buffered(m_widget, false);
|
||||
|
||||
// Focus Event
|
||||
g_signal_connect( G_OBJECT(m_widget), "focus_in_event", G_CALLBACK(CB_focusGet), this);
|
||||
g_signal_connect( G_OBJECT(m_widget), "focus_out_event", G_CALLBACK(CB_focusLost), this);
|
||||
@@ -189,12 +192,11 @@ void CodeView::OnMessage(int32_t id, int32_t dataID)
|
||||
break;
|
||||
}
|
||||
// Force redraw of the widget
|
||||
gtk_widget_queue_draw(m_widget);
|
||||
gtk_widget_queue_draw_area(m_widget, 0, 0, m_shawableAreaX, m_shawableAreaY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#define COUNT_TIME plop
|
||||
|
||||
gboolean CodeView::CB_displayDraw( GtkWidget *widget, GdkEventExpose *event, gpointer data)
|
||||
{
|
||||
CodeView * self = reinterpret_cast<CodeView*>(data);
|
||||
@@ -231,10 +233,9 @@ gboolean CodeView::CB_displayDraw( GtkWidget *widget, GdkEventExpose *event, gpo
|
||||
ColorizeManager *myColorManager = NULL;
|
||||
myColorManager = ColorizeManager::getInstance();
|
||||
|
||||
DrawerManager monDrawer(widget, self->m_shawableAreaX, self->m_shawableAreaY);
|
||||
Buffer * tmpBuf = self->m_bufferManager->Get(self->m_bufferID);
|
||||
|
||||
#ifdef COUNT_TIME
|
||||
#ifndef NDEBUG
|
||||
GTimeVal timeStart;
|
||||
g_get_current_time(&timeStart);
|
||||
#endif
|
||||
@@ -242,20 +243,28 @@ gboolean CodeView::CB_displayDraw( GtkWidget *widget, GdkEventExpose *event, gpo
|
||||
|
||||
tmpBuf->AnchorSetSize(self->m_displayUniqueId, self->m_shawableAreaX, self->m_shawableAreaY);
|
||||
bool enableToWrite = tmpBuf->AnchorGet(self->m_displayUniqueId, anchor);
|
||||
DrawerManager monDrawer(widget, self->m_shawableAreaX, self->m_shawableAreaY, Display::GetFontHeight()*anchor.m_BufferNumberLineOffset);
|
||||
|
||||
int32_t currentLineID = 0;
|
||||
while (true == enableToWrite) {
|
||||
if (true == anchor.m_redrawLine[currentLineID]) {
|
||||
#ifndef NDEBUG
|
||||
EDN_DEBUG("draw line=" << currentLineID << " realID=" << anchor.m_lineNumber );
|
||||
#endif
|
||||
tmpBuf->DrawLine(monDrawer, anchor);
|
||||
}
|
||||
enableToWrite = tmpBuf->AnchorNext(anchor);
|
||||
currentLineID++;
|
||||
}
|
||||
monDrawer.Flush();
|
||||
|
||||
// Need to clean the end of windows (sometimes)...
|
||||
/*
|
||||
if (iii<lineIdEnd+1) {
|
||||
int32_t positionY = letterHeight * (iii - m_displayStart.y - 1);
|
||||
drawer.Rectangle(myColorManager->Get(COLOR_CODE_BASIC_BG), 0, positionY, drawer.GetWidth(), letterHeight*(lineIdEnd+1-iii) );
|
||||
if(currentLineID<anchor.m_displaySize.y+1) {
|
||||
for (int32_t iii=currentLineID; iii < anchor.m_displaySize.y; iii++) {
|
||||
tmpBuf->DrawLineEmpty(monDrawer, iii);
|
||||
}
|
||||
*/
|
||||
#ifdef COUNT_TIME
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
GTimeVal timeStop;
|
||||
g_get_current_time(&timeStop);
|
||||
EDN_DEBUG("Display Generation = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s ==> " << (timeStop.tv_usec - timeStart.tv_usec)/1000. << "ms");
|
||||
@@ -289,6 +298,12 @@ gint CodeView::CB_focusGet( GtkWidget *widget, GdkEventFocus *event, gpointer da
|
||||
GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
|
||||
# endif
|
||||
self->SendMessage(EDN_MSG__BUFFER_CHANGE_CURRENT, self->m_bufferID);
|
||||
# ifdef USE_GTK_VERSION_2_0
|
||||
Buffer * tmpBuf = self->m_bufferManager->Get(self->m_bufferID);
|
||||
tmpBuf->AnchorRedrawAll(self->m_displayUniqueId);
|
||||
// Force redraw of the widget
|
||||
gtk_widget_queue_draw_area(self->m_widget, 0, 0, self->m_shawableAreaX, self->m_shawableAreaY);
|
||||
# endif
|
||||
EDN_INFO("Focus - In");
|
||||
return FALSE;
|
||||
}
|
||||
|
@@ -54,6 +54,7 @@ class CodeView : public MsgBroadcast
|
||||
private:
|
||||
// main windows widget :
|
||||
GtkWidget * m_widget;
|
||||
DrawerManager * m_Drawer;
|
||||
int32_t m_displayUniqueId;
|
||||
//position_ts m_displayStart; //!< position where the display is starting
|
||||
//position_ts m_displaySize; //!< number of char displayable in the screan
|
||||
|
@@ -40,7 +40,7 @@
|
||||
#define FONT_ITALIC_YES (1)
|
||||
|
||||
|
||||
// Variables privé du namespace
|
||||
// Variables priv<EFBFBD> du namespace
|
||||
#define POLICE_NAME "Monospace"
|
||||
|
||||
#ifdef USE_GTK_VERSION_3_0
|
||||
@@ -127,6 +127,7 @@ cairo_font_face_t * Display::GetFont(bool bold, bool italic)
|
||||
#undef __class__
|
||||
#define __class__ "DrawerManager"
|
||||
|
||||
//#define megaplop mlkjmlk
|
||||
/**
|
||||
* @brief DrawerManager constructor : generate a memoryDC where we can draw everything...
|
||||
*
|
||||
@@ -139,26 +140,47 @@ cairo_font_face_t * Display::GetFont(bool bold, bool italic)
|
||||
* @return ---
|
||||
*
|
||||
*/
|
||||
DrawerManager::DrawerManager(GtkWidget * widget, int32_t x, int32_t y)
|
||||
DrawerManager::DrawerManager(GtkWidget * widget, int32_t x, int32_t y, int32_t scrollOffset)
|
||||
{
|
||||
|
||||
m_size.x = x;
|
||||
m_size.y = y;
|
||||
m_haveWork = false;
|
||||
// Create the Cairo Element
|
||||
# if USE_GTK_VERSION_3_0
|
||||
m_cairo = gdk_cairo_create(gtk_widget_get_window(widget));
|
||||
m_windows = gtk_widget_get_window(widget);
|
||||
# elif USE_GTK_VERSION_2_0
|
||||
m_cairo = gdk_cairo_create(widget->window);
|
||||
m_windows = widget->window;
|
||||
# endif
|
||||
//cairo_translate(m_cairo, 0, 7);
|
||||
cairo_set_source_rgb(m_cairo, 0, 0, 0);
|
||||
|
||||
// Double buffer with previous copy management :
|
||||
{
|
||||
// Create the Cairo context from the current windows
|
||||
cairo_t * cairoWindows = gdk_cairo_create(m_windows);
|
||||
// inform that we nee a double buffer
|
||||
GdkRectangle myRect = {0, 0, x, y};
|
||||
gdk_window_begin_paint_rect(m_windows, &myRect);
|
||||
// Create the Cairo context from the double Buffer just created
|
||||
m_cairo = gdk_cairo_create(m_windows);
|
||||
// Copy the previous display data from the current display to the double buffer area:
|
||||
cairo_surface_t * drawableSurface = cairo_get_target(cairoWindows);
|
||||
TranslateVertical(-1* scrollOffset);
|
||||
cairo_set_source_surface(m_cairo, drawableSurface, 0, 0);
|
||||
cairo_paint(m_cairo);
|
||||
cairo_set_font_size(m_cairo, POLICE_SIZE);
|
||||
m_dataToDisplay[0] = '\0';
|
||||
TranslateVertical(scrollOffset);
|
||||
//cairo_surface_destroy(drawableSurface);
|
||||
cairo_destroy(cairoWindows);
|
||||
}
|
||||
|
||||
cairo_scale(m_cairo, 1.0, 1.0);
|
||||
|
||||
# ifndef NDEBUG
|
||||
// for Test only : this remove slowly the old line that is not rewritten
|
||||
cairo_set_source_rgb(m_cairo, 0, 0, 0);
|
||||
cairo_set_source_rgba(m_cairo, 1, 1, 1, 0.05);
|
||||
cairo_paint(m_cairo);
|
||||
# endif
|
||||
cairo_set_font_size(m_cairo, POLICE_SIZE);
|
||||
m_dataToDisplay[0] = '\0';
|
||||
|
||||
m_nbElement = 0;
|
||||
|
||||
// http://cairographics.org/FAQ/#clear_a_surface
|
||||
@@ -168,10 +190,6 @@ DrawerManager::DrawerManager(GtkWidget * widget, int32_t x, int32_t y)
|
||||
//cairo_paint(m_cairo);
|
||||
//cairo_fill(m_cairo);
|
||||
//cairo_stroke (m_cairo);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -187,6 +205,9 @@ DrawerManager::DrawerManager(GtkWidget * widget, int32_t x, int32_t y)
|
||||
*/
|
||||
DrawerManager::~DrawerManager()
|
||||
{
|
||||
// call the painting of the double buffer in the displayed current buffer
|
||||
gdk_window_end_paint(m_windows);
|
||||
// Destroy cairo context
|
||||
cairo_destroy(m_cairo);
|
||||
}
|
||||
|
||||
@@ -432,6 +453,7 @@ void DrawerManager::Cursor(int32_t x, int32_t y)
|
||||
cairo_rel_line_to(m_cairo, 0, -letterHeight);
|
||||
}
|
||||
cairo_stroke(m_cairo);
|
||||
//cairo_set_fill_rule(m_cairo, CAIRO_FILL_RULE_EVEN_ODD);
|
||||
cairo_fill(m_cairo);
|
||||
}
|
||||
|
||||
@@ -579,6 +601,14 @@ void DrawerManager::UTF8UnknownElement(Colorize *SelectColor, int32_t x, int32_t
|
||||
}
|
||||
|
||||
|
||||
void DrawerManager::TranslateVertical(int32_t nbPixelTranslation)
|
||||
{
|
||||
Flush();
|
||||
//scale((xmax-xmin)/W, (ymax-ymin)/H)
|
||||
cairo_translate(m_cairo, 0, nbPixelTranslation);
|
||||
cairo_fill(m_cairo);
|
||||
cairo_paint(m_cairo);
|
||||
}
|
||||
|
||||
|
||||
/* Basic axample with cairo and pango...
|
||||
|
@@ -52,7 +52,7 @@ class DrawerManager;
|
||||
class DrawerManager {
|
||||
public:
|
||||
// Constructeur
|
||||
DrawerManager(GtkWidget * widget, int32_t x, int32_t y);
|
||||
DrawerManager(GtkWidget * widget, int32_t x, int32_t y, int32_t scrollOffset=0);
|
||||
~DrawerManager();
|
||||
|
||||
void Rectangle(Colorize *SelectColor, int32_t x, int32_t y, int32_t width, int32_t height);
|
||||
@@ -72,6 +72,7 @@ class DrawerManager {
|
||||
void Flush(void);
|
||||
int32_t GetWidth(void) { return m_size.x; };
|
||||
int32_t GetHeight(void) { return m_size.y; };
|
||||
void TranslateVertical(int32_t nbPixelTranslation);
|
||||
|
||||
private:
|
||||
void DirectRectangle(Colorize *SelectColor, int32_t x, int32_t y, int32_t width, int32_t height);
|
||||
@@ -85,7 +86,7 @@ class DrawerManager {
|
||||
|
||||
position_ts m_size; //!< Total size
|
||||
cairo_t * m_cairo; //!< Cairo Layout pointer
|
||||
|
||||
GdkWindow * m_windows; //!< remember the current widget ==> for some internal problems
|
||||
};
|
||||
|
||||
|
||||
|
@@ -646,8 +646,22 @@ int32_t EdnBuf::CountLines(int32_t startPos, int32_t endPos)
|
||||
EdnVectorBuf::Iterator myPosIt = m_data.Position(startPos);
|
||||
int32_t lineCount = 0;
|
||||
|
||||
#ifndef NDEBUG
|
||||
GTimeVal timeStart;
|
||||
if (0 == startPos) {
|
||||
g_get_current_time(&timeStart);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (myPosIt) {
|
||||
if (myPosIt.Position() == endPos) {
|
||||
#ifndef NDEBUG
|
||||
if (0 == startPos) {
|
||||
GTimeVal timeStop;
|
||||
g_get_current_time(&timeStop);
|
||||
EDN_ERROR("Count line (" << startPos << "," << endPos << ") time = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s ==> " << (timeStop.tv_usec - timeStart.tv_usec)/1000. << "ms");
|
||||
}
|
||||
#endif
|
||||
return lineCount;
|
||||
}
|
||||
if ('\n' == *myPosIt) {
|
||||
@@ -655,6 +669,76 @@ int32_t EdnBuf::CountLines(int32_t startPos, int32_t endPos)
|
||||
}
|
||||
myPosIt++;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (0 == startPos) {
|
||||
GTimeVal timeStop;
|
||||
g_get_current_time(&timeStop);
|
||||
EDN_ERROR("Count line (" << startPos << "," << endPos << ") time = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s ==> " << (timeStop.tv_usec - timeStart.tv_usec)/1000. << "ms");
|
||||
}
|
||||
#endif
|
||||
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the Id of the line where is positionned the current pos element
|
||||
*
|
||||
* @param[in] pos posithion in the buffer where we need to know the current line
|
||||
* @param[in] refPos reference position
|
||||
* @param[in] refLine reference Line of the position
|
||||
*
|
||||
* @return the current line ID of the pos
|
||||
*
|
||||
*/
|
||||
int32_t EdnBuf::GetLinesIdWithRef(int32_t pos, int32_t refPos, int32_t refLine)
|
||||
{
|
||||
EdnVectorBuf::Iterator myPosIt = m_data.Position(refPos);
|
||||
int32_t lineCount = refLine;
|
||||
|
||||
#ifndef NDEBUG
|
||||
GTimeVal timeStart;
|
||||
g_get_current_time(&timeStart);
|
||||
#endif
|
||||
if (pos == refPos) {
|
||||
return refLine;
|
||||
} else if (pos > refPos) {
|
||||
while (myPosIt) {
|
||||
if (myPosIt.Position() == pos) {
|
||||
#ifndef NDEBUG
|
||||
GTimeVal timeStop;
|
||||
g_get_current_time(&timeStop);
|
||||
EDN_DEBUG("Count line " << pos << " with ref(" << refPos << "," << refPos << ") time = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s ==> " << (timeStop.tv_usec - timeStart.tv_usec)/1000. << "ms");
|
||||
#endif
|
||||
return lineCount;
|
||||
}
|
||||
if ('\n' == *myPosIt) {
|
||||
lineCount++;
|
||||
}
|
||||
myPosIt++;
|
||||
}
|
||||
} else {
|
||||
while (myPosIt) {
|
||||
if (myPosIt.Position() == pos) {
|
||||
#ifndef NDEBUG
|
||||
GTimeVal timeStop;
|
||||
g_get_current_time(&timeStop);
|
||||
EDN_DEBUG("Count line " << pos << " with ref(" << refPos << "," << refPos << ") time = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s ==> " << (timeStop.tv_usec - timeStart.tv_usec)/1000. << "ms");
|
||||
#endif
|
||||
return lineCount;
|
||||
}
|
||||
if ('\n' == *myPosIt) {
|
||||
lineCount--;
|
||||
}
|
||||
myPosIt--;
|
||||
}
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
GTimeVal timeStop;
|
||||
g_get_current_time(&timeStop);
|
||||
EDN_DEBUG("Count line " << pos << " with ref(" << refPos << "," << refPos << ") time = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s ==> " << (timeStop.tv_usec - timeStart.tv_usec)/1000. << "ms");
|
||||
#endif
|
||||
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
@@ -685,12 +769,21 @@ int32_t EdnBuf::CountLines(void)
|
||||
EdnVectorBuf::Iterator myPosIt = m_data.Begin();
|
||||
int32_t lineCount = 0;
|
||||
|
||||
#ifndef NDEBUG
|
||||
GTimeVal timeStart;
|
||||
g_get_current_time(&timeStart);
|
||||
#endif
|
||||
while(myPosIt) {
|
||||
if ('\n' == *myPosIt) {
|
||||
lineCount++;
|
||||
}
|
||||
myPosIt++;
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
GTimeVal timeStop;
|
||||
g_get_current_time(&timeStop);
|
||||
EDN_DEBUG("count total number of line time = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s ==> " << (timeStop.tv_usec - timeStart.tv_usec)/1000. << "ms");
|
||||
#endif
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
@@ -720,6 +813,12 @@ void EdnBuf::CountNumberOfLines(void)
|
||||
*/
|
||||
int32_t EdnBuf::CountForwardNLines(int32_t startPos, int32_t nLines)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
GTimeVal timeStart;
|
||||
if (0 == startPos) {
|
||||
g_get_current_time(&timeStart);
|
||||
}
|
||||
#endif
|
||||
if (nLines == 0) {
|
||||
return startPos;
|
||||
} else if (startPos > m_data.Size() ) {
|
||||
@@ -739,6 +838,14 @@ int32_t EdnBuf::CountForwardNLines(int32_t startPos, int32_t nLines)
|
||||
}
|
||||
myPosIt++;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (0 == startPos) {
|
||||
GTimeVal timeStop;
|
||||
g_get_current_time(&timeStop);
|
||||
EDN_DEBUG("get poiner line (pos=" << startPos << "=>" << nLines << "lines) time = " << timeStop.tv_usec - timeStart.tv_usec << " micro-s ==> " << (timeStop.tv_usec - timeStart.tv_usec)/1000. << "ms");
|
||||
}
|
||||
#endif
|
||||
//EDN_INFO(" ==> (2) at position=" << myPosIt.Position() );
|
||||
return myPosIt.Position();
|
||||
}
|
||||
|
@@ -105,6 +105,7 @@ class EdnBuf {
|
||||
int32_t CharWidth( char c, int32_t indent); // TODO : rework this
|
||||
int32_t CountDispChars( int32_t lineStartPos, int32_t targetPos);
|
||||
int32_t CountForwardDispChars( int32_t lineStartPos, int32_t nChars);
|
||||
int32_t GetLinesIdWithRef( int32_t pos, int32_t refPos, int32_t refLine);
|
||||
int32_t CountLines( int32_t startPos, int32_t endPos);
|
||||
int32_t CountLines( void);
|
||||
int32_t CountLines( Edn::VectorType<int8_t> &data);
|
||||
|
@@ -39,7 +39,7 @@
|
||||
</rule>
|
||||
<rule name="my comment">
|
||||
<color>comment</color>
|
||||
<start>//</start>
|
||||
<start>(//|@)</start>
|
||||
<end>\n</end>
|
||||
<EscapeChar>\</EscapeChar>
|
||||
</rule>
|
||||
|
@@ -36,6 +36,9 @@ int main(int argc, char **argv)
|
||||
|
||||
gtk_widget_set_app_paintable(window, TRUE);
|
||||
|
||||
// Remove double-buffering ==> in the current case we can not get the previous display...
|
||||
gtk_widget_set_double_buffered(window, FALSE);
|
||||
|
||||
# if USE_GTK_VERSION_3_0
|
||||
g_signal_connect(G_OBJECT(window), "draw", G_CALLBACK(expose), NULL);
|
||||
# elif USE_GTK_VERSION_2_0
|
||||
@@ -60,17 +63,17 @@ int main(int argc, char **argv)
|
||||
&color);
|
||||
*/
|
||||
#endif
|
||||
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
|
||||
gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);
|
||||
g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(clicked), NULL);
|
||||
//gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
|
||||
//gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);
|
||||
/* //g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(clicked), NULL);
|
||||
|
||||
GtkWidget* fixed_container = gtk_fixed_new();
|
||||
gtk_container_add(GTK_CONTAINER(window), fixed_container);
|
||||
GtkWidget* button = gtk_button_new_with_label("button1");
|
||||
gtk_widget_set_size_request(button, 100, 100);
|
||||
gtk_container_add(GTK_CONTAINER(fixed_container), button);
|
||||
|
||||
screen_changed(window, NULL, NULL);
|
||||
*/
|
||||
//screen_changed(window, NULL, NULL);
|
||||
|
||||
gtk_widget_show_all(window);
|
||||
gtk_main();
|
||||
@@ -114,21 +117,37 @@ static void screen_changed(GtkWidget *widget, GdkScreen *old_screen, gpointer us
|
||||
|
||||
static gboolean expose(GtkWidget *widget, GdkEventExpose *event, gpointer userdata)
|
||||
{
|
||||
return FALSE;
|
||||
# if USE_GTK_VERSION_3_0
|
||||
cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));
|
||||
# elif USE_GTK_VERSION_2_0
|
||||
cairo_t *cr = gdk_cairo_create(widget->window);
|
||||
# endif
|
||||
if (TRUE == supports_alpha)
|
||||
cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.3); /* transparent */
|
||||
else
|
||||
cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); /* opaque white */
|
||||
|
||||
//return FALSE;
|
||||
GdkWindow * m_windows = NULL;
|
||||
# if USE_GTK_VERSION_3_0
|
||||
m_windows = gtk_widget_get_window(widget);
|
||||
# elif USE_GTK_VERSION_2_0
|
||||
m_windows = widget->window;
|
||||
# endif
|
||||
gtk_widget_shape_combine_mask(widget, NULL, 0, 0);
|
||||
cairo_t *cr = gdk_cairo_create(m_windows);
|
||||
|
||||
|
||||
|
||||
//if (TRUE == supports_alpha) {
|
||||
cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.2); // transparent
|
||||
/*} else {
|
||||
cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); // opaque white
|
||||
}*/
|
||||
/* draw the background */
|
||||
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_paint (cr);
|
||||
|
||||
/* draw a circle */
|
||||
int width, height;
|
||||
gtk_window_get_size(GTK_WINDOW(widget), &width, &height);
|
||||
|
||||
cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.6);
|
||||
cairo_arc(cr, width / 2, height / 2, (width < height ? width : height) / 2 - 8 , 0, 2 * 3.14);
|
||||
cairo_fill(cr);
|
||||
cairo_stroke(cr);
|
||||
|
||||
cairo_destroy(cr);
|
||||
|
||||
return FALSE;
|
||||
|
292
test_transparence2.c
Normal file
292
test_transparence2.c
Normal file
@@ -0,0 +1,292 @@
|
||||
/*******************************************************************************
|
||||
**3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|
||||
** 10 20 30 40 50 60 70 80
|
||||
**
|
||||
** program:
|
||||
** input_shape_test
|
||||
**
|
||||
** created:
|
||||
** 19.2.2006
|
||||
**
|
||||
** last change:
|
||||
** 20.2.2006
|
||||
**
|
||||
** author:
|
||||
** Mirco "MacSlow" Mueller <macslow@bangang.de>
|
||||
**
|
||||
** license:
|
||||
** GPL
|
||||
**
|
||||
** notes:
|
||||
** - this is a test I did to figure out how to use input-shapes (XShape 1.1)
|
||||
** - opens a decoration-less and transparent gtk+-window and draws a red
|
||||
** cross with a circle around it
|
||||
** - only the parts drawn will be "draggable"
|
||||
** - window can be dragged around with LMB-drag
|
||||
** - window can be resized with MMB-drag (the input-shape also resizes!)
|
||||
** - window can be exited with ESC or q
|
||||
** - needs a compositing manager to run in order to look as intended
|
||||
** - tested with xcompmgr and compiz
|
||||
** - tested with gtk+-2.8.11 and gtk+-2.9.0 (CVS-head)
|
||||
**
|
||||
** bugs:
|
||||
** - there are no size-checks done for the input-shape, so I don't know what
|
||||
** will happen, if you make the window super large
|
||||
**
|
||||
** todo:
|
||||
** - nothing
|
||||
**
|
||||
** compile with:
|
||||
** gcc `pkg-config --cflags --libs gtk+-2.0` input_shape_test.c -o input_shape_test
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
||||
#include <math.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <gtk/gtk.h>
|
||||
#if !GTK_CHECK_VERSION(2,9,0)
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <gdk/gdkx.h>
|
||||
#endif
|
||||
|
||||
#define WIN_WIDTH 300
|
||||
#define WIN_HEIGHT 300
|
||||
|
||||
gint g_iCurrentWidth = WIN_WIDTH;
|
||||
gint g_iCurrentHeight = WIN_HEIGHT;
|
||||
|
||||
void update_input_shape (GtkWidget* pWindow, int iWidth, int iHeight);
|
||||
void on_alpha_screen_changed (GtkWidget* pWidget, GdkScreen* pOldScreen, GtkWidget* pLabel);
|
||||
void render (cairo_t* pCairoContext, gint iWidth, gint iHeight);
|
||||
gboolean on_expose (GtkWidget* pWidget, GdkEventExpose* pExpose);
|
||||
gboolean on_key_press (GtkWidget* pWidget, GdkEventKey* pKey, gpointer userData);
|
||||
gboolean on_button_press (GtkWidget* pWidget, GdkEventButton* pButton, GdkWindowEdge edge);
|
||||
gboolean on_configure (GtkWidget* pWidget, GdkEventConfigure* pEvent, gpointer data);
|
||||
#if !GTK_CHECK_VERSION(2,9,0)
|
||||
void do_shape_combine_mask (GdkWindow* window, GdkBitmap* mask, gint x, gint y);
|
||||
#endif
|
||||
void update_input_shape (GtkWidget* pWindow, int iWidth, int iHeight);
|
||||
|
||||
void on_alpha_screen_changed (GtkWidget* pWidget,
|
||||
GdkScreen* pOldScreen,
|
||||
GtkWidget* pLabel)
|
||||
{
|
||||
GdkScreen* pScreen = gtk_widget_get_screen (pWidget);
|
||||
GdkColormap* pColormap = gdk_screen_get_rgba_colormap (pScreen);
|
||||
|
||||
if (!pColormap)
|
||||
pColormap = gdk_screen_get_rgb_colormap (pScreen);
|
||||
|
||||
gtk_widget_set_colormap (pWidget, pColormap);
|
||||
}
|
||||
|
||||
void render (cairo_t* pCairoContext, gint iWidth, gint iHeight)
|
||||
{
|
||||
cairo_scale (pCairoContext, (double) iWidth, (double) iHeight);
|
||||
cairo_set_source_rgba (pCairoContext, 1.0f, 1.0f, 1.0f, 0.0f);
|
||||
cairo_set_operator (pCairoContext, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_paint (pCairoContext);
|
||||
cairo_set_source_rgba (pCairoContext, 1.0f, 0.0f, 0.0f, 0.75f);
|
||||
cairo_set_line_width (pCairoContext, 0.1f);
|
||||
cairo_move_to (pCairoContext, 0.15f, 0.15f);
|
||||
cairo_line_to (pCairoContext, 0.85f, 0.85f);
|
||||
cairo_move_to (pCairoContext, 0.85f, 0.15f);
|
||||
cairo_line_to (pCairoContext, 0.15f, 0.85f);
|
||||
cairo_stroke (pCairoContext);
|
||||
cairo_arc (pCairoContext, 0.5f, 0.5f, 0.45f, 0.0f, M_PI/180.0f * 360.0f);
|
||||
cairo_stroke (pCairoContext);
|
||||
}
|
||||
|
||||
gboolean on_expose (GtkWidget* pWidget,
|
||||
GdkEventExpose* pExpose)
|
||||
{
|
||||
gint iWidth;
|
||||
gint iHeight;
|
||||
cairo_t* pCairoContext = NULL;
|
||||
|
||||
pCairoContext = gdk_cairo_create (pWidget->window);
|
||||
if (!pCairoContext)
|
||||
return FALSE;
|
||||
|
||||
gtk_window_get_size (GTK_WINDOW (pWidget), &iWidth, &iHeight);
|
||||
render (pCairoContext, iWidth, iHeight);
|
||||
cairo_destroy (pCairoContext);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean on_configure (GtkWidget* pWidget,
|
||||
GdkEventConfigure* pEvent,
|
||||
gpointer userData)
|
||||
{
|
||||
gint iNewWidth = pEvent->width;
|
||||
gint iNewHeight = pEvent->height;
|
||||
|
||||
if (iNewWidth != g_iCurrentWidth || iNewHeight != g_iCurrentHeight)
|
||||
{
|
||||
update_input_shape (pWidget, iNewWidth, iNewHeight);
|
||||
g_iCurrentWidth = iNewWidth;
|
||||
g_iCurrentHeight = iNewHeight;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean on_key_press (GtkWidget* pWidget,
|
||||
GdkEventKey* pKey,
|
||||
gpointer userData)
|
||||
{
|
||||
gint iWidth;
|
||||
gint iHeight;
|
||||
|
||||
if (pKey->type == GDK_KEY_PRESS)
|
||||
{
|
||||
switch (pKey->keyval)
|
||||
{
|
||||
case GDK_Escape :
|
||||
case GDK_q :
|
||||
gtk_main_quit ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean on_button_press (GtkWidget* pWidget,
|
||||
GdkEventButton* pButton,
|
||||
GdkWindowEdge edge)
|
||||
{
|
||||
if (pButton->type == GDK_BUTTON_PRESS)
|
||||
{
|
||||
if (pButton->button == 1)
|
||||
gtk_window_begin_move_drag (GTK_WINDOW (gtk_widget_get_toplevel (pWidget)),
|
||||
pButton->button,
|
||||
pButton->x_root,
|
||||
pButton->y_root,
|
||||
pButton->time);
|
||||
if (pButton->button == 2)
|
||||
gtk_window_begin_resize_drag (GTK_WINDOW (gtk_widget_get_toplevel (pWidget)),
|
||||
edge,
|
||||
pButton->button,
|
||||
pButton->x_root,
|
||||
pButton->y_root,
|
||||
pButton->time);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if !GTK_CHECK_VERSION(2,9,0)
|
||||
/* this is piece by piece taken from gtk+ 2.9.0 (CVS-head with a patch applied
|
||||
regarding XShape's input-masks) so people without gtk+ >= 2.9.0 can compile and
|
||||
run input_shape_test.c */
|
||||
void do_shape_combine_mask (GdkWindow* window,
|
||||
GdkBitmap* mask,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
Pixmap pixmap;
|
||||
int ignore;
|
||||
int maj;
|
||||
int min;
|
||||
|
||||
if (!XShapeQueryExtension (GDK_WINDOW_XDISPLAY (window), &ignore, &ignore))
|
||||
return;
|
||||
|
||||
if (!XShapeQueryVersion (GDK_WINDOW_XDISPLAY (window), &maj, &min))
|
||||
return;
|
||||
|
||||
/* for shaped input we need at least XShape 1.1 */
|
||||
if (maj != 1 && min < 1)
|
||||
return;
|
||||
|
||||
if (mask)
|
||||
pixmap = GDK_DRAWABLE_XID (mask);
|
||||
else
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
pixmap = None;
|
||||
}
|
||||
|
||||
XShapeCombineMask (GDK_WINDOW_XDISPLAY (window),
|
||||
GDK_DRAWABLE_XID (window),
|
||||
ShapeInput,
|
||||
x,
|
||||
y,
|
||||
pixmap,
|
||||
ShapeSet);
|
||||
}
|
||||
#endif
|
||||
|
||||
void update_input_shape (GtkWidget* pWindow, int iWidth, int iHeight)
|
||||
{
|
||||
static GdkBitmap* pShapeBitmap = NULL;
|
||||
static cairo_t* pCairoContext = NULL;
|
||||
|
||||
pShapeBitmap = (GdkBitmap*) gdk_pixmap_new (NULL, iWidth, iHeight, 1);
|
||||
if (pShapeBitmap)
|
||||
{
|
||||
pCairoContext = gdk_cairo_create (pShapeBitmap);
|
||||
if (cairo_status (pCairoContext) == CAIRO_STATUS_SUCCESS)
|
||||
{
|
||||
render (pCairoContext, iWidth, iHeight);
|
||||
cairo_destroy (pCairoContext);
|
||||
#if !GTK_CHECK_VERSION(2,9,0)
|
||||
do_shape_combine_mask (pWindow->window, NULL, 0, 0);
|
||||
do_shape_combine_mask (pWindow->window, pShapeBitmap, 0, 0);
|
||||
#else
|
||||
gtk_widget_input_shape_combine_mask (pWindow, NULL, 0, 0);
|
||||
gtk_widget_input_shape_combine_mask (pWindow, pShapeBitmap, 0, 0);
|
||||
#endif
|
||||
}
|
||||
g_object_unref ((gpointer) pShapeBitmap);
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
GtkWidget* pWindow = NULL;
|
||||
GdkBitmap* pShapeMaskBitmap = NULL;
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
pWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
on_alpha_screen_changed (pWindow, NULL, NULL);
|
||||
gtk_widget_set_app_paintable (pWindow, TRUE);
|
||||
gtk_window_set_decorated (GTK_WINDOW (pWindow), FALSE);
|
||||
gtk_window_set_resizable (GTK_WINDOW (pWindow), TRUE);
|
||||
gtk_window_set_title (GTK_WINDOW (pWindow), "gtk+/XShape 1.1 test");
|
||||
gtk_widget_set_size_request (pWindow, g_iCurrentWidth, g_iCurrentHeight);
|
||||
gtk_widget_add_events (pWindow, GDK_BUTTON_PRESS_MASK);
|
||||
gtk_widget_show (pWindow);
|
||||
|
||||
g_signal_connect (G_OBJECT (pWindow),
|
||||
"destroy",
|
||||
G_CALLBACK (gtk_main_quit),
|
||||
NULL);
|
||||
g_signal_connect (G_OBJECT (pWindow),
|
||||
"expose-event",
|
||||
G_CALLBACK (on_expose),
|
||||
NULL);
|
||||
g_signal_connect (G_OBJECT (pWindow),
|
||||
"configure-event",
|
||||
G_CALLBACK (on_configure),
|
||||
NULL);
|
||||
g_signal_connect (G_OBJECT (pWindow),
|
||||
"key-press-event",
|
||||
G_CALLBACK (on_key_press),
|
||||
NULL);
|
||||
g_signal_connect (G_OBJECT (pWindow),
|
||||
"button-press-event",
|
||||
G_CALLBACK (on_button_press),
|
||||
NULL);
|
||||
|
||||
update_input_shape (pWindow, g_iCurrentWidth, g_iCurrentHeight);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user