(librunview) Init new RenderView/RunView

Base-level replacement of the Vision-derived text RunView― a couple
important features supported by the replacee haven't been implemented yet,
including:
	* Right-click menu
	* URL-highlighting/selection
	* Emote support
This commit is contained in:
Jaidyn Ann 2021-07-14 13:17:00 -05:00
parent 7f30571703
commit e760818007
11 changed files with 78 additions and 3187 deletions

View File

@ -1,116 +1,54 @@
/*
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "RenderView.h"
#include <librunview/RunView.h>
#include <librunview/Theme.h>
#include "AppPreferences.h"
#include <InterfaceDefs.h>
RenderView::RenderView(const char *name, const char* smileyConfig)
RenderView::RenderView(const char* name)
:
RunView(BRect(0, 0, 1, 1), name,
fTheme = new Theme(name, COL_MAX_COLORS + 1, COL_MAX_COLORS + 1,
MAX_RENDERS + 1),
B_FOLLOW_ALL, B_WILL_DRAW)
RunView(name)
{
if (smileyConfig)
Emoticor::Get()->LoadConfig(smileyConfig);
PrepareTheme(fTheme);
SetTimeStampFormat("[%H:%M]");
if ( IsHidden() )
Show();
ScrollToBottom();
}
void
RenderView::AppendMessage(const char* nick, const char* message,
rgb_color nameColor, time_t time)
rgb_color nameColor, time_t time)
{
rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color fg = ui_color(B_PANEL_TEXT_COLOR);
if (BString(message).IsEmpty() == true) return;
Append("<", nameColor, bg, nameColor, time);
Append(nick, fg, bg, fg);
Append("> ", nameColor, bg, nameColor);
if (Emoticor::Get()->Config() == NULL)
Append(message, fg, bg, fg);
else
AddEmoticText(message, fg, bg);
Append("\n", fg, bg, fg);
ScrollToSelection();
AppendTimestamp(time);
Append("<", nameColor);
Append(nick);
Append("> ", nameColor);
Append(message);
if (BString(message).EndsWith("\n") == false) Append("\n");
}
void
RenderView::AppendGenericMessage(const char* message)
{
rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color fg = ui_color(B_PANEL_TEXT_COLOR);
Append(message, fg, bg, fg, time(NULL));
ScrollToSelection();
if (BString(message).IsEmpty() == true) return;
AppendTimestamp(time(NULL));
Append(message, ui_color(B_PANEL_TEXT_COLOR), B_BOLD_FACE);
if (BString(message).EndsWith("\n") == false) Append("\n");
}
void
RenderView::AddEmoticText(const char * txt, rgb_color fore, rgb_color bg)
RenderView::AppendTimestamp(time_t time)
{
if (AppPreferences::Item()->IgnoreEmoticons)
Append(txt, fore, bg, fore);
else
Emoticor::Get()->AddText(this, txt, fore, fore, bg, fore);
if (time == 0) {
Append("[xx:xx] ", ui_color(B_LINK_HOVER_COLOR));
return;
}
char timestamp[9] = { '\0' };
strftime(timestamp, 8, "[%H:%M] ", localtime(&time));
Append(timestamp, ui_color(B_LINK_HOVER_COLOR));
}
void
RenderView::PrepareTheme(Theme *fTheme)
{
Theme::TimestampFore = COL_TIMESTAMP_DUMMY;
Theme::TimestampBack = COL_TIMESTAMP_DUMMY;
Theme::TimespaceFore = COL_MAX_COLORS;
Theme::TimespaceBack = COL_MAX_COLORS;
Theme::TimespaceFont = MAX_RENDERS;
Theme::TimestampFont = R_TIMESTAMP_DUMMY;
Theme::NormalFore = COL_TEXT;
Theme::NormalBack = COL_TEXT;
Theme::NormalFont = R_TEXT;
Theme::SelectionBack = COL_SELECTION;
fTheme->WriteLock();
rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color fg = ui_color(B_PANEL_TEXT_COLOR);
fTheme->SetForeground(COL_URL, ui_color(B_LINK_TEXT_COLOR));
fTheme->SetBackground(COL_URL, bg);
fTheme->SetForeground(COL_TIMESTAMP, fg);
fTheme->SetBackground(COL_TIMESTAMP, bg);
fTheme->SetForeground(COL_TEXT, fg);
fTheme->SetBackground(COL_TEXT, bg);
fTheme->SetForeground(COL_ACTION, fg);
fTheme->SetBackground(COL_ACTION, bg);
fTheme->SetForeground(COL_SELECTION, ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR));
fTheme->SetBackground(COL_SELECTION, ui_color(B_MENU_SELECTED_BACKGROUND_COLOR));
fTheme->SetForeground(COL_OWNNICK, 0, 0, 255);
fTheme->SetBackground(COL_OWNNICK, bg);
fTheme->SetForeground(COL_OTHERNICK, 255, 0, 0);
fTheme->SetBackground(COL_OTHERNICK, bg);
if (Emoticor::Get()->Config() != NULL)
fTheme->SetTextRender(R_EMOTICON, &str);
fTheme->SetSoftLineIndent(5.0);
fTheme->SetTextMargin(5.0);
fTheme->WriteUnlock();
}

View File

@ -1,54 +1,21 @@
#ifndef _RenderView_H
#define _RenderView_H_
/*
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef _RENDER_VIEW_H
#define _RENDER_VIEW_H
#include <librunview/RunView.h>
#include <librunview/SmileTextRender.h>
class RunView;
class Theme;
enum RenderViewColors {
COL_URL = 0,
COL_TIMESTAMP,
COL_TEXT,
COL_OWNNICK,
COL_OTHERNICK,
COL_ACTION,
COL_SELECTION,
COL_TIMESTAMP_DUMMY,
COL_MAX_COLORS
};
enum {
R_URL = 0,
R_TEXT,
R_TIMESTAMP,
R_ACTION,
R_EMOTICON,
R_TIMESTAMP_DUMMY,
MAX_RENDERS
};
class RenderView : public RunView
{
public:
RenderView(const char* name, const char* smileyConfig = NULL);
class RenderView : public RunView {
public:
RenderView(const char* name);
void AppendMessage(const char* nick, const char* message,
rgb_color nameColor, time_t time = 0);
void AppendGenericMessage(const char* message);
void AddEmoticText(const char * txt, rgb_color fore, rgb_color bg);
protected:
void PrepareTheme(Theme* theme);
private:
Theme* fTheme;
SmileTextRender str;
void AppendTimestamp(time_t time = 0);
};
#endif
#endif // _RENDER_VIEW_H

View File

@ -7,7 +7,6 @@
#include <String.h>
#include <Path.h>
#include <TranslationUtils.h>
#include "SmileTextRender.h"
//tmp
BMessage* faces = NULL;

View File

@ -32,10 +32,7 @@ APP_MIME_SIG =
# same name (source.c or source.cpp) are included from different directories.
# Also note that spaces in folder names do not work well with this Makefile.
SRCS = \
libs/librunview/Theme.cpp \
libs/librunview/RunView.cpp \
libs/librunview/Utilities.cpp \
libs/librunview/URLCrunch.cpp \
libs/librunview/Emoticor.cpp \
libs/librunview/Emoconfig.cpp

View File

@ -1,46 +0,0 @@
#ifndef _NormalTextRender_H_
#define _NormalTextRender_H_
#include "TextRender.h"
#include <Font.h>
#include <View.h>
#include <stdio.h>
class NormalTextRender : public TextRender
{
public:
NormalTextRender(BFont f): TextRender() {
font = f;
}
virtual ~NormalTextRender() {};
virtual void Render(BView* target, const char* txt, int num, BPoint pos) {
target->SetFont(&font);
target->DrawString(txt, num, pos);
};
virtual float Size() {
return font.Size();
}
virtual void GetHeight(font_height* height) {
font.GetHeight(height);
};
virtual void
GetEscapements(const char charArray[], int32 numChars, float escapementArray[]) {
font.GetEscapements(charArray, numChars, escapementArray);
}
private:
BFont font;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,187 +1,24 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Vision.
*
* The Initial Developer of the Original Code is The Vision Team.
* Portions created by The Vision Team are
* Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights
* Reserved.
*
* Contributor(s): Rene Gollent
* Todd Lair
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef _RUN_VIEW_H
#define _RUN_VIEW_H
#ifndef RUNVIEW_H_
#define RUNVIEW_H_
#include <TextView.h>
#define LINE_COUNT 1000
#include <View.h>
const uint32 M_LOOKUP_WEBSTER = 'rvlw';
const uint32 M_LOOKUP_GOOGLE = 'rvlg';
const uint32 M_LOOKUP_ACRONYM = 'rvla';
const uint32 M_CLEAR = 'rvcl';
const uint32 M_OFFVIEW_SELECTION = 'rvos';
const uint32 M_THEME_FOREGROUND_CHANGE = 'rvtf';
const uint32 M_THEME_BACKGROUND_CHANGE = 'rvtb';
const uint32 M_THEME_FONT_CHANGE = 'rvto';
#define C_URL 0
#define F_URL 0
struct Line;
class Theme;
class RunView;
class BScrollView;
class BCursor;
class BMessageRunner;
class BPopUpMenu;
class SelectPos
{
class RunView : public BTextView {
public:
RunView(const char* name);
int fLine;
int fOffset;
SelectPos (
int selLine = 0,
int selOffset = 0)
: fLine (selLine),
fOffset (selOffset)
{ }
SelectPos (const SelectPos& pos)
: fLine (pos.fLine),
fOffset (pos.fOffset)
{ }
~SelectPos (void)
{ }
SelectPos& operator = (const SelectPos& pos) {
fLine = pos.fLine;
fOffset = pos.fOffset;
return *this;
}
inline int operator == (const SelectPos& rhs) const {
return ((fLine == rhs.fLine) && (fOffset == rhs.fOffset));
}
inline int operator != (const SelectPos& rhs) const {
return (!(*this == rhs));
}
void Append(const char* text, rgb_color color,
uint16 fontFace = B_REGULAR_FACE);
void Append(const char* text);
private:
bool fLastStyled;
text_run_array fDefaultRun;
};
class RunView : public BView
{
BScrollView* fScroller;
BCursor* fURLCursor;
Theme* fTheme;
Line* fWorking;
Line* fLines[LINE_COUNT];
int16 fLine_count,
fClickCount;
char* fStamp_format;
char* fClipping_name;
SelectPos fSp_start, fSp_end;
int32 fTracking;
SelectPos fTrack_offset;
BMessageRunner* fOff_view_runner;
bigtime_t fOff_view_time;
bool fResizedirty;
bool fFontsdirty;
BPopUpMenu* fMyPopUp;
BPoint fLastClick;
bigtime_t fLastClickTime;
bool RecalcScrollBar (bool constrain);
void ResizeRecalc (void);
void FontChangeRecalc (void);
void ExtendTrackingSelect (BPoint);
void ShiftTrackingSelect (BPoint, bool, bigtime_t);
void CheckURLCursor (BPoint);
void BuildPopUp (void);
bool CheckClickBounds (const SelectPos&,
const BPoint&) const;
void LoadURL(const char* url);
public:
RunView (
BRect,
const char*,
Theme*,
uint32 = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 = 0UL);
virtual ~RunView (void);
virtual void AttachedToWindow (void);
virtual void DetachedFromWindow (void);
virtual void FrameResized (float, float);
virtual void TargetedByScrollView (BScrollView*);
virtual void Show ();
virtual void Draw (BRect);
virtual void MessageReceived (BMessage*);
virtual void SetViewColor (rgb_color);
void SetViewColor (uchar red, uchar green, uchar blue, uchar alpha = 255) {
rgb_color color = {red, green, blue, alpha};
SetViewColor (color);
}
virtual void MouseDown (BPoint);
virtual void MouseMoved (BPoint, uint32, const BMessage*);
virtual void MouseUp (BPoint);
void Append (const char*, int32, rgb_color, rgb_color, rgb_color, time_t = 0);
void Append (const char*, rgb_color, rgb_color, rgb_color, time_t = 0);
void Clear (void);
int16 LineCount (void) const;
const char* LineAt (int) const;
void SetTimeStampFormat (const char*);
void SetTheme (Theme*);
SelectPos PositionAt (BPoint) const;
BPoint PointAt (SelectPos) const;
BRect GetTextFrame (const SelectPos&, const SelectPos&) const;
bool IntersectSelection (const SelectPos&, const SelectPos&) const;
void GetSelectionText (BString&) const;
void Select (const SelectPos&, const SelectPos&);
void SelectAll (void);
void SetClippingName (const char*);
bool FindText(const char*);
void ScrollToBottom(void);
void ScrollToSelection(void);
};
#endif
#endif // _RUN_VIEW_H

View File

@ -1,54 +0,0 @@
#ifndef _SmileTextRender_H_
#define _SmileTextRender_H_
#include <Font.h>
#include <View.h>
#include <stdio.h>
#include <TranslationUtils.h>
#include <Resources.h>
#include <String.h>
#include <librunview/TextRender.h>
#include <librunview/Emoticor.h>
class SmileTextRender : public TextRender
{
public:
SmileTextRender(): TextRender() {};
virtual ~SmileTextRender() {};
virtual void Render(BView* target, const char* txt, int num, BPoint pos) {
BBitmap* pointer = NULL;
BString f(txt, num);
if (Emoticor::Get()->Config()->FindPointer(f.String(), (void**)&pointer) == B_OK) {
target->SetDrawingMode( B_OP_ALPHA );
target->DrawBitmapAsync( pointer, BPoint(pos.x, pos.y - (Emoticor::Get()->Config()->GetEmoticonSize() / 2)) );
target->SetDrawingMode( B_OP_OVER );
}
};
virtual float Size() {
printf("GETTING EMOTICOR SIZE!!!!\n");
return Emoticor::Get()->Config()->GetEmoticonSize();
}
virtual void GetHeight(font_height* h) {
h->descent = h->ascent = Emoticor::Get()->Config()->GetEmoticonSize() / 2;
h->leading = 0;
};
virtual void
GetEscapements(const char * /*charArray*/, int32 numChars, float escapementArray[]) {
//font.GetEscapements(charArray,numChars,escapementArray);
escapementArray[0] = 1;
for (int i = 1; i < numChars; i++) escapementArray[i] = 0;
}
};
#endif

View File

@ -1,19 +0,0 @@
#ifndef _TextRender_H_
#define _TextRender_H_
#include <Font.h>
class TextRender
{
public:
TextRender() {};
virtual ~TextRender() {};
virtual void Render(BView* target, const char*, int num, BPoint pos) = 0;
virtual void GetHeight(font_height* height) = 0;
virtual void GetEscapements(const char charArray[], int32 numChars, float escapementArray[]) = 0;
virtual float Size() = 0;
//
};
#endif

View File

@ -1,279 +0,0 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Vision.
*
* The Initial Developer of the Original Code is The Vision Team.
* Portions created by The Vision Team are
* Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights
* Reserved.
*
* Contributor(s): Rene Gollent
* Todd Lair
* Andrea Anzani, andrea.anzani@gmail.com
*/
#define NUMBER_THEME_READERS 1000
#include <Message.h>
#include <Messenger.h>
#include <View.h>
#include <malloc.h>
#include <stdio.h> //fix
#include <string.h>
#include "Theme.h"
#include "NormalTextRender.h"
int Theme::TimestampFore = 0;
int Theme::TimestampBack = 0;
int Theme::TimestampFont = 0;
int Theme::TimespaceFore = 1;
int Theme::TimespaceBack = 1;
int Theme::TimespaceFont = 1;
int Theme::NormalFore = 2;
int Theme::NormalBack = 2;
int Theme::NormalFont = 2;
int Theme::SelectionBack = 3;
//at least we use a 'normal' text render
Theme::Theme(const char* n, int foreCount, int backCount, int renderCount)
:
name (NULL),
fores (NULL),
backs (NULL),
text_renders (NULL),
fore_count (max_c (foreCount, 4)),
back_count (max_c (backCount, 4)),
render_count (max_c (renderCount, 4))
{
fSoftLineIndent = (float)(MARGIN_WIDTH / 2.0);
fTextMargin = (float)(MARGIN_WIDTH / 2.0);
name = strcpy (new char [strlen (n) + 1], n);
fores = new rgb_color [fore_count];
backs = new rgb_color [back_count];
normal_textrender = new NormalTextRender(be_plain_font);
text_renders = (TextRender**)malloc(render_count * sizeof(TextRender*));
for ( int i = 0; i < render_count; i++ )
text_renders[i] = normal_textrender;
sid = create_sem (NUMBER_THEME_READERS, name);
rgb_color def_timestamp_fore = {200, 150, 150, 255};
rgb_color def_timestamp_back = {255, 255, 255, 255};
rgb_color def_fore = {0, 0, 0, 255};
rgb_color def_back = {255, 255, 255, 255};
fores[0] = def_timestamp_fore;
int i;
for (i = 1; i < fore_count; ++i)
fores[i] = def_fore;
backs[0] = def_timestamp_back;
for (i = 1; i < back_count; ++i)
backs[i] = def_back;
}
Theme::~Theme (void)
{
delete_sem (sid);
//delete [] fonts;
for ( int i = 0; i < render_count; i++ )
if ( text_renders[i] )
text_renders[i] = NULL;
delete normal_textrender;
delete [] backs;
delete [] fores;
delete [] name;
}
int
Theme::CountForegrounds (void) const
{
return fore_count;
}
int
Theme::CountBackgrounds (void) const
{
return back_count;
}
/*
int16
Theme::CountFonts (void) const
{
return font_count;
}
*/
int
Theme::CountTextRenders (void) const
{
return render_count;
}
void
Theme::ReadLock (void)
{
acquire_sem (sid);
}
void
Theme::ReadUnlock (void)
{
release_sem (sid);
}
void
Theme::WriteLock (void)
{
acquire_sem_etc (sid, NUMBER_THEME_READERS, 0, 0);
}
void
Theme::WriteUnlock (void)
{
release_sem_etc (sid, NUMBER_THEME_READERS, 0);
}
const rgb_color
Theme::ForegroundAt (int which) const
{
rgb_color color = {0, 0, 0, 255};
if (which >= fore_count || which < 0)
return color;
return fores[which];
}
const rgb_color
Theme::BackgroundAt (int which) const
{
rgb_color color = {255, 255, 255, 255};
if (which >= back_count || which < 0)
return color;
return backs[which];
}
/*
const BFont &
Theme::FontAt (int16 which) const
{
if (which >= font_count || which < 0)
return *be_plain_font;
return fonts[which];
}
*/
TextRender*
Theme::TextRenderAt (int which)
{
if ( which < 0 ) {
//printf("Theme::TextRenderAt(): which < 0 (%d)\n", which);
return normal_textrender;
}
if ( which >= render_count ) {
//printf("Theme::TextRenderAt(): which >= render_count (%d, %d)\n", which, render_count);
return normal_textrender;
}
return text_renders[which];
}
bool
Theme::SetForeground (int which, const rgb_color color)
{
if (which >= fore_count || which < 0)
return false;
fores[which] = color;
return true;
}
bool
Theme::SetBackground (int which, const rgb_color color)
{
if (which >= back_count || which < 0)
return false;
backs[which] = color;
return true;
}
bool
Theme::SetTextRender(int which, TextRender* trender)
{
if (which >= render_count || which < 0 || !trender)
return false;
text_renders[which] = trender;
return true;
}
void
Theme::AddView (BView* view)
{
list.AddItem (view);
}
void
Theme::RemoveView (BView* view)
{
list.RemoveItem (view);
}
void
Theme::SetTextMargin(float margin)
{
fTextMargin = margin;
}
void
Theme::SetSoftLineIndent(float indent)
{
fSoftLineIndent = indent;
}

View File

@ -1,125 +0,0 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Vision.
*
* The Initial Developer of the Original Code is The Vision Team.
* Portions created by The Vision Team are
* Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights
* Reserved.
*
* Contributor(s): Rene Gollent
* Todd Lair
*/
#ifndef THEME_H_
#define THEME_H_
#include <OS.h>
#include <GraphicsDefs.h>
#include <List.h>
#include <librunview/TextRender.h>
class BView;
class NormalTextRender;
#define MARGIN_WIDTH 10.0 //default value, double of fTextMargin
#define MARGIN_INDENT 10.0 //default value, double of fSoftLineIndent
class Theme
{
char* name;
rgb_color* fores;
rgb_color* backs;
TextRender** text_renders; //FIX!!
int fore_count;
int back_count;
int render_count;
BList list;
sem_id sid;
float fSoftLineIndent;
float fTextMargin;
NormalTextRender* normal_textrender;
public:
static int TimestampFore;
static int TimestampBack;
static int TimestampFont;
static int TimespaceFore;
static int TimespaceBack;
static int TimespaceFont;
static int NormalFore;
static int NormalBack;
static int NormalFont;
static int SelectionBack;
Theme(const char*, int, int, int);
virtual ~Theme (void);
const char* Name (void) const {
return name;
}
void ReadLock (void);
void ReadUnlock (void);
void WriteLock (void);
void WriteUnlock (void);
int CountForegrounds (void) const;
int CountBackgrounds (void) const;
// int16 CountFonts (void) const;
int CountTextRenders (void) const;
const rgb_color ForegroundAt (int) const;
const rgb_color BackgroundAt (int) const;
//const BFont &FontAt (int16) const;
TextRender* TextRenderAt(int);
bool SetForeground (int, const rgb_color);
bool SetForeground (int w, uchar r, uchar g, uchar b, uchar a = 255) {
rgb_color color = {r, g, b, a};
return SetForeground (w, color);
}
bool SetBackground (int, const rgb_color);
bool SetBackground (int w, uchar r, uchar g, uchar b, uchar a = 255) {
rgb_color color = {r, g, b, a};
return SetBackground (w, color);
}
//bool SetFont (int16, const BFont &);
bool SetTextRender(int, TextRender*);
void SetSoftLineIndent(float indent);
void SetTextMargin(float margin);
float TextMargin() const {
return fTextMargin;
}
float SoftLineIndent() const {
return fSoftLineIndent;
}
void AddView (BView*);
void RemoveView (BView*);
};
#endif